aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2024-09-10 00:00:00 +0000
committertdro <tdro@noreply.example.com>2024-09-10 00:00:00 +0000
commit06bd42fb1ebf2f788232b79f6998b334f41c5284 (patch)
tree08815176e2c9a3546b569993dcf5ee9e93480de7
parent204ac1bfe954433ca1be87be23f2e27e544f6ebd (diff)
downloadcanory-06bd42fb1ebf2f788232b79f6998b334f41c5284.tar.gz
canory-06bd42fb1ebf2f788232b79f6998b334f41c5284.tar.bz2
canory-06bd42fb1ebf2f788232b79f6998b334f41c5284.zip
themes/default/layouts/_default/_markup/render-link: Guess broken link filter
-rw-r--r--assets/css/default.css8
-rw-r--r--themes/default/layouts/_default/_markup/render-link.html44
2 files changed, 29 insertions, 23 deletions
diff --git a/assets/css/default.css b/assets/css/default.css
index dbe6e9a..db6ff78 100644
--- a/assets/css/default.css
+++ b/assets/css/default.css
@@ -650,7 +650,13 @@ meta-handle a:hover span {
text-decoration-color: inherit !important;
}
-a[data-internal] {
+p a[data-type="broken"]:not(a[href$=".md"]):not(a[href$=".pdf"]):not(a[href$=".yaml"]) {
+ color: #8f0000;
+ color: var(--danger);
+}
+
+a[data-type="internal"],
+p a[data-type="broken"] {
text-decoration-color: #aaa;
text-decoration-thickness: 0.15rem;
}
diff --git a/themes/default/layouts/_default/_markup/render-link.html b/themes/default/layouts/_default/_markup/render-link.html
index 44cd8a3..874ea15 100644
--- a/themes/default/layouts/_default/_markup/render-link.html
+++ b/themes/default/layouts/_default/_markup/render-link.html
@@ -1,30 +1,30 @@
-{{- $link := .Destination -}}
-{{- $target := urls.Parse $link -}}
-{{- $self := urls.Parse .Page.Site.BaseURL -}}
-{{- $prurl := eq (findRE `^/\w` $link | len) 0 -}}
-{{- $local := or (eq $target.Host $self.Host) (and (strings.HasPrefix $link "/") (not $prurl)) -}}
-{{- $remote := not $local -}}
+{{- $rel := "" -}}
+{{- $type := "" -}}
+{{- $fragment := "" -}}
+{{- $link := .Destination -}}
+{{- $target := urls.Parse $link -}}
+{{- $self := urls.Parse .Page.Site.BaseURL -}}
+{{- $prurl := eq (findRE `^/\w` $link | len) 0 -}}
+{{- $local := or (eq $target.Host $self.Host) (and (strings.HasPrefix $link "/") (not $prurl)) -}}
+{{- $remote := not $local -}}
-{{- if and $local $target.Path -}}
- {{- $fragment := "" -}}
-
- {{- with $target.Fragment -}}
- {{- $fragment = printf "#%s" . -}}
- {{- end -}}
+{{- if $remote -}}
+ {{- $rel ="noopener no-referrer" -}}
+{{- else -}}
+ {{- $type ="internal" -}}
+{{- end -}}
- {{- with .Page.GetPage $target.Path -}}
+{{- if and $local $target.Path -}}
+ {{- with .Page.GetPage (strings.TrimRight "/" $target.Path) -}}
+ {{- with $target.Fragment -}} {{- $fragment = printf "#%s" . -}} {{- end -}}
{{- $link = printf "%s%s" .Permalink $fragment -}}
- {{- end -}}
+ {{- else -}} {{- $type ="broken" -}} {{- end -}}
{{- end -}}
<a
- {{- if $remote }}
- rel="noopener no-referrer"
- {{- else }}
- data-internal=""
- {{- end }}
+ rel="{{ $rel }}"
+ data-type="{{ $type }}"
href="{{ $link | safeURL }}"
- {{ with or .Title ($link | safeURL) -}}
- title="{{ . }}"
- {{ end }}>{{ .Text | safeHTML }}</a>
+ title="{{ or .Title ($link | safeURL) }}"
+>{{ .Text | safeHTML }}</a>
{{- /* This comment removes trailing newlines and white spaces. */ -}}