1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-11-27 14:12:09 +00:00

Compare commits

...

3 commits

Author SHA1 Message Date
Rohan Kumar
58b61eef2a
New note: polygot xhtml5 2023-07-22 20:41:11 -07:00
Rohan Kumar
6fc55df736
Render webmentions whose targets have fragments
If a target URL has a fragment, it should match against the page URL
even without the fragment.
2023-07-22 17:26:11 -07:00
Rohan Kumar
6391da4aa7
Add the Hugo generator meta-tag again
Finally found a legitimate use-case:
https://www.marginalia.nu/release-notes/v2023-06-0/#generator-keywords
2023-07-22 15:14:53 -07:00
3 changed files with 34 additions and 1 deletions

View file

@ -0,0 +1,18 @@
---
title: "Polygot XHTML5"
date: 2023-07-22T20:39:24-07:00
syndicatedCopies:
- title: 'The Fediverse'
url: 'https://pleroma.envs.net/notice/AXyQMNhrMjeGLBrmim'
---
Why is my site's markup polygot XHTML5? I have had to deal with some really awful user-agents:
- Bespoke markup parsers in RSS readers.
- Link previews in obscure messaging apps.
- A reader-mode bookmarklet-turned-browser-extension that hasn't been updated in twelve years.
- Various search engines trying to parse the page without using a compliant parser.
Most of my issues were solved by running my generated markup through both `xmllint` (XML syntax) and the Nu HTML Checker (HTML5). Optional elements tend to cause issues the most.
Overly-aggressive validation tends to spot latent bugs. Even if something is valid without an optional closing tag, I may have meant to include one in my templates. If that becomes an issue when I change something else later, it'll be hard to track down the bug when it passes more lax validation.

View file

@ -82,4 +82,5 @@
<meta property="og:image:height" content="{{ $og_image.Height }}" /><meta property="og:image:width" content="{{ $og_image.Width }}" />
<meta property="og:url" content="{{ .Site.Params.CanonicalBaseURL }}{{ $canonicalRelPermalink }}" />
<meta property="og:description" content="{{ $description }}" />
{{ hugo.Generator | replaceRE ">" " />" | safeHTML}}
</head>

View file

@ -17,7 +17,21 @@
{{- $oldTarget := $target | replaceRE "/posts" "" | replaceRE "/$" ".html" -}}
{{ $targets = (slice $target $oldTarget) }}
{{- end -}}
{{- $webmentions := where $allMentions "target" "in" $targets -}}
{{- /* We can't just use a simple "where" function because we need to ignore URL anchors when making a comparison: https://discourse.gohugo.io/t/add-like-comparison-operator-to-the-where-function/42013/4 */ -}}
{{- $webmentions := slice -}}
{{- range $allMentions -}}
{{- if in $targets .target -}}
{{ $webmentions = $webmentions | append . }}
{{- else -}}
{{- $fragment := printf `#%s` (urls.Parse .target).Fragment -}}
{{- if gt (len $fragment) 1 -}}
{{- $trimmedTarget := strings.TrimSuffix $fragment .target -}}
{{- if in $targets $trimmedTarget -}}
{{ $webmentions = $webmentions | append . }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- /* Render webmentions if they exist */ -}}
{{- $count := (len $webmentions) -}}
{{- if gt $count 0 -}}