summaryrefslogtreecommitdiff
path: root/themes/blowfish/layouts/shortcodes
diff options
context:
space:
mode:
authorChristoph Cullmann <christoph@cullmann.io>2024-07-15 22:27:55 +0200
committerChristoph Cullmann <christoph@cullmann.io>2024-07-15 22:27:55 +0200
commit3be5285488090ab70254b3080e33e64e6c702d2c (patch)
tree1e54462f560fd759b5be13d5ecfe1fa5c2c832ed /themes/blowfish/layouts/shortcodes
parent69075c6fb15ae660fc3d78eb2a4dfcde1c5fba1c (diff)
sync theme
Diffstat (limited to 'themes/blowfish/layouts/shortcodes')
-rw-r--r--themes/blowfish/layouts/shortcodes/codeimporter.html25
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 }}