From ade244c72af62827c4c30151404abf755597f243 Mon Sep 17 00:00:00 2001 From: Arne Rief Date: Mon, 1 Sep 2025 21:57:30 +0200 Subject: Search & socials --- layouts/_default/list.html | 28 ++++++++------ layouts/_default/search.html | 69 +++++++++++++++++++++++++++++++++++ layouts/index.json | 14 +++++++ layouts/partials/footer.html | 42 +++++++++++++++++++-- layouts/partials/header.html | 4 +- layouts/partials/select-language.html | 39 ++++++++++++++++++++ layouts/partials/select-theme.html | 15 ++++++++ layouts/partials/selectLanguage.html | 39 -------------------- layouts/partials/selectTheme.html | 15 -------- 9 files changed, 195 insertions(+), 70 deletions(-) create mode 100644 layouts/_default/search.html create mode 100644 layouts/index.json create mode 100644 layouts/partials/select-language.html create mode 100644 layouts/partials/select-theme.html delete mode 100644 layouts/partials/selectLanguage.html delete mode 100644 layouts/partials/selectTheme.html (limited to 'layouts') diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 8ff9b18..d3d2d99 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,28 +1,34 @@ {{- define "main" }} -
-
-

+
+
+

{{ .Title }}

+ {{- with .Content }} +
+ {{ . }} +
+ {{- else }} {{- $description := or .Description .Summary (lang.Translate "list.default_description" .Title | default (printf "All posts in %s" .Title)) }} -

- {{ $description }} -

+

+ {{ $description }} +

+ {{- end }}
-
+
{{- /* 20 posts per site */ -}} {{- $paginator := .Paginate .Pages 20 }} {{- with $paginator.Pages }} -
    +
      {{- range . }} -
    • +
    • {{- partial "list/post-card.html" . }}
    • {{- end }}
    - {{- else }} -

    + {{ else }} +

    {{ lang.Translate "list.empty" | default "No posts found in this section." }}

    {{- end }} diff --git a/layouts/_default/search.html b/layouts/_default/search.html new file mode 100644 index 0000000..569cc9a --- /dev/null +++ b/layouts/_default/search.html @@ -0,0 +1,69 @@ +{{ define "main" }} +
    +
    +

    + {{ .Title }} +

    + {{- with .Content }} +
    + {{ . }} +
    + {{- else }} + {{- $description := or .Description (lang.Translate "search.description" | default "Find posts by search term.") }} +

    + {{ $description }} +

    + {{- end }} +
    + +
    + + +
    + +
    + + + + + {{- /* Hidden template, used for hydrating search results from index.json with JS */ -}} + + +
    +
    +{{ end }} diff --git a/layouts/index.json b/layouts/index.json new file mode 100644 index 0000000..29d7e14 --- /dev/null +++ b/layouts/index.json @@ -0,0 +1,14 @@ +{{- $allPages := slice -}} + +{{- range (where site.RegularPages "Section" "!=" "") -}} + {{- $currentPage := dict + "title" .Title + "summary" (.Summary | plainify | htmlUnescape) + "url" .RelPermalink + "date" (.Date.Format "2006-01-02T15:04:05Z07:00") + "tags" .Params.tags + -}} + {{- $allPages = $allPages | append $currentPage -}} +{{- end -}} + +{{ jsonify $allPages }} diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 7225d09..9b66758 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -1,7 +1,43 @@

    © {{ now.Year }} {{ site.Params.author.name }}

    - - - +
    diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 9195345..0f3cfce 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -7,6 +7,6 @@ {{- end }} - {{- partial "selectTheme.html" . }} - {{- partial "selectLanguage.html" . }} + {{- partial "select-theme.html" . }} + {{- partial "select-language.html" . }}

diff --git a/layouts/partials/select-language.html b/layouts/partials/select-language.html new file mode 100644 index 0000000..752b605 --- /dev/null +++ b/layouts/partials/select-language.html @@ -0,0 +1,39 @@ +{{- /* +Selection of available languages. +Dynamically links to corresponding page/post if a translated version exists, otherwise to homepage of that language as fallback. + +Note: `$activeLang` and `$allTranslationsForPage` are technically unnecessary variables, their values could be called with `$.Lang` and `$.Translations` respectively. +These variables - together with the explicit naming of `.` context variables in other cases - were chosen for better readability and understandability of the code. +*/ -}} + +{{- if gt (len site.Languages) 1 }} +{{- $activeLang := .Lang }} +{{- $allTranslationsForPage := .Translations }} +
+
    + {{- range site.Languages }} + {{- $currLangSlice := . }} + {{- if ne $currLangSlice.Lang $activeLang }} + {{- $targetPage := index (where site.Home.Translations "Lang" $currLangSlice.Lang) 0 }} + {{- $translatedPage := index (where $allTranslationsForPage "Lang" $currLangSlice.Lang) 0 }} + {{- if $translatedPage }}{{- $targetPage = $translatedPage }}{{- end }} +
  • + + + +
  • + {{- end }} + {{- end }} +
+
+{{- end }} diff --git a/layouts/partials/select-theme.html b/layouts/partials/select-theme.html new file mode 100644 index 0000000..e9114cc --- /dev/null +++ b/layouts/partials/select-theme.html @@ -0,0 +1,15 @@ + diff --git a/layouts/partials/selectLanguage.html b/layouts/partials/selectLanguage.html deleted file mode 100644 index 752b605..0000000 --- a/layouts/partials/selectLanguage.html +++ /dev/null @@ -1,39 +0,0 @@ -{{- /* -Selection of available languages. -Dynamically links to corresponding page/post if a translated version exists, otherwise to homepage of that language as fallback. - -Note: `$activeLang` and `$allTranslationsForPage` are technically unnecessary variables, their values could be called with `$.Lang` and `$.Translations` respectively. -These variables - together with the explicit naming of `.` context variables in other cases - were chosen for better readability and understandability of the code. -*/ -}} - -{{- if gt (len site.Languages) 1 }} -{{- $activeLang := .Lang }} -{{- $allTranslationsForPage := .Translations }} -
-
    - {{- range site.Languages }} - {{- $currLangSlice := . }} - {{- if ne $currLangSlice.Lang $activeLang }} - {{- $targetPage := index (where site.Home.Translations "Lang" $currLangSlice.Lang) 0 }} - {{- $translatedPage := index (where $allTranslationsForPage "Lang" $currLangSlice.Lang) 0 }} - {{- if $translatedPage }}{{- $targetPage = $translatedPage }}{{- end }} -
  • - - - -
  • - {{- end }} - {{- end }} -
-
-{{- end }} diff --git a/layouts/partials/selectTheme.html b/layouts/partials/selectTheme.html deleted file mode 100644 index e9114cc..0000000 --- a/layouts/partials/selectTheme.html +++ /dev/null @@ -1,15 +0,0 @@ - -- cgit v1.2.3