diff options
author | Christoph Cullmann <christoph@cullmann.io> | 2024-07-15 22:27:55 +0200 |
---|---|---|
committer | Christoph Cullmann <christoph@cullmann.io> | 2024-07-15 22:27:55 +0200 |
commit | 3be5285488090ab70254b3080e33e64e6c702d2c (patch) | |
tree | 1e54462f560fd759b5be13d5ecfe1fa5c2c832ed /themes/blowfish/layouts/shortcodes | |
parent | 69075c6fb15ae660fc3d78eb2a4dfcde1c5fba1c (diff) |
sync theme
Diffstat (limited to 'themes/blowfish/layouts/shortcodes')
-rw-r--r-- | themes/blowfish/layouts/shortcodes/codeimporter.html | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/themes/blowfish/layouts/shortcodes/codeimporter.html b/themes/blowfish/layouts/shortcodes/codeimporter.html index 493f444..952c28a 100644 --- a/themes/blowfish/layouts/shortcodes/codeimporter.html +++ b/themes/blowfish/layouts/shortcodes/codeimporter.html @@ -1,8 +1,27 @@ {{ $url := .Get "url" }} {{ $type := .Get "type" }} +{{ $startLine := .Get "startLine" | default 1 | int }} +{{ $startLine = sub $startLine 1 }} +{{ $endLine := .Get "endLine" | default -1 | int }} +{{ $selectedLines := slice }} {{ with resources.GetRemote (urls.Parse $url) }} -{{ $codeBlock := printf "```%s\n%s\n```" $type .Content }} -{{ $codeBlock | markdownify }} + {{ $lines := split .Content "\n" }} + {{ $totalLine := $lines | len }} + + {{ if ne $endLine -1 }} + {{ $endLine = math.Min $endLine $totalLine }} + {{ else }} + {{ $endLine = $totalLine }} + {{ end }} + + {{ if gt $startLine $endLine }} + {{ errorf "Code Importer Shortcode - startLine is greater than endLine" . }} + {{ end }} + + {{ $selectedLines := first $endLine $lines }} + {{ $selectedLines = after $startLine $selectedLines }} + {{ $codeBlock := printf "```%s\n%s\n```" $type (delimit $selectedLines "\n") }} + {{ $codeBlock | markdownify }} {{ else }} -{{ errorf "Code Importer Shortcode - Unable to get remote resource" . }} + {{ errorf "Code Importer Shortcode - Unable to get remote resource" . }} {{ end }} |