From 07d1396986d107f8b366714b5d124f5a35cc9fa4 Mon Sep 17 00:00:00 2001 From: Manjunath Mohan Date: Fri, 10 May 2024 11:50:28 +0530 Subject: [PATCH] Added codeimporter shortcode - updated exampleSite. --- exampleSite/content/docs/shortcodes/index.md | 25 ++++++++++++++++++++ layouts/shortcodes/codeimporter.html | 8 +++++++ 2 files changed, 33 insertions(+) create mode 100644 layouts/shortcodes/codeimporter.html diff --git a/exampleSite/content/docs/shortcodes/index.md b/exampleSite/content/docs/shortcodes/index.md index d15f9554..eac40c36 100644 --- a/exampleSite/content/docs/shortcodes/index.md +++ b/exampleSite/content/docs/shortcodes/index.md @@ -522,6 +522,31 @@ This shortcode allows you to import markdown files from external sources. This i {{< mdimporter url="https://raw.githubusercontent.com/nunocoracao/nunocoracao/master/README.md" >}} +

+ +## Code Importer + +This shortcode is for importing code from external sources easily without copying and pasting. + + +| Parameter | Description | +| --------- | ------------------------------------------------------- | +| `url` | **Required** URL to an externally hosted code file. | +| `type` | Code type used for syntax highlighting. | + + + + + +**Example:** + +```md +{{}} + +``` +{{< codeimporter url="https://raw.githubusercontent.com/nunocoracao/blowfish/main/layouts/shortcodes/mdimporter.html" type="go" >}} + +

## Mermaid diff --git a/layouts/shortcodes/codeimporter.html b/layouts/shortcodes/codeimporter.html new file mode 100644 index 00000000..801697bc --- /dev/null +++ b/layouts/shortcodes/codeimporter.html @@ -0,0 +1,8 @@ +{{ $url := .Get "url" }} +{{ $type := .Get "type" }} +{{ with resources.GetRemote (printf $url) }} +{{ $codeBlock := printf "```%s\n%s\n```" $type .Content }} +{{ $codeBlock | markdownify }} +{{ else }} +{{ errorf "Code Importer Shortcode - Unable to get remote resource" . }} +{{ end }}