Extract code groups into a partial and display them for entire files and raw files.

This commit is contained in:
2021-01-17 18:23:43 -08:00
parent d1ea7b5364
commit 5d0920cb6d
7 changed files with 31 additions and 18 deletions

View File

@@ -0,0 +1,12 @@
{{ $scratch := .scratch }}
{{ $scratch.Set "bestLength" -1 }}
{{ $scratch.Set "bestUrl" (printf "https://dev.danilafe.com/Web-Projects/blog-static/src/branch/master/code/%s" .path) }}
{{ $filePath := .path }}
{{ range $module, $props := .submoduleLinks }}
{{ $path := index $props "path" }}
{{ $bestLength := $scratch.Get "bestLength" }}
{{ if and (le $bestLength (len $path)) (hasPrefix $filePath $path) }}
{{ $scratch.Set "bestLength" (len $path) }}
{{ $scratch.Set "bestUrl" (printf "%s%s" (index $props "url") (strings.TrimPrefix $path $filePath)) }}
{{ end }}
{{ end }}

View File

@@ -0,0 +1,3 @@
<div class="highlight-group">
<div class="highlight-label">From <a href="{{ .url }}">{{ path.Base .path }}</a>{{ .comment }}</div>{{ .content }}
</div>

View File

@@ -0,0 +1 @@
{{ partial "group.html" (dict "url" .url "path" .path "comment" .comment "content" (highlight .code .language .opts)) }}