From 3c7b035b1b8e3481b666bc53859049f624d721a5 Mon Sep 17 00:00:00 2001 From: Raphael Aguiar Date: Fri, 28 Aug 2020 13:32:29 -0300 Subject: Update RSS template and minor changes * Update RSS template * Add some custom front matter params to the README * Other minor changes --- README.md | 12 +++++-- assets/scss/main.scss | 2 +- exampleSite/config.toml | 2 +- exampleSite/content/posts/readme.md | 13 ++++++-- layouts/404.html | 4 +-- layouts/_default/baseof.html | 4 +-- layouts/_default/rss.xml | 2 +- layouts/_default/search.json.json | 1 + layouts/_default/single.html | 14 ++------ layouts/_default/sitemap.xml | 57 ++++++++++++++++++++------------- layouts/index.html | 13 +++++++- layouts/partials/footer.html | 6 ++-- layouts/partials/head.html | 16 ++++----- layouts/partials/header.html | 2 +- layouts/partials/table-of-contents.html | 9 ++++++ 15 files changed, 98 insertions(+), 59 deletions(-) create mode 100644 layouts/partials/table-of-contents.html diff --git a/README.md b/README.md index 975f884..da5e968 100644 --- a/README.md +++ b/README.md @@ -241,6 +241,12 @@ A **really** basic 404 page can be generated via config file by using: paragraph = "Nothing to see here, buddy." ``` +### Custom front matter params + +* `mainTitle` (string): Can be used to replace the `` meta tag, if you wish it to be different from the `<h1>` (which will still use the `title` param); +* `sitemapExclude` (true|false): Can be used to exclude a page/section from the sitemap; +* `noindex` (true|false): Similar to the above. Can be used to exclude a page/section from being indexed (by bots or your own site). It will change the meta tag `robots` to `noindex` and the page(s) will not be added to the site's search index. + ### Custom partials * The site title can be replaced by creating a file named `layouts/partials/custom/site-title.html`; @@ -248,9 +254,9 @@ A **really** basic 404 page can be generated via config file by using: * Custom CSS can be imported into the main CSS file by creating a file named `static/css/custom.css` or `assets/scss/custom.scss`; * The `copyright` param can be replaced by creating a file named `layouts/partials/custom/copyright.html`. -### More config +### More params -More possible params for your config file: +More possible params for your config file (or front matter): ```toml [params] @@ -288,9 +294,9 @@ More possible params for your config file: markupImgClass = "borderless" # This will append a separator (of your choice) along the site title to your <title> + # ie.: | ❚ - – — • ⚫ # You can disabled it PER PAGE by using "disableTitleSeparator" at front # matter or disable it entirely by commenting the line below - # ie.: | ❚ - – — • ⚫ titleSeparator = "|" [params.search] diff --git a/assets/scss/main.scss b/assets/scss/main.scss index c9ce8bd..e1936e0 100644 --- a/assets/scss/main.scss +++ b/assets/scss/main.scss @@ -338,7 +338,7 @@ code { // If there's no "custom/site-title" partial, style a default one -{{ if not (or (templates.Exists "partials/custom/site-title") (templates.Exists "partials/custom/site-title.html")) }} +{{ if not (templates.Exists "partials/custom/site-title.html") }} body > header { > a { @extend %heading-base; diff --git a/exampleSite/config.toml b/exampleSite/config.toml index fdebfd9..8566f3f 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -57,9 +57,9 @@ paginate = 5 markupImgClass = "" # This will append a separator (of your choice) along the site title to your <title> + # ie.: | ❚ - – — • ⚫ # You can disabled it PER PAGE by using "disableTitleSeparator" at front # matter or disable it entirely by commenting the line below - # ie.: | ❚ - – — • ⚫ titleSeparator = "|" diff --git a/exampleSite/content/posts/readme.md b/exampleSite/content/posts/readme.md index 2922bc9..b9d473c 100644 --- a/exampleSite/content/posts/readme.md +++ b/exampleSite/content/posts/readme.md @@ -2,6 +2,7 @@ title : "Read Me" description : "A copy of the README.md file." tags : [ extra, markdown ] +toc : true --- [Live demo (on Netlify)](https://color-your-world-demo.netlify.app/) | [Demo (on Hugo Themes)](https://themes.gohugo.io/theme/hugo-theme-color-your-world/) @@ -245,6 +246,12 @@ A **really** basic 404 page can be generated via config file by using: paragraph = "Nothing to see here, buddy." ``` +### Custom front matter params + +* `mainTitle` (string): Can be used to replace the `<title>` meta tag, if you wish it to be different from the `<h1>` (which will still use the `title` param); +* `sitemapExclude` (true|false): Can be used to exclude a page/section from the sitemap; +* `noindex` (true|false): Similar to the above. Can be used to exclude a page/section from being indexed (by bots or your own site). It will change the meta tag `robots` to `noindex` and the page(s) will not be added to the site's search index. + ### Custom partials * The site title can be replaced by creating a file named `layouts/partials/custom/site-title.html`; @@ -252,9 +259,9 @@ A **really** basic 404 page can be generated via config file by using: * Custom CSS can be imported into the main CSS file by creating a file named `static/css/custom.css` or `assets/scss/custom.scss`; * The `copyright` param can be replaced by creating a file named `layouts/partials/custom/copyright.html`. -### More config +### More params -More possible params for your config file: +More possible params for your config file (or front matter): ```toml [params] @@ -292,9 +299,9 @@ More possible params for your config file: markupImgClass = "borderless" # This will append a separator (of your choice) along the site title to your <title> + # ie.: | ❚ - – — • ⚫ # You can disabled it PER PAGE by using "disableTitleSeparator" at front # matter or disable it entirely by commenting the line below - # ie.: | ❚ - – — • ⚫ titleSeparator = "|" [params.search] diff --git a/layouts/404.html b/layouts/404.html index 9de2956..9b99da1 100644 --- a/layouts/404.html +++ b/layouts/404.html @@ -1,8 +1,8 @@ {{ define "main" }} <main> - <h1>{{ .Site.Params.notFound.title | default .Site.Data.default.notFound.title }}</h1> - <p>{{ .Site.Params.notFound.paragraph | default .Site.Data.default.notFound.paragraph }}</p> + <h1>{{ .Site.Params.notFound.title | emojify | default .Site.Data.default.notFound.title }}</h1> + <p>{{ .Site.Params.notFound.paragraph | emojify | default .Site.Data.default.notFound.paragraph }}</p> </main> {{ end }} diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index b6b0682..fd10f53 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -4,7 +4,7 @@ Currently here to avoid certain priority issues... --> -{{- .Scratch.Set "imageProc" (dict "highRes" (.Site.Params.imageProc.highRes | default .Site.Data.default.imageProc.highRes) "mediumRes" (.Site.Params.imageProc.mediumRes | default .Site.Data.default.imageProc.mediumRes) "lowRes" (.Site.Params.imageProc.lowRes | default .Site.Data.default.imageProc.lowRes) "markupAutoResizeWidth" (.Site.Params.imageProc.markupAutoResizeWidth | default .Site.Data.default.imageProc.markupAutoResizeWidth)) }} +{{- .Scratch.Set "imageProc" (dict "highRes" (.Site.Params.imageProc.highRes | default .Site.Data.default.imageProc.highRes) "mediumRes" (.Site.Params.imageProc.mediumRes | default .Site.Data.default.imageProc.mediumRes) "lowRes" (.Site.Params.imageProc.lowRes | default .Site.Data.default.imageProc.lowRes) "markupAutoResizeWidth" (.Site.Params.imageProc.markupAutoResizeWidth | default .Site.Data.default.imageProc.markupAutoResizeWidth)) -}} <!DOCTYPE html> <html lang="{{ .Site.Language.Lang }}" data-mode="{{ if .Site.Params.Style.isDark }}dark{{ else }}light{{ end }}"> @@ -82,7 +82,7 @@ <!-- KaTeX --> {{ if or .Params.katex .Site.Params.katex .Params.math .Site.Params.math }} - {{ partial "katex.html" . }} + {{ partial "katex" . }} {{ end }} </body> diff --git a/layouts/_default/rss.xml b/layouts/_default/rss.xml index eb0f835..8d0c681 100644 --- a/layouts/_default/rss.xml +++ b/layouts/_default/rss.xml @@ -6,7 +6,7 @@ {{- else -}} {{- $pages = $pctx.Pages -}} {{- end -}} -{{- $pages = where $pages "Params.sitemapexclude" "ne" true -}} +{{- $pages = where $pages "Params.noindex" "ne" true -}} {{- $limit := .Site.Config.Services.RSS.Limit -}} {{- if ge $limit 1 -}} {{- $pages = $pages | first $limit -}} diff --git a/layouts/_default/search.json.json b/layouts/_default/search.json.json index 279aeb2..e401800 100644 --- a/layouts/_default/search.json.json +++ b/layouts/_default/search.json.json @@ -1,6 +1,7 @@ {{- $stopWords := or .Params.stopWords .Site.Params.Search.stopWords -}} {{- $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections -}} +{{- $pages = where $pages "Params.noindex" "ne" true -}} {{- $lastIndex := (sub (len $pages) 1) -}} diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 48c7aee..3b32bde 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -4,11 +4,7 @@ <article> <header> - <h1>{{ .Title }}</h1> - - {{ range .Data.Terms }} - {{ .Name }} - {{ end }} + <h1>{{ .Title | emojify }}</h1> {{ if or .Params.categories .Params.tags }} <section class="terms"> @@ -39,13 +35,7 @@ </header> - {{ if .Params.toc }} - <details class="toc" open> - <summary class="outline-dashed">{{ T "tableOfContents" }}</summary> - {{ .Page.TableOfContents }} - </details> - {{ end }} - + {{ partial "table-of-contents" . }} {{ partial "processed-content" . }} </article> diff --git a/layouts/_default/sitemap.xml b/layouts/_default/sitemap.xml index 8177b07..b42a7af 100644 --- a/layouts/_default/sitemap.xml +++ b/layouts/_default/sitemap.xml @@ -1,29 +1,42 @@ +{{- $pages := .RegularPages -}} +{{- $pages = where $pages "Params.sitemapexclude" "ne" true -}} {{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" | safeHTML }} <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"> - {{ range .Site.RegularPages }} - {{ if not .Params.sitemapExclude }} - <url> - <loc>{{ .Permalink }}</loc> - - {{ if not .Lastmod.IsZero }} - <lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod> - {{ end }} - - {{ with .Sitemap.ChangeFreq }} - <changefreq>{{ . }}</changefreq> - {{ end }} - - {{ if ge .Sitemap.Priority 0.0 }} - <priority>{{ .Sitemap.Priority }}</priority> + {{ range $pages }} + + <url> + <loc>{{ .Permalink }}</loc> + + {{ if not .Lastmod.IsZero }} + <lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod> + {{ end }} + + {{ with .Sitemap.ChangeFreq }} + <changefreq>{{ . }}</changefreq> + {{ end }} + + {{ if ge .Sitemap.Priority 0.0 }} + <priority>{{ .Sitemap.Priority }}</priority> + {{ end }} + + {{ if .IsTranslated }} + {{ range .Translations }} + <xhtml:link + rel="alternate" + hreflang="{{ .Lang }}" + href="{{ .Permalink }}" + /> {{ end }} - {{ if .IsTranslated }} - {{ range .Translations }} - <xhtml:link rel="alternate" hreflang="{{ .Lang }}" href="{{ .Permalink }}" /> - {{ end }} - {{ end }} - </url> - {{ end }} + <xhtml:link + rel="alternate" + hreflang="{{ .Lang }}" + href="{{ .Permalink }}" + /> + {{ end }} + + </url> + {{ end }} </urlset> \ No newline at end of file diff --git a/layouts/index.html b/layouts/index.html index dc92444..566e19d 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -6,9 +6,20 @@ {{ if .Content }} <article> - <h1>{{ .Title | emojify }}</h1> + + <header> + + <h1>{{ .Title | emojify }}</h1> + + {{ if .Params.cover }} + {{ partial "cover" . }} + {{ end }} + + </header> + {{ partial "table-of-contents" . }} {{ partial "processed-content" . }} + </article> {{ else }} diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 9ea8cee..b314f1b 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -1,8 +1,10 @@ <!-- Custom or default copyright --> -{{ if or (templates.Exists "partials/custom/copyright") (templates.Exists "partials/custom/copyright.html") }} +{{ if (templates.Exists "partials/custom/copyright.html") }} {{ partial "custom/copyright" . }} {{ else }} - <p>{{ .Site.Copyright | markdownify | emojify }}</p> + {{ with .Site.Copyright }} + <p>{{ . | markdownify | emojify }}</p> + {{ end }} {{ end }} <!-- diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 7509980..d950a45 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -3,8 +3,8 @@ <meta name="generator" content="Hugo {{ hugo.Version }} -- gohugo.io / Color Your World -- gitlab.com/rmaguiar/hugo-theme-color-your-world"> <!-- I'm 99% sure there's a smarter way of doing it but whatever --> -{{ $currentTitle := (.Title | emojify) }} -{{ $mainTitle := .Params.mainTitle }} +{{ $currentTitle := .Title | emojify }} +{{ $mainTitle := .Params.mainTitle | emojify }} {{ $titleSeparator := .Site.Params.titleSeparator }} @@ -13,7 +13,7 @@ {{ if (eq .Kind "404") }} <!-- If 404 page --> - {{ $currentTitle = .Site.Params.notFound.title | default .Site.Data.default.notFound.title }} + {{ $currentTitle = .Site.Params.notFound.title | emojify | default .Site.Data.default.notFound.title }} {{ else if (eq .Kind "section") }} @@ -53,15 +53,15 @@ {{ else if and (.IsHome) (not .Content) }} <!-- If home page without content --> - {{ $currentTitle = (.Site.Title | emojify) }} + {{ $currentTitle = .Site.Title | emojify }} {{ end }} -{{ $currentDesc := (.Params.Description | emojify) }} +{{ $currentDesc := .Params.Description | emojify }} {{ if .IsHome }} - {{ $currentDesc = (.Site.Params.description | emojify) }} + {{ $currentDesc = .Site.Params.description | emojify }} {{ else if and (ne .Kind "taxonomy") (eq .Type "tags") (not .Params.description) }} {{ $currentDesc = (T "postsUnderTag" .) }} {{ else if and (ne .Kind "taxonomy") (eq .Type "categories") (not .Params.description) }} @@ -69,7 +69,7 @@ {{ else if eq .Kind "taxonomy" }} {{ $currentDesc = printf "%s %s." (T "pageContaining") ($currentTitle | lower) }} {{ else if (eq .Kind "404") }} - {{ $currentDesc = .Site.Params.notFound.description | default .Site.Data.default.notFound.description }} + {{ $currentDesc = .Site.Params.notFound.description | emojify | default .Site.Data.default.notFound.description }} {{ end }} @@ -126,7 +126,7 @@ <!-- If the user wants to add something (custom favicons, fonts, scripts, etc) --> -{{ if or (templates.Exists "partials/custom/head-append") (templates.Exists "partials/custom/head-append.html") }} +{{ if (templates.Exists "partials/custom/head-append.html") }} {{ partial "custom/head-append" . }} {{ end }} diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 83e9cfc..8c148f8 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -1,5 +1,5 @@ <!-- Custom or default site title --> -{{ if or (templates.Exists "partials/custom/site-title") (templates.Exists "partials/custom/site-title.html") }} +{{ if (templates.Exists "partials/custom/site-title.html") }} {{ partial "custom/site-title" . }} {{ else }} <a href="{{ .Site.BaseURL | relLangURL }}">{{ .Site.Title }}</a> diff --git a/layouts/partials/table-of-contents.html b/layouts/partials/table-of-contents.html new file mode 100644 index 0000000..2ccd8cc --- /dev/null +++ b/layouts/partials/table-of-contents.html @@ -0,0 +1,9 @@ +{{ if .Params.toc }} + <details class="toc" open> + <summary class="outline-dashed"> + {{ T "tableOfContents" }} + </summary> + + {{ .Page.TableOfContents }} + </details> +{{ end }} \ No newline at end of file -- cgit v1.2.3