From dd6f7b578b9073f363d41f0e5575767226528f57 Mon Sep 17 00:00:00 2001 From: Henk Verlinde Date: Tue, 21 Jun 2022 20:52:44 +0200 Subject: [PATCH 01/28] feat: add to top button as an option --- assets/js/to-top.js | 20 ++++++++++++++++++++ config/_default/params.toml | 1 + layouts/_default/baseof.html | 5 +++++ layouts/partials/footer/script-footer.html | 6 ++++++ 4 files changed, 32 insertions(+) create mode 100644 assets/js/to-top.js diff --git a/assets/js/to-top.js b/assets/js/to-top.js new file mode 100644 index 0000000..3287f43 --- /dev/null +++ b/assets/js/to-top.js @@ -0,0 +1,20 @@ +var topbutton = document.getElementById('toTop'); + +if (topbutton !== null) { + + topbutton.style.display = 'none'; + window.onscroll = function() { + scrollFunction() + }; + +} + +function scrollFunction() { + + if (document.body.scrollTop > 40 || document.documentElement.scrollTop > 40) { + topbutton.style.display = 'block'; + } else { + topbutton.style.display = 'none'; + } + +} diff --git a/config/_default/params.toml b/config/_default/params.toml index 5780d96..f241b10 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -92,6 +92,7 @@ lastMod = false docsVersioning = false fullWidth = false navbarSticky = true + toTopButton = true [menu] [menu.section] diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index b8b4273..561b8e2 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -23,5 +23,10 @@ {{ block "sidebar-footer" . }}{{ end }} {{ partial "footer/footer.html" . }} {{ partial "footer/script-footer.html" . }} + {{ if eq .Site.Params.options.toTopButton true -}} +
+ Top +
+ {{ end }} \ No newline at end of file diff --git a/layouts/partials/footer/script-footer.html b/layouts/partials/footer/script-footer.html index f57261a..cc77b65 100644 --- a/layouts/partials/footer/script-footer.html +++ b/layouts/partials/footer/script-footer.html @@ -60,6 +60,12 @@ {{ $scrollLock := resources.Get "js/scroll-lock.js" | js.Build -}} {{ $slice = $slice | append $scrollLock -}} +{{ if .Site.Params.options.toTopButton -}} + {{ $toTopButton := resources.Get "js/to-top.js" -}} + {{ $toTopButton := $toTopButton | js.Build -}} + {{ $slice = $slice | append $toTopButton -}} +{{ end -}} + {{ $js := $slice | resources.Concat "main.js" -}} {{ if eq (hugo.Environment) "development" -}} From 21ba62dcc809138b4bc6185b46d5e924d8d46047 Mon Sep 17 00:00:00 2001 From: James Elliott Date: Thu, 23 Jun 2022 12:26:16 +1000 Subject: [PATCH 02/28] fix(menus): sort pages and sections by default order This restores the default hugo sorting behaviour. --- content/en/docs/help/_index.md | 1 + content/en/docs/prologue/_index.md | 1 + layouts/partials/sidebar/auto-collapsible-menu.html | 4 ++-- layouts/partials/sidebar/auto-default-menu.html | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/content/en/docs/help/_index.md b/content/en/docs/help/_index.md index bc503ec..b5763a3 100644 --- a/content/en/docs/help/_index.md +++ b/content/en/docs/help/_index.md @@ -6,4 +6,5 @@ date: 2020-10-06T08:49:15+00:00 lastmod: 2020-10-06T08:49:15+00:00 draft: false images: [] +weight: 600 --- diff --git a/content/en/docs/prologue/_index.md b/content/en/docs/prologue/_index.md index c3c1c40..d6b467c 100644 --- a/content/en/docs/prologue/_index.md +++ b/content/en/docs/prologue/_index.md @@ -6,4 +6,5 @@ date: 2020-10-06T08:48:45+00:00 lastmod: 2020-10-06T08:48:45+00:00 draft: false images: [] +weight: 100 --- diff --git a/layouts/partials/sidebar/auto-collapsible-menu.html b/layouts/partials/sidebar/auto-collapsible-menu.html index 3eaa2f6..4600d0a 100644 --- a/layouts/partials/sidebar/auto-collapsible-menu.html +++ b/layouts/partials/sidebar/auto-collapsible-menu.html @@ -3,7 +3,7 @@ {{ $currentPage := . -}} {{ $section := $currentPage.Section -}} {{ range (where .Site.Sections "Section" "in" $section) }} - {{ range .Sections.ByWeight.Reverse }} + {{ range .Sections }} {{ $active := in $currentPage.RelPermalink .RelPermalink }}
  • {{ end }} {{ end }} - \ No newline at end of file + diff --git a/layouts/partials/sidebar/auto-default-menu.html b/layouts/partials/sidebar/auto-default-menu.html index b46bb5a..6e4565b 100644 --- a/layouts/partials/sidebar/auto-default-menu.html +++ b/layouts/partials/sidebar/auto-default-menu.html @@ -2,7 +2,7 @@ {{ $currentPage := . -}} {{ $section := $currentPage.Section -}} {{ range (where .Site.Sections "Section" "in" $section) }} - {{ range .Sections.ByWeight.Reverse }} + {{ range .Sections }} {{ $active := in $currentPage.RelPermalink .RelPermalink }}

    {{ .Title }}

    - {{ if and .Site.Params.options.flexSearch (or (eq (len .Site.Params.options.searchSectionsShow) 0) (in .Site.Params.options.searchSectionsShow .Section)) -}} + {{- $showFlexSearch := .Site.Params.options.flexSearch }} + {{- if $showFlexSearch }} + {{- if (isset .Site.Params.options "searchsectionsshow") }} + {{- $showFlexSearch = or (eq (len .Site.Params.options.searchSectionsShow) 0) (in .Site.Params.options.searchSectionsShow .Section) }} + {{- end }} + {{- end }} + + {{ if $showFlexSearch -}}
    From b532c69bd769353490e412e22d790e484aeb91dc Mon Sep 17 00:00:00 2001 From: James Elliott Date: Sat, 25 Jun 2022 13:36:32 +1000 Subject: [PATCH 08/28] feat: add all method --- assets/js/index.js | 8 ++++++-- layouts/partials/footer/script-footer.html | 2 +- layouts/partials/header/header.html | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/assets/js/index.js b/assets/js/index.js index 2f47890..0c2de5d 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -95,11 +95,15 @@ Source: // https://discourse.gohugo.io/t/range-length-or-last-element/3803/2 {{ $list := slice }} - {{- if or (not (isset .Site.Params.options "searchsectionsindex")) (eq (len .Site.Params.options.searchSectionsIndex) 0) }} - {{- $list = (where .Site.Pages "Section" "docs") }} + {{- if and (isset .Site.Params.options "searchsectionsindex") (not (eq (len .Site.Params.options.searchSectionsIndex) 0)) }} + {{- if eq .Site.Params.options.searchSectionsIndex "ALL" }} + {{- $list = .Site.Pages }} {{- else }} {{- $list = (where .Site.Pages "Type" "in" .Site.Params.options.searchSectionsIndex) }} {{- end }} + {{- else }} + {{- $list = (where .Site.Pages "Section" "docs") }} + {{- end }} {{ $len := (len $list) -}} diff --git a/layouts/partials/footer/script-footer.html b/layouts/partials/footer/script-footer.html index 769494a..1a571d1 100644 --- a/layouts/partials/footer/script-footer.html +++ b/layouts/partials/footer/script-footer.html @@ -39,7 +39,7 @@ {{ if $showFlexSearch -}} {{ $flexSearch := resources.Get "js/vendor/flexsearch/dist/flexsearch.bundle.js" -}} {{ $slice = $slice | append $flexSearch -}} - {{ if (isset .Site.Params.options "searchsectionsshow") -}} + {{ if and (isset .Site.Params.options "searchsectionsshow") (not (eq .Site.Params.options.searchSectionsShow "ALL")) -}} {{ $showFlexSearch = or (eq (len .Site.Params.options.searchSectionsShow) 0) (in .Site.Params.options.searchSectionsShow .Section) -}} {{ end -}} {{ end -}} diff --git a/layouts/partials/header/header.html b/layouts/partials/header/header.html index 8b4e4ca..77c24de 100644 --- a/layouts/partials/header/header.html +++ b/layouts/partials/header/header.html @@ -79,7 +79,7 @@ {{- $showFlexSearch := .Site.Params.options.flexSearch }} {{- if $showFlexSearch }} - {{- if (isset .Site.Params.options "searchsectionsshow") }} + {{- if and (isset .Site.Params.options "searchsectionsshow") (not (eq .Site.Params.options.searchSectionsShow "ALL")) }} {{- $showFlexSearch = or (eq (len .Site.Params.options.searchSectionsShow) 0) (in .Site.Params.options.searchSectionsShow .Section) }} {{- end }} {{- end }} From 76d7db7b4c3514cebfd1631a2fdb29234b400221 Mon Sep 17 00:00:00 2001 From: James Elliott Date: Sat, 25 Jun 2022 21:54:54 +1000 Subject: [PATCH 09/28] feat: handle homepage for search sections show --- layouts/partials/footer/script-footer.html | 2 +- layouts/partials/header/header.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/layouts/partials/footer/script-footer.html b/layouts/partials/footer/script-footer.html index 1a571d1..7240b00 100644 --- a/layouts/partials/footer/script-footer.html +++ b/layouts/partials/footer/script-footer.html @@ -40,7 +40,7 @@ {{ $flexSearch := resources.Get "js/vendor/flexsearch/dist/flexsearch.bundle.js" -}} {{ $slice = $slice | append $flexSearch -}} {{ if and (isset .Site.Params.options "searchsectionsshow") (not (eq .Site.Params.options.searchSectionsShow "ALL")) -}} - {{ $showFlexSearch = or (eq (len .Site.Params.options.searchSectionsShow) 0) (in .Site.Params.options.searchSectionsShow .Section) -}} + {{ $showFlexSearch = or (eq (len .Site.Params.options.searchSectionsShow) 0) (in .Site.Params.options.searchSectionsShow .Section) (and .IsHome (in .Site.Params.options.searchSectionsShow "HomePage")) -}} {{ end -}} {{ end -}} diff --git a/layouts/partials/header/header.html b/layouts/partials/header/header.html index 77c24de..d6e0f6e 100644 --- a/layouts/partials/header/header.html +++ b/layouts/partials/header/header.html @@ -80,7 +80,7 @@ {{- $showFlexSearch := .Site.Params.options.flexSearch }} {{- if $showFlexSearch }} {{- if and (isset .Site.Params.options "searchsectionsshow") (not (eq .Site.Params.options.searchSectionsShow "ALL")) }} - {{- $showFlexSearch = or (eq (len .Site.Params.options.searchSectionsShow) 0) (in .Site.Params.options.searchSectionsShow .Section) }} + {{- $showFlexSearch = or (eq (len .Site.Params.options.searchSectionsShow) 0) (in .Site.Params.options.searchSectionsShow .Section) (and .IsHome (in .Site.Params.options.searchSectionsShow "HomePage")) }} {{- end }} {{- end }} From 8588fe5b16838d9c848102b4b16d59cf12ec5359 Mon Sep 17 00:00:00 2001 From: James Elliott Date: Sat, 25 Jun 2022 21:59:06 +1000 Subject: [PATCH 10/28] feat: handle homepage for search sections index --- assets/js/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/assets/js/index.js b/assets/js/index.js index 0c2de5d..15e09bb 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -100,6 +100,9 @@ Source: {{- $list = .Site.Pages }} {{- else }} {{- $list = (where .Site.Pages "Type" "in" .Site.Params.options.searchSectionsIndex) }} + {{- if (in .Site.Params.options.searchSectionsIndex "HomePage") }} + {{ $list = $list | append .Site.Home }} + {{- end }} {{- end }} {{- else }} {{- $list = (where .Site.Pages "Section" "docs") }} From 59a3f00529dbacae1882c9a27b38eac7d3a5ef83 Mon Sep 17 00:00:00 2001 From: Henk Verlinde Date: Mon, 27 Jun 2022 14:41:00 +0200 Subject: [PATCH 11/28] feat: update blog pages --- assets/images/.gitkeep | 0 .../images/default-image.png | Bin assets/js/highlight.js | 2 + assets/scss/common/_global.scss | 4 +- assets/scss/layouts/_posts.scss | 35 +++++++++++++++-- config/_default/config.toml | 14 +++++++ config/_default/params.toml | 4 ++ content/en/blog/say-hello-to-doks/index.md | 6 +-- layouts/_default/list.html | 35 +++++++++++++---- layouts/_default/terms.html | 20 ++++++++++ layouts/blog/list.html | 24 ------------ layouts/blog/single.html | 37 ++++++++++++++++-- layouts/contributors/list.html | 23 ----------- layouts/partials/content/card-image.html | 14 +++++++ layouts/partials/header/header.html | 2 +- 15 files changed, 154 insertions(+), 66 deletions(-) delete mode 100644 assets/images/.gitkeep rename content/en/blog/say-hello-to-doks/say-hello-to-doks.png => assets/images/default-image.png (100%) create mode 100644 layouts/_default/terms.html delete mode 100644 layouts/blog/list.html delete mode 100644 layouts/contributors/list.html create mode 100644 layouts/partials/content/card-image.html diff --git a/assets/images/.gitkeep b/assets/images/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/content/en/blog/say-hello-to-doks/say-hello-to-doks.png b/assets/images/default-image.png similarity index 100% rename from content/en/blog/say-hello-to-doks/say-hello-to-doks.png rename to assets/images/default-image.png diff --git a/assets/js/highlight.js b/assets/js/highlight.js index c96b781..4ad6017 100644 --- a/assets/js/highlight.js +++ b/assets/js/highlight.js @@ -7,6 +7,7 @@ import xml from 'highlight.js/lib/languages/xml'; import ini from 'highlight.js/lib/languages/ini'; import yaml from 'highlight.js/lib/languages/yaml'; import markdown from 'highlight.js/lib/languages/markdown'; +import python from 'highlight.js/lib/languages/python'; hljs.registerLanguage('javascript', javascript); hljs.registerLanguage('json', json); @@ -16,6 +17,7 @@ hljs.registerLanguage('ini', ini); hljs.registerLanguage('toml', ini); hljs.registerLanguage('yaml', yaml); hljs.registerLanguage('md', markdown); +hljs.registerLanguage('python', python); document.addEventListener('DOMContentLoaded', () => { document.querySelectorAll('pre code:not(.language-mermaid)').forEach((block) => { diff --git a/assets/scss/common/_global.scss b/assets/scss/common/_global.scss index cbc8e41..e1cee67 100644 --- a/assets/scss/common/_global.scss +++ b/assets/scss/common/_global.scss @@ -4,7 +4,9 @@ .error404 .content, .docs.list .content, .tutorial.list .content, -.showcase.list .content { +.showcase.list .content, +.categories.list .content, +.tags.list .content { padding-top: 1rem; padding-bottom: 3rem; } diff --git a/assets/scss/layouts/_posts.scss b/assets/scss/layouts/_posts.scss index da27660..27d316a 100644 --- a/assets/scss/layouts/_posts.scss +++ b/assets/scss/layouts/_posts.scss @@ -1,6 +1,9 @@ .home .card, .contributors.list .card, -.blog.list .card { +.blog.list .card, +.blog.single .card, +.categories.list .card, +.tags.list .card { margin-top: 2rem; margin-bottom: 2rem; transition: transform 0.3s; @@ -8,16 +11,34 @@ .home .card:hover, .contributors.list .card:hover, -.blog.list .card:hover { +.blog.list .card:hover, +.blog.single .card:hover, +.categories.list .card:hover, +.tags.list .card:hover { transform: scale(1.025); } +.contributors.list .card.card-terms:hover, +.categories.list .card.card-terms:hover, +.tags.list .card.card-terms:hover { + transform: none; +} + .home .card-body, .contributors.list .card-body, -.blog.list .card-body { +.blog.list .card-body, +.blog.single .card-body, +.categories.list .card-body, +.tags.list .card-body { padding: 0 2rem 1rem; } +.contributors.list .card-terms .card-body, +.categories.list .card-terms .card-body, +.tags.list .card-terms .card-body { + padding: 1rem; +} + .blog-header { text-align: center; margin-bottom: 2rem; @@ -26,3 +47,11 @@ .blog-footer { text-align: center; } + +.related-posts { + margin-top: 4rem; +} + +h2.section-title { + margin-bottom: 1.25rem; +} diff --git a/config/_default/config.toml b/config/_default/config.toml index 086f8b4..321aa14 100644 --- a/config/_default/config.toml +++ b/config/_default/config.toml @@ -69,6 +69,20 @@ rel = "sitemap" [minify.tdewolff.html] keepWhitespace = false +[related] + threshold = 80 + includeNewer = true + toLower = false + [[related.indices]] + name = "categories" + weight = 100 + [[related.indices]] + name = "tags" + weight = 80 + [[related.indices]] + name = "date" + weight = 10 + [module] [module.hugoVersion] extended = true diff --git a/config/_default/params.toml b/config/_default/params.toml index 5780d96..3af900c 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -53,6 +53,10 @@ portraitPhotoWidths = [800, 700, 600, 500] lqipWidth = "20x" smallLimit = "300" +### Image template +defaultImage = "default-image.png" # put in `./assets/images/` +fillImage = "1270x740 Center" # normalize image size + # Footer footer = "Powered by Netlify, Hugo, and Doks" diff --git a/content/en/blog/say-hello-to-doks/index.md b/content/en/blog/say-hello-to-doks/index.md index d86eb93..cc97343 100644 --- a/content/en/blog/say-hello-to-doks/index.md +++ b/content/en/blog/say-hello-to-doks/index.md @@ -6,9 +6,9 @@ date: 2020-11-04T09:19:42+01:00 lastmod: 2020-11-04T09:19:42+01:00 draft: false weight: 50 -images: ["say-hello-to-doks.png"] -categories: [] -tags: [] +images: [] +categories: ["Startups", "News"] +tags: ["security"] contributors: ["Henk Verlinde"] pinned: false homepage: false diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 1401ccd..2778b20 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,13 +1,32 @@ {{ define "main" }}
    -
    - {{ range .Paginator.Pages }} - - {{ end }} - {{ template "_internal/pagination.html" . }} +
    +

    {{ .Title }}

    + {{ with .Content -}}
    {{ . }}
    {{ end -}} +
    +
    +
    + {{ $paginator := .Paginate (.Data.Pages) -}} + {{ range $paginator.Pages -}} +
    +
    + {{- .Scratch.Set "fillImage" "1270x620 Center" -}} + {{ partial "content/card-image.html" . }} +
    +
    +

    {{ .Params.title }}

    +

    {{ .Params.excerpt | safeHTML }}

    + {{ partial "main/blog-meta.html" . -}} +
    +
    +
    +
    + {{ end -}} +
    +
    +
    + {{ $.Scratch.Set "paginator" true }} + {{ template "_internal/pagination.html" . }}
    {{ end }} \ No newline at end of file diff --git a/layouts/_default/terms.html b/layouts/_default/terms.html new file mode 100644 index 0000000..73fdeb8 --- /dev/null +++ b/layouts/_default/terms.html @@ -0,0 +1,20 @@ +{{ define "main" }} +
    +
    +

    {{ .Title }}

    +
    {{ .Content }}
    +
    + {{ range .Paginator.Pages }} + + {{ end }} +
    + {{ template "_internal/pagination.html" . }} +
    +
    +{{ end }} diff --git a/layouts/blog/list.html b/layouts/blog/list.html deleted file mode 100644 index 4e2a770..0000000 --- a/layouts/blog/list.html +++ /dev/null @@ -1,24 +0,0 @@ -{{ define "main" }} -
    -
    -
    -

    {{ .Title }}

    -
    {{ .Content }}
    -
    - {{ $paginator := .Paginate (.Data.Pages) -}} - {{ range $paginator.Pages -}} -
    -
    -

    {{ .Params.title }}

    -

    {{ .Params.excerpt | safeHTML }}

    - {{ partial "main/blog-meta.html" . -}} -
    -
    - {{ end -}} - {{ $.Scratch.Set "paginator" true }} - {{ template "_internal/pagination.html" . }} -
    -
    -
    -
    -{{ end }} \ No newline at end of file diff --git a/layouts/blog/single.html b/layouts/blog/single.html index 2ff4294..87cdd29 100644 --- a/layouts/blog/single.html +++ b/layouts/blog/single.html @@ -8,13 +8,13 @@ {{ partial "main/blog-meta.html" . }}
    -
    +
    {{- .Scratch.Set "fillImage" "1270x620 Center" -}} {{ partial "content/figure.html" . }}
    -
    +
    {{ .Content }} {{ if .Params.tags -}}
    @@ -26,4 +26,35 @@
    -{{ end }} \ No newline at end of file + +{{ $related := .Site.RegularPages.Related . | first 3 -}} +{{ with $related -}} + +{{ end -}} + +{{ end }} + + diff --git a/layouts/contributors/list.html b/layouts/contributors/list.html deleted file mode 100644 index 414646e..0000000 --- a/layouts/contributors/list.html +++ /dev/null @@ -1,23 +0,0 @@ -{{ define "main" }} -
    -
    -
    -

    {{ .Title }}

    -
    {{ .Content }}
    -
    - {{ range .Data.Pages -}} -
    -
    -

    {{ .Params.title }}

    - {{ if eq .Section "blog" -}} -

    {{ .Params.excerpt | safeHTML }}

    - {{ partial "main/blog-meta.html" . -}} - {{ end -}} -
    -
    - {{ end -}} -
    -
    -
    -
    -{{ end }} \ No newline at end of file diff --git a/layouts/partials/content/card-image.html b/layouts/partials/content/card-image.html new file mode 100644 index 0000000..c20f2da --- /dev/null +++ b/layouts/partials/content/card-image.html @@ -0,0 +1,14 @@ +{{ $fillImage := .Scratch.Get "fillImage" }} +{{ if not $fillImage -}} + {{ $fillImage = site.Params.fillImage }} +{{ end -}} + +{{ $image := .Resources.GetMatch (printf "**%s" (index .Params.images 0)) }} +{{ if not $image -}} + {{ $image = resources.Get (printf "%s%s" "images/" site.Params.defaultImage) }} +{{ end -}} + +{{ $image = $image.Fill $fillImage }} +{{ $lqip := $image.Resize site.Params.lqipWidth -}} + +{{ .Title }} diff --git a/layouts/partials/header/header.html b/layouts/partials/header/header.html index 65744ec..9881d8c 100644 --- a/layouts/partials/header/header.html +++ b/layouts/partials/header/header.html @@ -53,7 +53,7 @@ {{- $active := or ($current.IsMenuCurrent "main" .) ($current.HasMenuCurrent "main" .) -}} {{- $active = or $active (eq .Name $current.Title) -}} {{- $active = or $active (and (eq .Name ($section | humanize)) (eq $current.Section $section)) -}} - {{- $active = or $active (and (eq .Name "Blog") (eq $current.Section "blog" "contributors")) -}} + {{- $active = or $active (and (eq .Name "Blog") (eq $current.Section "blog" "contributors" "categories" "tags")) -}} {{ if .HasChildren }}