From 9620f0ff31fe3391e6d070c724d5f079c58b3746 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Sun, 29 Sep 2024 18:12:59 +0200 Subject: Code cleanup and minor fixes --- layouts/_default/index.json | 59 +++++++++++++++++++++++++++++++++++++++++ layouts/index.json | 59 ----------------------------------------- layouts/partials/post-tags.html | 2 +- 3 files changed, 60 insertions(+), 60 deletions(-) create mode 100644 layouts/_default/index.json delete mode 100644 layouts/index.json (limited to 'layouts') diff --git a/layouts/_default/index.json b/layouts/_default/index.json new file mode 100644 index 0000000..7f30c80 --- /dev/null +++ b/layouts/_default/index.json @@ -0,0 +1,59 @@ +{{- /* Generate the search index. */ -}} +{{- $pages := slice -}} + +{{- $mainSections := site.Params.mainSections | default (slice "posts") -}} +{{- $pages = where site.RegularPages.ByDate.Reverse "Type" "in" $mainSections -}} + +{{- $.Scratch.Add "pagesIndex" slice -}} +{{- $.Scratch.Add "urlsAdded" slice -}} + +{{- range $index, $page := $pages -}} + {{- /* Do not index drafts or private pages. */ -}} + {{- if and (not .Draft) (not .Params.private) | and (ne .Params.searchable false) -}} + + {{- /* Do not index pages w/o content. */ -}} + {{- if gt (len $page.Content) 0 -}} + + {{- /* Add page to index. */ -}} + {{- if not (in ($.Scratch.Get "urlsAdded") $page.Permalink) -}} + + {{- /* Exclude virtual pages which aren't backed by a file */ -}} + {{ if .File -}} + + {{- $publishDate := $page.PublishDate -}} + {{- if $publishDate.IsZero -}} + {{ $publishDate = now -}} + {{- end -}} + + {{- $modifiedDate := $page.Lastmod -}} + {{- if $modifiedDate.IsZero -}} + {{ $modifiedDate = $publishDate -}} + {{- end -}} + + {{- $pageData := (dict + "objectID" $page.File.UniqueID + "title" $page.Title + "href" $page.Permalink + "lang" ($page.Params.lang | default $page.Lang) + "tags" ($page.Params.tags | default slice) + "kind" $page.Kind + "type" $page.Type + "section" $page.Section + "content" (trim $page.Plain "\n ") + "publishDate" $publishDate + "lastmod" $modifiedDate + ) -}} + + {{- $.Scratch.Add "pagesIndex" $pageData -}} + {{- $.Scratch.Add "urlsAdded" $page.Permalink -}} + {{- end -}} + + {{- end -}} + + {{- end -}} + + {{- end -}} + +{{- end -}} + +{{- $.Scratch.Get "pagesIndex" | jsonify -}} diff --git a/layouts/index.json b/layouts/index.json deleted file mode 100644 index de685ff..0000000 --- a/layouts/index.json +++ /dev/null @@ -1,59 +0,0 @@ -{{- /* Generate the search index. */ -}} -{{- $pages := slice -}} - -{{- $mainSections := site.Params.mainSections | default (slice "posts") }} -{{- $pages = where site.RegularPages.ByDate.Reverse "Type" "in" $mainSections -}} - -{{- $.Scratch.Add "pagesIndex" slice -}} -{{- $.Scratch.Add "urlsAdded" slice -}} - -{{- range $index, $page := $pages -}} - {{- /* Do not index drafts or private pages. */ -}} - {{- if and (not .Draft) (not .Params.private) | and (ne .Params.searchable false) -}} - - {{- /* Do not index pages w/o content. */ -}} - {{- if gt (len $page.Content) 0 -}} - - {{- /* Add page to index. */ -}} - {{- if not (in ($.Scratch.Get "urlsAdded") $page.Permalink) -}} - - {{/* Exclude virtual pages which aren't backed by a file */}} - {{ if .File }} - - {{- $publishDate := $page.PublishDate -}} - {{- if $publishDate.IsZero -}} - {{ $publishDate = now -}} - {{- end -}} - - {{- $modifiedDate := $page.Lastmod -}} - {{- if $modifiedDate.IsZero -}} - {{ $modifiedDate = $publishDate -}} - {{- end -}} - - {{- $pageData := (dict - "objectID" $page.File.UniqueID - "title" $page.Title - "href" $page.Permalink - "lang" ($page.Params.lang | default $page.Lang) - "tags" ($page.Params.tags | default slice) - "kind" $page.Kind - "type" $page.Type - "section" $page.Section - "content" (trim $page.Plain "\n ") - "publishDate" $publishDate - "lastmod" $modifiedDate - ) -}} - - {{- $.Scratch.Add "pagesIndex" $pageData -}} - {{- $.Scratch.Add "urlsAdded" $page.Permalink -}} - {{- end -}} - - {{- end -}} - - {{- end -}} - - {{- end -}} - -{{- end -}} - -{{- $.Scratch.Get "pagesIndex" | jsonify -}} diff --git a/layouts/partials/post-tags.html b/layouts/partials/post-tags.html index 267bbab..68d29c2 100644 --- a/layouts/partials/post-tags.html +++ b/layouts/partials/post-tags.html @@ -4,7 +4,7 @@