Compare commits

...

2 commits

Author SHA1 Message Date
George Cushen
9b3512593a i18n: fix ID 2024-06-01 14:26:24 +01:00
George Cushen
a5aba50938 feat: reimplement backlinks 2024-06-01 14:26:24 +01:00
5 changed files with 22 additions and 34 deletions

View file

@ -1,18 +1,14 @@
{{- $u := urls.Parse .Destination -}}
{{- if or $u.IsAbs (strings.HasPrefix $u.String "#") }}
{{- /* do nothing */}}
{{- else }}
{{- with .PageInner.GetPage (strings.TrimPrefix "./" $u.Path) }}
{{- $source := dict
{{- $url_struct := urls.Parse .Destination -}}
{{/* Ignore anchor links to other sections of the same page. */}}
{{- if not (or $url_struct.IsAbs (strings.HasPrefix $url_struct.String "#")) }}
{{- $page_path := strings.TrimPrefix "./" $url_struct.Path -}}
{{- with .PageInner.GetPage $page_path }}
{{- $page := dict
"date" ($.Page.Date.UTC.Format "2006-01-02T15:04:05-07:00")
"linkTitle" $.Page.LinkTitle
"permalink" $.Page.Permalink
"relPermalink" $.Page.RelPermalink
"section" $.Page.Section
"title" $.Page.Title
"type" $.Page.Type
}}
{{- $el := dict "source" $source "target" .RelPermalink }}
{{- site.Home.Store.Add "backlinks" (slice $el) }}
{{- $backlink := dict "page" $page "links_to" .RelPermalink }}
{{- site.Home.Store.Add "backlinks" (slice $backlink) }}
{{- end }}
{{- end }}

View file

@ -1,9 +1,2 @@
{{- $debug := false }}
{{- range site.Pages }}
{{- $noop := .WordCount }}
{{- end }}
{{- if $debug }}
{{- jsonify (dict "indent" " ") (.Store.Get "backlinks") }}
{{- else }}
{{- jsonify (dict "indent" " ") (dict "comment" "This file is intentionally empty.") }}
{{- end }}
{{- /* Hugo 0.126 requires a `home` layout even if it serves no purpose, otherwise shows warning */ -}}
{{- jsonify dict -}}

View file

@ -28,7 +28,7 @@
{{ if $person.work }}
<div class="w-full">
<h3 class="mb-6 text-3xl font-bold text-gray-900 dark:text-white">{{ i18n "work_experience" | default "Experience" }}</h3>
<h3 class="mb-6 text-3xl font-bold text-gray-900 dark:text-white">{{ i18n "experience" | default "Experience" }}</h3>
<ol class="relative border-s border-gray-200 dark:border-gray-700">
{{ range $idx, $key := $person.work }}
<li class="mb-10 ms-6">

View file

@ -1,20 +1,19 @@
{{ $show_backlinks := .Params.backlinks | default true }}
{{ if $show_backlinks }}
{{- $debug := false }}
{{- $backlinks := site.Home.Store.Get "backlinks" | uniq }}
{{- with (where $backlinks "target" .RelPermalink) }}
{{ $backlinks := site.Home.Store.Get "backlinks" | uniq }}
{{ with (where $backlinks "links_to" .RelPermalink) }}
<div class="backlinks">
<div class="mb-1 font-semibold tracking-tight">
{{ or (T "backlinks") "Backlinks" }}
{{ (T "backlinks") | default "Backlinks" }}
</div>
<ul>
{{- range (sort . "source.linkTitle" "asc") }}
<li><a href="{{ .source.relPermalink }}" class="backlink">{{ .source.linkTitle }}</a></li>
{{- end }}
{{ range (sort . "page.date" "desc") }}
{{ $page := .page }}
<li>
<a href="{{ $page.relPermalink }}" class="backlink">{{ $page.linkTitle }}</a>
</li>
{{ end }}
</ul>
</div>
{{- end }}
{{- if $debug }}
<pre>{{ jsonify (dict "indent" " ") $backlinks }}</pre>
{{- end }}
{{ end }}
{{ end }}

View file

@ -50,7 +50,7 @@
{{- define "toc-headings" -}}
{{- $headings := .headings -}}
{{- $level := .level -}}
{{- if ge $level 5 -}}
{{- if ge $level 4 -}}
{{ return }}
{{- end -}}