I would like to load content of a markdown file that is available on the internet.
I found out here I have to write my own shortcode. I tried it the way they mentioned. But when I use it with a URL it always says
execute of template failed: template: shortcodes/content.html:2:11: executing "shortcodes/content.html" at <readFile>: error calling readFile: file "<myUrl>" does not exist.
But I am sure it is free to access on the internet.
To receive assistance you’ll need to share your shortcode. I don’t know of a method used to get the contents of a remote markdown file and render it via shortcode at build time. There’s normally a step involving getting the remote file and moving it to the local filesystem, where functions like readFile work.
See Local file templates | Hugo for more details. The “remote” calls work for JSON and CSV, where Hugo will retrieve and cache the files for processing, described at Data templates | Hugo.
sorry, I guess I wasn’t clear enough, I did not add the URL there as I thought this was overfilling the error message, it does show my actual URL at that placeholder
failed to render shortcode "content": failed to process shortcode: "...../layouts/shortcodes/content.html:2:11": execute of template failed: template: shortcodes/content.html:2:11: executing "shortcodes/content.html" at <readFile>: error calling readFile: file "https:/raw.githubusercontent.com/europace/kex-vorgang-export-api/master/README.md" does not exist
I did assume that readFile does not take a URL with it, but I could not find another way to make this work and I assumed that somehow this must be possible…
@maiki do you have a suggestion for the shortcode that would allow this? If I do getJSON I am not sure what will happen, as this file is not json but markdown…
Building sites … ERROR 2020/08/05 08:31:18 Failed to get JSON resource "https://raw.githubusercontent.com/europace/kex-vorgang-export-api/master/README.md": invalid character '#' looking for beginning of value
I am not happy with how it looks, but I am happy that I found something. I will keep this open for a few days as maybe somene has a better solution. Then I will close it
As you’re discovered, we don’t have a generic “get file via HTTP” template function. readFile is for the local OS. Our only “remote get” functions as of today are getJSON and getCSV.