Replies: 5 comments 6 replies
-
@real-nicholas I have implemented the functionality you want in my fork: To test it run the following: git clone -b dev/archives --single-branch https://github.com/eyllanesc/DoIt.git
cd DoIt
hugo server --source=exampleSite And then open http://localhost:1313/. Tell me if there are mistakes. If my changes do not have errors then I could write you a small tutorial on how to implement it in any demo. |
Beta Was this translation helpful? Give feedback.
-
@eyllanesc Thank you for your help! It is what I want in my case. By the way, I found another problem in your demo: in the but in the so, I think the URL could be unified: how do you think about it? |
Beta Was this translation helpful? Give feedback.
-
Tutorialhugo new site demo
cd demo
git init
git submodule add https://github.com/HEIGE-PCloud/DoIt.git themes/DoIt
cp themes/DoIt/exampleSite/config.toml .
cp themes/DoIt/archetypes/default.md archetypes Then copy the files to the respective directory: layouts/index.html{{- define "content" -}}
{{- $params := .Scratch.Get "params" -}}
{{- $profile := .Site.Params.home.profile -}}
{{- $posts := .Site.Params.home.posts -}}
<div class="page home"{{ if ne $posts.enable false | or .Content }} posts{{ end }}>
{{- /* Profile */ -}}
{{- if ne $profile.enable false -}}
{{- partial "home/profile.html" . -}}
{{- end -}}
{{- /* Content */ -}}
{{- if .Content -}}
<div class="single">
<div class="content" id="content">
{{- dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
</div>
</div>
{{- end -}}
{{- /* Posts */ -}}
{{- if ne $posts.enable false | and .Site.RegularPages -}}
{{- /* Paginate */ -}}
{{- $pages := where .Site.RegularPages "Type" "archives" -}}
{{- if .Site.Params.page.hiddenFromHomePage -}}
{{- $pages = where $pages "Params.hiddenfromhomepage" false -}}
{{- else -}}
{{- $pages = where $pages "Params.hiddenfromhomepage" "!=" true -}}
{{- end -}}
{{- with $posts.paginate | default .Site.Params.paginate -}}
{{- $pages = $.Paginate $pages . -}}
{{- else -}}
{{- $pages = .Paginate $pages -}}
{{- end -}}
{{- range $pages.Pages -}}
{{- .Render "summary" -}}
{{- end -}}
{{- partial "paginator.html" . -}}
{{- end -}}
</div>
{{- end -}} layouts/index.rss.xml<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>
{{- .Site.Title -}}
</title>
<link>
{{- .Permalink -}}
</link>
<description>
{{- .Site.Params.description | default .Site.Title -}}
</description>
<generator>Hugo -- gohugo.io</generator>
{{- with .Site.LanguageCode -}}
<language>
{{- . -}}
</language>
{{- end -}}
{{- with .Site.Author.email -}}
<managingEditor>
{{- . }}{{ with $.Site.Author.name }} ({{ . }}){{ end -}}
</managingEditor>
<webMaster>
{{- . }}{{ with $.Site.Author.name }} ({{ . }}){{ end -}}
</webMaster>
{{- end -}}
{{- with .Site.Copyright -}}
<copyright>
{{- . -}}
</copyright>
{{- end -}}
{{- if not .Date.IsZero -}}
<lastBuildDate>
{{- .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" -}}
</lastBuildDate>
{{- end -}}
{{ with .OutputFormats.Get "RSS" }}
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
{{ end }}
{{- range where .Site.RegularPages "Type" "archives" | first (.Site.Params.home.rss | default 10) -}}
{{- dict "Page" . "Site" .Site | partial "rss/item.html" -}}
{{- end -}}
</channel>
</rss> layouts/archives/rss.xml<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>
{{- .Params.Title | default (T .Section) | default .Section | dict "Some" | T "allSome" }} - {{ .Site.Title -}}
</title>
<link>
{{- .Permalink -}}
</link>
<description>
{{- .Params.Title | default (T .Section) | default .Section | dict "Some" | T "allSome" }} | {{ .Site.Title -}}
</description>
<generator>Hugo -- gohugo.io</generator>
{{- with .Site.LanguageCode -}}
<language>
{{- . -}}
</language>
{{- end -}}
{{- with .Site.Author.email -}}
<managingEditor>
{{- . }}{{ with $.Site.Author.name }} ({{ . }}){{ end -}}
</managingEditor>
<webMaster>
{{- . }}{{ with $.Site.Author.name }} ({{ . }}){{ end -}}
</webMaster>
{{- end -}}
{{- with .Site.Copyright -}}
<copyright>
{{- . -}}
</copyright>
{{- end -}}
{{- if not .Date.IsZero -}}
<lastBuildDate>
{{- .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" -}}
</lastBuildDate>
{{- end -}}
<atom:link href="{{ .Permalink }}" rel="self" type="application/rss+xml" />
{{- if .Site.Params.section.recentlyUpdated.rss -}}
{{- $postCount := 0 -}}
{{- $maxPostCount := .Site.Params.section.recentlyUpdated.maxCount | default 10 -}}
{{- $days := .Site.Params.section.recentlyUpdated.days | default 30 -}}
{{- range (where .Data.Pages.ByLastmod.Reverse "Section" "!=" "") -}}
{{- if gt (add .Lastmod.Unix (mul 86900 $days)) now.Unix -}}
{{- if lt $postCount $maxPostCount -}}
{{- if ne .Lastmod.Unix .Date.Unix }}
{{- dict "Page" . "Site" .Site | partial "rss/item.html" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- range .Pages | first (.Site.Params.section.rss | default 10) -}}
{{- dict "Page" . "Site" .Site | partial "rss/item.html" -}}
{{- end -}}
{{- end -}}
</channel>
</rss> layouts/archives/single.html{{- define "title" }}{{ .Title }} - {{ .Site.Title }}{{ end -}}
{{- define "content" -}}
{{- $params := .Scratch.Get "params" -}}
{{- $toc := $params.toc -}}
{{- if eq $toc true -}}
{{- $toc = .Site.Params.page.toc | default dict -}}
{{- else if eq $toc false -}}
{{- $toc = dict "enable" false -}}
{{- end -}}
{{- /* Auto TOC */ -}}
{{- if $toc.enable | and (eq $toc.keepStatic false) -}}
<div class="toc" id="toc-auto">
<h2 class="toc-title">{{ T "contents" }}</h2>
<div class="toc-content{{ if eq $toc.auto false }} always-active{{ end }}" id="toc-content-auto">
{{- dict "Content" .TableOfContents "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
</div>
</div>
{{- end -}}
{{- /* Page Style */ -}}
{{- if eq $params.pageStyle "wide" -}}
<script>document.getElementsByTagName("main")[0].setAttribute("pageStyle", "wide")</script>
{{- else -}}
<script>document.getElementsByTagName("main")[0].setAttribute("pageStyle", "normal")</script>
{{- end -}}
{{- /* TOC Style */ -}}
{{- if eq $toc.enable true -}}
{{- if eq $toc.keepStatic true -}}
<script>document.getElementsByTagName("main")[0].setAttribute("autoTOC", "false")</script>
{{- else -}}
<script>document.getElementsByTagName("main")[0].setAttribute("autoTOC", "true")</script>
{{- end -}}
{{- else if eq $toc.enable false -}}
<script>document.getElementsByTagName("main")[0].setAttribute("autoTOC", "false")</script>
{{- end -}}
<article class="page single">
{{- /* Title */ -}}
<h1 class="single-title animate__animated animate__flipInX">{{ .Title }}</h1>
{{- /* Subtitle */ -}}
{{- with $params.subtitle -}}
<h2 class="single-subtitle">{{ . }}</h2>
{{- end -}}
{{- /* Meta */ -}}
<div class="post-meta">
<div class="post-meta-line">
<span class="post-author">
{{- partial "meta/author.html" . }}
</span>
{{- with .Params.categories | or .Params.series -}}
<span class="post-category">
{{- T "includedIn" | safeHTML -}}
</span>
{{- end -}}
{{- $categories := slice -}}
{{- range .Params.categories -}}
{{- $category := partialCached "function/path.html" . . | printf "/categories/%v" | $.Site.GetPage -}}
{{- $categories = $categories | append (printf `<a href="%v"><i class="far fa-folder fa-fw"></i>%v</a>` $category.RelPermalink $category.Title) -}}
{{- end -}}
{{- with delimit $categories " " -}}
<span class="post-category">
{{- dict "Categories" . "Count" (len $categories) | T "includedInCategories" | safeHTML -}}
</span>
{{- end -}}
{{- with (and (.Params.categories) (.Params.series)) -}}
<span class="post-category">
{{- T "includedInAnd" | safeHTML -}}
</span>
{{- end -}}
{{- $series := slice -}}
{{- range .Params.series -}}
{{- $singleSeries := partialCached "function/path.html" . . | printf "/series/%v" | $.Site.GetPage -}}
{{- $series = $series | append (printf `<a href="%v"><i class="far fa-list-alt fa-fw"></i>%v</a>` $singleSeries.RelPermalink $singleSeries.Title) -}}
{{- end -}}
{{- with delimit $series " " -}}
<span class="post-series">
{{- dict "Series" . | T "includedInSeries" | safeHTML -}}
</span>
{{- end -}}
</div>
<div class="post-meta-line">
{{- with .Site.Params.dateformat | default "2006-01-02" | .PublishDate.Format -}}
<i class="far fa-calendar-alt fa-fw"></i> <time datetime="{{ . }}">{{ . }}</time>
{{- end -}}
{{- with .Site.Params.dateformat | default "2006-01-02" | .Lastmod.Format -}}
<i class="far fa-edit fa-fw"></i> <time datetime="{{ . }}">{{ . }}</time>
{{- end -}}
<i class="fas fa-pencil-alt fa-fw"></i> {{ T "wordCount" .WordCount }}
<i class="far fa-clock fa-fw"></i> {{ T "readingTime" .ReadingTime }}
{{- $comment := .Scratch.Get "comment" | default dict -}}
{{- /* Visitor Count */ -}}
{{- if $comment.enable | and $comment.valine.enable | and $comment.valine.visitor -}}
<span id="{{ .RelPermalink }}" class="leancloud_visitors" data-flag-title="{{ .Title }}">
<i class="far fa-eye fa-fw"></i> <span class=leancloud-visitors-count></span> {{ T "views" }}
</span>
{{- end -}}
{{- if $comment.enable | and $comment.waline.enable | and $comment.waline.visitor -}}
<span id="{{ .RelPermalink }}" class="leancloud_visitors" data-flag-title="{{ .Title }}">
<i class="far fa-eye fa-fw"></i> <span class=leancloud-visitors-count></span> {{ T "views" }}
</span>
{{- end -}}
{{- if $comment.enable | and $comment.twikoo.enable | and $comment.twikoo.visitor -}}
<span id="{{ .RelPermalink }}" class="leancloud_visitors" data-flag-title="{{ .Title }}">
<i class="far fa-eye fa-fw"></i> <span class=leancloud-visitors-count id=twikoo_visitors></span> {{ T "views" }}
</span>
{{- end -}}
{{- /* Comment Count */ -}}
{{- if $comment.enable | and $comment.waline.enable | and $comment.waline.commentCount -}}
<span id="{{ .RelPermalink }}" class="comment_count" data-flag-title="{{ .Title }}">
<i class="far fa-comments fa-fw"></i> <span class="waline-comment-count" id="waline-comment-count"></span> {{ T "comments" }}
</span>
{{- end -}}
{{- if $comment.enable | and $comment.twikoo.enable | and $comment.twikoo.commentCount -}}
<span id="{{ .RelPermalink }}" class="comment_count" data-flag-title="{{ .Title }}">
<i class="far fa-comments fa-fw"></i> <span class="twikoo-comment-count" id="twikoo-comment-count"></span> {{ T "comments" }}
</span>
{{- end -}}
{{- /* License */ -}}
{{- $license := $params.license -}}
{{- with $license -}}
<span>
<i class="fas fa-balance-scale fa-fw"></i> <span>{{- . | safeHTML -}}</span>
</span>
{{- end -}}
</div>
</div>
{{- /* Featured image */ -}}
{{- $image := $params.featuredimage -}}
{{- $width := "auto" -}}
{{- $height := "auto" -}}
{{- with .Resources.GetMatch (printf "**%s" $params.featuredimage) -}}
{{- $image = .RelPermalink -}}
{{- $width = .Width -}}
{{- $height = .Height -}}
{{- end -}}
{{- with .Resources.GetMatch "featured-image" -}}
{{- $image = .RelPermalink -}}
{{- $width = .Width -}}
{{- $height = .Height -}}
{{- end -}}
{{- with $image -}}
<div class="featured-image">
{{- dict "Src" . "Title" $.Description "Resources" $.Resources "Width" $width "Height" $height | partial "plugin/image.html" -}}
</div>
{{- end -}}
{{- /* Series list */ -}}
{{- if $params.series | and $params.seriesNavigation -}}
{{- range $key, $value := .Site.Taxonomies.series -}}
{{- range $params.series -}}
{{- if . | urlize | eq $key -}}
{{- $term := $.Site.GetPage "series" $key -}}
<div class="details series-nav open">
<div class="details-summary series-title">
<span>{{ T "series" }} - {{ $term.Title }}</span>
<span><i class="details-icon fas fa-angle-right"></i></span>
</div>
<div class="details-content series-content">
<nav>
<ul>
{{- range $value.Pages -}}
{{- if .LinkTitle | eq $.Title -}}
<li><span class="active">{{ .LinkTitle }}</span></li>
{{- else }}
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
{{- end }}
{{- end -}}
</ul>
</nav>
</div>
</div>
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- /* Static TOC */ -}}
{{- if $toc.enable -}}
<div class="details toc" id="toc-static" kept="{{ if $toc.keepStatic }}true{{ end }}">
<div class="details-summary toc-title">
<span>{{ T "contents" }}</span>
<span><i class="details-icon fas fa-angle-right"></i></span>
</div>
<div class="details-content toc-content" id="toc-content-static">
{{- if $toc.keepStatic -}}
{{- dict "Content" .TableOfContents "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
{{- end -}}
</div>
</div>
{{- end -}}
{{- /* Content */ -}}
<div class="content" id="content">
{{- /* Outdated Article Reminder */ -}}
{{- partial "single/outdatedArticleReminder.html" . -}}
{{- dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
</div>
{{/* Sponsor */}}
{{- partial "single/sponsor.html" . -}}
{{- /* Footer */ -}}
{{- partial "single/footer.html" . -}}
{{- /* Comment */ -}}
{{- partial "comment.html" . -}}
</article>
{{- end -}} config.toml [[languages.en.menu.main]]
identifier = "archives"
# you can add extra information before the name (HTML format is supported), such as icons
pre = ""
# you can add extra information after the name (HTML format is supported), such as icons
post = ""
name = "Archives"
url = "/archives/"
# title will be shown when you hover on this menu link.
title = ""
weight = 1 [[languages.zh-cn.menu.main]]
identifier = "archives"
# 你可以在名称 (允许 HTML 格式) 之前添加其他信息, 例如图标
pre = ""
# 你可以在名称 (允许 HTML 格式) 之后添加其他信息, 例如图标
post = ""
name = "所有文章"
url = "/archives/"
title = ""
weight = 1 [Permalinks]
# archives = ":year/:month/:filename"
archives = ":filename" Comment this line i18n/en.toml# === Archives ===
[archives]
other = "Archives"
# === Archives === i18n/zh-CN.toml# === Archives ===
[archives]
other = "归档"
# === Archives === Then create a post: git commit -m "apply changes"
hugo new archives/foo/index.en.md
hugo server -D |
Beta Was this translation helpful? Give feedback.
-
I got " |
Beta Was this translation helpful? Give feedback.
-
I run it on my macOS localhost, it's working normally. (use: but, it does not work when I build with why? |
Beta Was this translation helpful? Give feedback.
-
默认的URL为:
http://localhost:1313/posts/
因为我把菜单
Posts
名称改为了Archives
,所以,想进一步自定义URL的名称为:http://localhost:1313/archives/
查看 demo
testing-1.md:
md
文件结构:config.toml
文件配置:zh-CN.toml
文件配置:en.toml
文件配置:以上的配置,可以实现自定义URL的名称为:
http://localhost:1313/archives/
问题:
查看 demo
@HEIGE-PCloud
@eyllanesc
请问如何解决?谢谢!
Beta Was this translation helpful? Give feedback.
All reactions