mirror of
https://git.sr.ht/~seirdy/seirdy.one
synced 2024-11-30 15:22:09 +00:00
Compare commits
3 commits
b66871a573
...
58b61eef2a
Author | SHA1 | Date | |
---|---|---|---|
|
58b61eef2a | ||
|
6fc55df736 | ||
|
6391da4aa7 |
3 changed files with 34 additions and 1 deletions
18
content/notes/polygot-xhtml5.md
Normal file
18
content/notes/polygot-xhtml5.md
Normal 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.
|
|
@ -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: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:url" content="{{ .Site.Params.CanonicalBaseURL }}{{ $canonicalRelPermalink }}" />
|
||||||
<meta property="og:description" content="{{ $description }}" />
|
<meta property="og:description" content="{{ $description }}" />
|
||||||
|
{{ hugo.Generator | replaceRE ">" " />" | safeHTML}}
|
||||||
</head>
|
</head>
|
||||||
|
|
|
@ -17,7 +17,21 @@
|
||||||
{{- $oldTarget := $target | replaceRE "/posts" "" | replaceRE "/$" ".html" -}}
|
{{- $oldTarget := $target | replaceRE "/posts" "" | replaceRE "/$" ".html" -}}
|
||||||
{{ $targets = (slice $target $oldTarget) }}
|
{{ $targets = (slice $target $oldTarget) }}
|
||||||
{{- end -}}
|
{{- 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 */ -}}
|
{{- /* Render webmentions if they exist */ -}}
|
||||||
{{- $count := (len $webmentions) -}}
|
{{- $count := (len $webmentions) -}}
|
||||||
{{- if gt $count 0 -}}
|
{{- if gt $count 0 -}}
|
||||||
|
|
Loading…
Reference in a new issue