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

Avoid data races with codeIndex on feeds

This commit is contained in:
Rohan Kumar 2023-11-29 00:36:14 -08:00
parent a097b46950
commit 7de728fdfe
No known key found for this signature in database
GPG key ID: 1E892DB2A5F84479
4 changed files with 36 additions and 1 deletions

View file

@ -58,7 +58,6 @@
{{ range $pages -}}
{{- if not .Params.Private -}}
<entry>
{{- .Page.Scratch.Set "codeIndex" 1 -}}
<title>{{ .Title }}</title>
<link rel="alternate" type="text/html" href="{{ .Permalink }}" />
<id>{{ .Permalink }}</id>

View file

@ -1,6 +1,8 @@
{{- define "main" -}}
{{- $canonicalRelPermalink := .RelPermalink | replaceRE "^/~seirdy/" "/" }}
{{- .Scratch.Set "codeIndex" 1 -}}
{{- .Scratch.Set "codeIndexAtom" 1 -}}
{{- .Scratch.Set "codeIndexRss" 1 -}}
<main
itemprop="mainEntity" itemscope="" itemtype="https://schema.org/BlogPosting{{ with .Params.articleType }} https://schema.org/{{ . }}{{ end }}" itemid="{{ .Site.Params.CanonicalBaseURL }}{{ $canonicalRelPermalink }}">
<link itemprop="isPartOf" href="{{ .Site.Params.CanonicalBaseURL }}/" />

View file

@ -0,0 +1,17 @@
{{- $codeIndex := (.Page.Scratch.Get "codeIndexAtom") -}}
{{- $id := (printf `code-%d` $codeIndex) -}}
{{- with .Get "id" -}}
{{- $id = . -}}
{{- end -}}
{{ with .Parent }}
{{- with .Get "id" -}}
{{- $id = . -}}
{{- end -}}
{{- end -}}
<figcaption id="{{ $id }}-caption">
<span id="{{ $id }}" tabindex="-1">
<strong itemprop="name"> <span itemprop="codeSampleType">Code snippet</span> {{ $codeIndex }}</strong>{{with .Get "lang"}} (<span itemprop="programmingLanguage">{{ . }}</span>){{ end -}}
</span>:
{{ .Inner | .Page.RenderString | safeHTML }}
</figcaption>
{{- .Page.Scratch.Set "codeIndexAtom" (add 1 $codeIndex) -}}

View file

@ -0,0 +1,17 @@
{{- $codeIndex := (.Page.Scratch.Get "codeIndexRss") -}}
{{- $id := (printf `code-%d` $codeIndex) -}}
{{- with .Get "id" -}}
{{- $id = . -}}
{{- end -}}
{{ with .Parent }}
{{- with .Get "id" -}}
{{- $id = . -}}
{{- end -}}
{{- end -}}
<figcaption id="{{ $id }}-caption">
<span id="{{ $id }}" tabindex="-1">
<strong itemprop="name"> <span itemprop="codeSampleType">Code snippet</span> {{ $codeIndex }}</strong>{{with .Get "lang"}} (<span itemprop="programmingLanguage">{{ . }}</span>){{ end -}}
</span>:
{{ .Inner | .Page.RenderString | safeHTML }}
</figcaption>
{{- .Page.Scratch.Set "codeIndexRss" (add 1 $codeIndex) -}}