I am trying to fetch markdown from a remote repository during the Hugo build and have that markdown render in a page. I have managed to do this with a shortcode that uses the resources.GetRemote
function, however my right hand side bar TOC does not include the headings from the markdown that is pulled in at build time, which is a problem. I don’t know if I am doing something wrong in the shortcode, or whether it is an issue in the theme I’m using (Docsy).
Hugo 0.119.0
Docsy 0.8.0
I was inspired by this post: Is there a way to embed raw github url in hugo? - #7 by jmooring
My shortcode is as follows and can be found here:
{{ $url := $.Page.Params.rnurl }
{{ with resources.GetRemote $url }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
{{ .Content | $.Page.RenderString }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource." }}
{{ end }}
The markdown page where I want to pull in the remote markdown contains this and can be found here:
---
title: "fetch-remote"
linkTitle: "fetch-remote"
no_list: true
rnurl: "https://raw.githubusercontent.com/mstura/doc_test/master/markdown/com.castsoftware.dotnet/1.5.md"
---
{{< fetch-remote >}}
The result can be seen here where the right side bar does not contain the headings from the imported markdown.
Maybe what I am trying to achieve is just not possible? Does anyone have any clues?
thank you for any pearls of wisdom… or just to tell me I can’t do what I’m trying to do…!
Note 1:
I have achieved what I want using RenderShortcodes
(RenderShortcodes | Hugo) but this requires that I import the markdown files from the remote repo into the repo I’m building from using module.imports
- BUT i’m trying to avoid doing this because it will inflate the number of files that are output at the end of the build (I’m using Cloudflare and there is a hard limit on the number of files that you can host per “site” (20000)). You can see this result here.
Note 2:
I’ve experimented also with getJSON
by pulling the markdown in JSON format with the github API, but I have similar issues and also getJSON
is now deprecated.