Skip to content

Commit

Permalink
Merge pull request #1108 from gethinode/develop
Browse files Browse the repository at this point in the history
Fix embedded and anchor links
  • Loading branch information
markdumay authored Aug 16, 2024
2 parents d3f471a + cfd1706 commit 7413155
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 53 deletions.
33 changes: 5 additions & 28 deletions hugo_stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"htmlElements": {
"tags": [
"a",
"annotation",
"body",
"button",
"div",
Expand All @@ -16,29 +15,13 @@
"label",
"li",
"link",
"math",
"meta",
"mfrac",
"mi",
"mn",
"mo",
"mpadded",
"mphantom",
"mrow",
"mspace",
"msqrt",
"mstyle",
"msub",
"msup",
"mtext",
"munder",
"nav",
"noscript",
"ol",
"p",
"path",
"script",
"semantics",
"small",
"span",
"strong",
Expand Down Expand Up @@ -76,12 +59,10 @@
"col-6",
"col-lg-2",
"col-lg-8",
"col-md-2",
"col-md-3",
"col-md-4",
"col-md-8",
"col-md-9",
"col-sm-12",
"collapse",
"collapsed",
"container-fluid",
Expand All @@ -92,16 +73,14 @@
"d-md-block",
"d-md-none",
"d-none",
"display-1",
"display-4",
"emphasis",
"end-0",
"fa",
"fa-10x",
"fa-2x",
"fa-arrow-left",
"fa-arrow-right",
"fa-book-open",
"fa-ellipsis",
"fa-face-frown",
"fa-facebook",
"fa-fw",
"fa-github",
Expand Down Expand Up @@ -137,15 +116,13 @@
"justify-content-center",
"justify-content-end",
"justify-content-start",
"katex",
"label",
"lead",
"link-bg-footer",
"link-secondary",
"main-content",
"main-nav-toggler",
"mb-3",
"mb-4",
"mb-5",
"mb-lg-5",
"me-auto",
Expand All @@ -172,6 +149,7 @@
"navbar-mode-selector",
"navbar-nav",
"navbar-toggler",
"next",
"no-js",
"offcanvas",
"offcanvas-body",
Expand All @@ -186,11 +164,13 @@
"p-2",
"p-3",
"p-4",
"p-auto",
"pb-4",
"pb-5",
"pb-md-0",
"position-fixed",
"position-relative",
"previous",
"ps-1",
"pt-5",
"pt-md-3",
Expand All @@ -205,7 +185,6 @@
"row-cols-md-2",
"row-cols-md-3",
"row-cols-sm-2",
"row-cols-sm-3",
"search",
"search-input",
"search-suggestions",
Expand All @@ -219,7 +198,6 @@
"text-decoration-none",
"text-end",
"text-muted",
"text-secondary",
"text-sm-start",
"text-start",
"text-uppercase",
Expand All @@ -233,7 +211,6 @@
"top-bar"
],
"ids": [
"blogs",
"btn-webshare",
"navbar-0-collapse",
"navbar-mode",
Expand Down
6 changes: 4 additions & 2 deletions layouts/_default/_markup/render-link.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{{ if gt (findRE `^HAHAHUGO` .Destination 1) 0 }}
{{ errorf "Invalid markdown link destination, use '%s' syntax when using shortcodes as input. See '%s'"
("{{% %}}" | htmlUnescape)
.Page.File.Filename
.Page.File.Path
}}
{{ else if not .Destination }}
{{ errorf "Missing markdown link destination, see '%s'" .Page.File.Path }}
{{ else }}
{{ partial "assets/link.html" (dict
"destination" .Destination
"page" .Page
"text" .Text
"title" .Title
) }}
{{ end }}
{{- end }}
46 changes: 26 additions & 20 deletions layouts/partials/assets/link.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{{- $cue := .cue | default site.Params.main.externalLinks.cue -}}
{{- $tab := .tab | default site.Params.main.externalLinks.tab -}}
{{- $isExternal := or (ne (urls.Parse (absURL $destination)).Host (urls.Parse site.BaseURL).Host) $external -}}
{{- $isLocal := hasPrefix $destination "#" -}}
{{- $page := .page -}}
{{- $anchor := "" -}}
{{- $text := .text -}}
Expand Down Expand Up @@ -54,32 +55,37 @@
{{ end }}
{{ end }}

{{ $ref := partial "utilities/GetPage.html" (dict "url" $destination "page" $page) }}
{{- if not $ref -}}
{{- errorf "partial [assets/link.html] - Cannot find page: %s" $destination -}}
{{- $error = true -}}
{{- else -}}
{{- $destination = $ref.RelPermalink -}}
{{- with $anchor }}{{ $destination = printf "%s#%s" (strings.TrimSuffix "/" $destination) . -}}{{ end -}}
{{ if not $isLocal }}
{{ $ref := partial "utilities/GetPage.html" (dict "url" $destination "page" $page) }}
{{- if not $ref -}}
{{- errorf "partial [assets/link.html] - Cannot find page: %s" $destination -}}
{{- $error = true -}}
{{- else -}}
{{- $destination = $ref.RelPermalink -}}
{{- with $anchor }}{{ $destination = printf "%s#%s" (strings.TrimSuffix "/" $destination) . -}}{{ end -}}
{{- end -}}

{{- if not $text -}}
{{- if $anchor -}}
{{- $text = $anchor -}}
{{- else -}}
{{- $text = $ref.LinkTitle -}}
{{- end -}}
{{ if $anchor }}{{ $text = $anchor }}{{ else }}{{ $text = $ref.LinkTitle }}{{ end }}
{{ end -}}
{{- if not $case }}{{ $text = lower $text }}{{ end -}}
{{- end -}}
{{ else }}
{{ with $anchor }}
{{ $destination = printf "#%s" . }}
{{ if not $text }}{{ $text = . }}{{ end }}
{{ end }}
{{ end }}

{{- if not $case }}{{ $text = lower $text }}{{ end -}}
{{- end -}}

{{ if not $error -}}
<a
{{- with $destination }} href="{{ . | safeURL }}"{{ end -}}
{{- with $class }}class="{{ . }}" {{ end -}}
{{- with $target }} target="{{ . }}"{{ end -}}
{{- with $rel }} rel="{{ . }}"{{ end -}}
{{- with $title }} title="{{ . }}"{{ end -}}
{{ with $class }} class="{{ . }}" {{ end -}}
{{ with $target }} target="{{ . }}"{{ end -}}
{{ with $rel }} rel="{{ . }}"{{ end -}}
{{ with $title }} title="{{ . }}"{{ end -}}
>
{{- $text -}}
{{- $text | safeHTML -}}
</a>
{{- end }}
{{- end -}}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gethinode/hinode",
"version": "0.26.0",
"version": "0.26.1",
"description": "Hinode is a clean documentation and blog theme for Hugo, an open-source static site generator",
"keywords": [
"hugo",
Expand Down

0 comments on commit 7413155

Please sign in to comment.