I have a GitHub repo with Markdown docs, currently linked among them using the filename.md format. I’d like to render the docs using Hugo, and I also have the requirement to keep them browsable via GitHub.
How can I write the links so that they work both on GitHub and in Hugo?
The first requirement means that they have to be in the filename.md format (I tried in a test repo to use just filename or filename.html to point to filename.md files, but only got 404s).
If I understand correctly, permalinks or shortcodes in Hugo are not useful, because they’re only used in templates and not in Markdown docs.
There would have to be some way to intercept link generation during the Markdown parsing and rendering, to convert the filename.md links into filename.html ones (given uglyurls = true). Any way to do that?
Or any other way to satisfy both requirements? Thanks.
If those md-files had had “front matter” they you would only need a template (or use the default).
Front matter is metadata in the header about the page used by Hugo to create titles, permalinks etc.
One could envision that Hugo could create some default metadata if not present, or fetch it from GitHub (creation date …?)… But that would need some thinking by some developer.
So in the front matter for each file I could define the path for the rendered output to have the .md extension rather than the .html one, and links would work. Having HTML files with the .md files is slightly ugly, though.
Otherwise I guess I could define a template filter function that replaces all the “.md” strings into “.html” in the rendered output.
I’ll test both approaches later (Europe bedtime approaching ) and see what happens. Thank you for the help!
I’ll suggest you test it out and see for yourself. The HTML is just for layout/formatting of the packaging – the content and the formatting of the content will always be the md files.
The path for each document can be set. but the output file extension will always be HTML. There’s talk about making it configurable at https://github.com/spf13/hugo/issues/320.
The code to support 320 is already committed. Just need to add a configuration option for it.
Hugo is complied. The only way to add custom template functions is exactly how we do it in the file you referenced. If you need one, it needs to be in that file, you can’t dynamically add one at runtime because hugo isn’t developed in a dynamic language.
That said, we are happy to have users contributed more custom template functions. Over half of those functions were contributed by the community.
Hi there. Did anybody solved this problem? being able to use ‘.md’ relative links that work on github and gitlab, and also get converted in hugo to ‘.html’ links?