mirror of
https://github.com/gcushen/hugo-academic.git
synced 2025-07-23 10:00:52 +02:00
feat: reimplement backlinks
This commit is contained in:
parent
8d25fbed12
commit
a5aba50938
3 changed files with 20 additions and 32 deletions
|
@ -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 }}
|
||||
|
|
|
@ -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 -}}
|
||||
|
|
|
@ -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 }}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue