revamp code highlighting

This commit is contained in:
panr
2025-02-28 15:14:45 +01:00
parent 6122019375
commit 32e7220cb9
10 changed files with 179 additions and 611 deletions

View File

@ -13,9 +13,9 @@
</footer>
{{ $menu := resources.Get "js/menu.js" | js.Build }}
{{ $prism := resources.Get "js/prism.js" | js.Build }}
{{ $cp := resources.Get "js/copy-to-clipboard.js" | js.Build }}
{{ $bundle := slice $menu $prism | resources.Concat "bundle.js" | resources.Minify }}
{{ $bundle := slice $menu $cp | resources.Concat "bundle.js" | resources.Minify }}
<script type="text/javascript" src="{{ $bundle.RelPermalink }}"></script>

View File

@ -1,15 +1,13 @@
<div class="pagination">
<div class="pagination__buttons">
{{ if .Paginator.HasPrev }}
<a href="{{ .Paginator.Prev.URL }}" class="button prev">
<span class="button__icon"></span>
<a href="{{ .Paginator.Prev.URL }}" class="button inline prev">
<span class="button__text">{{ $.Site.Params.newerPosts | default "Newer posts" }}</span>
</a>
{{ end }}
{{ if .Paginator.HasNext }}
<a href="{{ .Paginator.Next.URL }}" class="button next">
<a href="{{ .Paginator.Next.URL }}" class="button inline next">
<span class="button__text">{{ $.Site.Params.olderPosts | default "Older posts" }}</span>
<span class="button__icon"></span>
</a>
{{ end }}
</div>

View File

@ -1,15 +1,16 @@
{{ $id := delimit (shuffle (seq 1 9)) "" }}
{{ $open := .Get "open" }}
{{ $lang := .Get "language" }}
{{ if .Get "language" }}
<div class="collapsable-code">
<input id="{{ .Get "id" | default $id }}" type="checkbox" {{ if ( eq ( .Get "isCollapsed" ) "true" ) -}} checked {{- end }} />
<label for="{{ .Get "id" | default $id }}">
<span class="collapsable-code__language">{{ .Get "language" }}</span>
{{ if .Get "title" }}<span class="collapsable-code__title">{{ .Get "title" | markdownify }}</span>{{ end }}
<span class="collapsable-code__toggle" data-label-expand="{{ .Get "expand" | default "" }}" data-label-collapse="{{ .Get "collapse" | default "" }}"></span>
</label>
<pre {{ if .Get "language" }}class="language-{{ .Get "language" }}" {{ end }}><code>{{ .Inner | string }}</code></pre>
</div>
{{- if $lang -}}
<details class="collapsable-code" title="Click to interact" {{ if eq $open "true" -}} open {{- end }}>
<summary>
<span class="collapsable-code__language">{{ $lang }}</span>
{{- if .Get "title" }}<span class="collapsable-code__title">{{ .Get "title" | markdownify }}</span>{{ end -}}
</summary>
{{ $trInner := trim .Inner "\n" }}
{{- transform.Highlight $trInner ($lang) -}}
</details>
{{ else }}
{{ errorf "If you want to use the \"collapsable code\" shortcode, you need to pass a mandatory \"language\" param. The issue occured in %q (%q)" .Page.File .Page.Permalink }}
{{ end }}
{{- end -}}