mirror of
https://github.com/gcushen/hugo-academic.git
synced 2025-07-23 18:10:52 +02:00
feat: add support for backlinks
Enabled by default in right sidebar. Can be disabled with `backlinks: false` in front matter. See https://github.com/gohugoio/hugo/issues
This commit is contained in:
parent
c2e9a799f7
commit
971f297e46
8 changed files with 87 additions and 3 deletions
|
@ -80,3 +80,7 @@
|
||||||
z-index: -1;
|
z-index: -1;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.backlink {
|
||||||
|
@apply text-xs font-medium text-gray-500 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100 contrast-more:text-gray-800 contrast-more:dark:text-gray-50;
|
||||||
|
}
|
||||||
|
|
4
modules/blox-tailwind/assets/dist/wc.min.css
vendored
4
modules/blox-tailwind/assets/dist/wc.min.css
vendored
File diff suppressed because one or more lines are too long
|
@ -1,13 +1,20 @@
|
||||||
markup:
|
markup:
|
||||||
defaultMarkdownHandler: goldmark
|
defaultMarkdownHandler: goldmark
|
||||||
goldmark:
|
goldmark:
|
||||||
|
renderHooks:
|
||||||
|
link:
|
||||||
|
# Process backlinks hook
|
||||||
|
enableDefault: true
|
||||||
renderer:
|
renderer:
|
||||||
|
# Render HTML in Markdown
|
||||||
unsafe: true
|
unsafe: true
|
||||||
parser:
|
parser:
|
||||||
|
# Support Latex math(?)
|
||||||
attribute:
|
attribute:
|
||||||
block: true
|
block: true
|
||||||
title: true
|
title: true
|
||||||
extensions:
|
extensions:
|
||||||
|
# Support Latex math
|
||||||
passthrough:
|
passthrough:
|
||||||
enable: true
|
enable: true
|
||||||
delimiters:
|
delimiters:
|
||||||
|
@ -21,7 +28,18 @@ markup:
|
||||||
- \)
|
- \)
|
||||||
- - $
|
- - $
|
||||||
- $
|
- $
|
||||||
|
extras:
|
||||||
|
# Enable subscript, superscript, and highlighting with ~,^, and == wrappers
|
||||||
|
insert:
|
||||||
|
enable: false
|
||||||
|
mark:
|
||||||
|
enable: true
|
||||||
|
subscript:
|
||||||
|
enable: true
|
||||||
|
superscript:
|
||||||
|
enable: true
|
||||||
highlight:
|
highlight:
|
||||||
|
# Enable code highlighting
|
||||||
codeFences: true
|
codeFences: true
|
||||||
noHl: false
|
noHl: false
|
||||||
lineNumbersInTable: false
|
lineNumbersInTable: false
|
||||||
|
@ -31,14 +49,16 @@ markup:
|
||||||
startLevel: 2
|
startLevel: 2
|
||||||
endLevel: 3
|
endLevel: 3
|
||||||
minify:
|
minify:
|
||||||
|
minifyOutput: true
|
||||||
tdewolff:
|
tdewolff:
|
||||||
html:
|
html:
|
||||||
keepComments: true
|
keepComments: true
|
||||||
|
keepSpecialComments: true
|
||||||
sitemap:
|
sitemap:
|
||||||
changefreq: weekly
|
changefreq: weekly
|
||||||
module:
|
module:
|
||||||
hugoVersion:
|
hugoVersion:
|
||||||
min: '0.122.0'
|
min: '0.126.0'
|
||||||
extended: true
|
extended: true
|
||||||
imports:
|
imports:
|
||||||
- path: github.com/HugoBlox/hugo-blox-builder/modules/blox-analytics
|
- path: github.com/HugoBlox/hugo-blox-builder/modules/blox-analytics
|
||||||
|
@ -62,6 +82,14 @@ security:
|
||||||
getenv:
|
getenv:
|
||||||
- ^HUGO_
|
- ^HUGO_
|
||||||
- ^WC_
|
- ^WC_
|
||||||
|
- ^HB_
|
||||||
|
outputFormats:
|
||||||
|
backlinks:
|
||||||
|
mediaType: application/json
|
||||||
|
baseName: backlinks
|
||||||
|
isPlainText: true
|
||||||
|
notAlternative: true
|
||||||
|
weight: 1
|
||||||
params:
|
params:
|
||||||
locale:
|
locale:
|
||||||
date_format: 'Jan 2, 2006'
|
date_format: 'Jan 2, 2006'
|
||||||
|
|
|
@ -26,6 +26,9 @@
|
||||||
- id: related
|
- id: related
|
||||||
translation: Related
|
translation: Related
|
||||||
|
|
||||||
|
- id: backlinks
|
||||||
|
translation: Backlinks
|
||||||
|
|
||||||
- id: minute_read
|
- id: minute_read
|
||||||
translation: min read
|
translation: min read
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
{{- $u := urls.Parse .Destination -}}
|
||||||
|
{{- if or $u.IsAbs (strings.HasPrefix $u.String "#") }}
|
||||||
|
{{- /* do nothing */}}
|
||||||
|
{{- else }}
|
||||||
|
{{- with .PageInner.GetPage (strings.TrimPrefix "./" $u.Path) }}
|
||||||
|
{{- $source := 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) }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{{- $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 }}
|
|
@ -0,0 +1,20 @@
|
||||||
|
{{ $show_backlinks := .Params.backlinks | default true }}
|
||||||
|
{{ if $show_backlinks }}
|
||||||
|
{{- $debug := false }}
|
||||||
|
{{- $backlinks := site.Home.Store.Get "backlinks" | uniq }}
|
||||||
|
{{- with (where $backlinks "target" .RelPermalink) }}
|
||||||
|
<div class="backlinks">
|
||||||
|
<div class="mb-1 font-semibold tracking-tight">
|
||||||
|
{{ or (T "backlinks") "Backlinks" }}
|
||||||
|
</div>
|
||||||
|
<ul>
|
||||||
|
{{- range (sort . "source.linkTitle" "asc") }}
|
||||||
|
<li><a href="{{ .source.relPermalink }}" class="backlink">{{ .source.linkTitle }}</a></li>
|
||||||
|
{{- end }}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{{- end }}
|
||||||
|
{{- if $debug }}
|
||||||
|
<pre>{{ jsonify (dict "indent" " ") $backlinks }}</pre>
|
||||||
|
{{- end }}
|
||||||
|
{{ end }}
|
|
@ -38,6 +38,8 @@
|
||||||
</div>
|
</div>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
|
{{ partial "components/backlinks" . }}
|
||||||
|
|
||||||
{{ partial "functions/get_hook" (dict "hook" "toc-end" "context" .) }}
|
{{ partial "functions/get_hook" (dict "hook" "toc-end" "context" .) }}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue