What is the easiest way to add a code file to huge?
something like below
the file I am calling from is in content/article/article-1.md
{{ < code_file ../codes/main.py > }}
this gets auto-translated to
What is the easiest way to add a code file to huge?
something like below
the file I am calling from is in content/article/article-1.md
{{ < code_file ../codes/main.py > }}
this gets auto-translated to
structure
content/article/
└── article-1/
├── index.md
└── main.py
layouts/shortcodes/get-content.html
{{ (.Page.Resources.GetMatch (.Get 0)).Content }}
content/article/article-1/index.md
{{< get-content main.py >}}
This didn’t worked like I said, I want it to show as code with python
highlighting, but it just showed text only Also your code don’t work if the file name is not
index.md
Start building sites …
hugo v0.87.0+extended darwin/amd64 BuildDate=unknown
Error: Error building site: "$ROOT/content/article/article-1.md:35:1":
failed to render shortcode "get-content":
failed to process shortcode: "$ROOT/layouts/shortcodes/get-content.html:1:35":
execute of template failed: template: shortcodes/get-content.html:1:35:
executing "shortcodes/get-content.html" at <0>:
nil pointer evaluating resource.Resource.Content
Built in 4847 ms
That is not what you originally asked for.
Then incorporate the highlight
function within the shortcode:
layouts/shortcodes/highlight-content.html
{{ highlight (.Page.Resources.GetMatch (.Get 0)).Content (.Get 1) "linenos=table" }}
And call it like this:
{{< highlight-content main.py python >}}
Page Resources must exist within Page Bundles, either leaf bundles or branch bundles. A leaf bundle is a directory with an index.md
file and associated resources.
Thanks a lot.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.