mirror of
https://git.sr.ht/~seirdy/seirdy.one
synced 2024-11-23 12:52:10 +00:00
Avoid data races with codeIndex on feeds
This commit is contained in:
parent
a097b46950
commit
7de728fdfe
4 changed files with 36 additions and 1 deletions
|
@ -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>
|
||||
|
|
|
@ -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 }}/" />
|
||||
|
|
17
layouts/shortcodes/codecaption.atom
Normal file
17
layouts/shortcodes/codecaption.atom
Normal 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) -}}
|
17
layouts/shortcodes/codecaption.rss
Normal file
17
layouts/shortcodes/codecaption.rss
Normal 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) -}}
|
Loading…
Reference in a new issue