1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-11-23 21:02:09 +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 -}} {{ range $pages -}}
{{- if not .Params.Private -}} {{- if not .Params.Private -}}
<entry> <entry>
{{- .Page.Scratch.Set "codeIndex" 1 -}}
<title>{{ .Title }}</title> <title>{{ .Title }}</title>
<link rel="alternate" type="text/html" href="{{ .Permalink }}" /> <link rel="alternate" type="text/html" href="{{ .Permalink }}" />
<id>{{ .Permalink }}</id> <id>{{ .Permalink }}</id>

View file

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