First commit
Some checks failed
Blowfish Docs Deploy / build (push) Has been cancelled
Blowfish Docs Deploy / deploy (push) Has been cancelled
Test Build / Build Example Site (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Update Hugo version / updateBlowfish (push) Has been cancelled
Some checks failed
Blowfish Docs Deploy / build (push) Has been cancelled
Blowfish Docs Deploy / deploy (push) Has been cancelled
Test Build / Build Example Site (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Update Hugo version / updateBlowfish (push) Has been cancelled
Delete exampleSite Add initial content, images & docker-compose.yml Use extend-head.html for analytics Set remote url to gitea.novicelab.io Remove original .git due to "shallow update not allowed" error
This commit is contained in:
27
layouts/shortcodes/codeimporter.html
Normal file
27
layouts/shortcodes/codeimporter.html
Normal file
@@ -0,0 +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) }}
|
||||
{{ $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 "codeimporter 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 }}
|
||||
{{ warnf "codeimporter shortcode: unable to fetch %q: %s" $url .Position }}
|
||||
{{ end }}
|
||||
Reference in New Issue
Block a user