# Trying to fetch markdown from a remote repository using resources.GetRemote

**URL:** <https://discourse.gohugo.io/t/trying-to-fetch-markdown-from-a-remote-repository-using-resources-getremote/49156>\
**Category:** support\
**Created:** [April 3, 2024, 5:09pm UTC](https://discourse.gohugo.io/t/trying-to-fetch-markdown-from-a-remote-repository-using-resources-getremote/49156 "2024-04-03T17:09:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimmyhurr](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@jimmyhurr](https://discourse.gohugo.io/u/jimmyhurr)\
**Post date:** [April 3, 2024, 5:09pm UTC](https://discourse.gohugo.io/t/trying-to-fetch-markdown-from-a-remote-repository-using-resources-getremote/49156/1 "2024-04-03T17:09:07Z")

</div>

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](https://www.docsy.dev/)).

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](https://discourse.gohugo.io/t/is-there-a-way-to-embed-raw-github-url-in-hugo/39957/7)

My shortcode is as follows and can be found [here](https://gitlab.com/castdoc/doc-test/-/blob/JHU@release_notes_testing/layouts/shortcodes/fetch-remote.html?ref_type=heads):

```auto
{{ $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](https://gitlab.com/castdoc/doc-test/-/blob/JHU@release_notes_testing/content/en/docs/release-notes/fetch-remote/index.md?ref_type=heads&plain=1):

```auto
---
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](https://jhu-release-notes-testing.doc-test.pages.dev/docs/release-notes/fetch-remote/) 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](https://gohugo.io/methods/page/rendershortcodes/)) 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](https://jhu-release-notes-testing.doc-test.pages.dev/docs/release-notes/fetch-include/).

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.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [April 3, 2024, 5:16pm UTC](https://discourse.gohugo.io/t/trying-to-fetch-markdown-from-a-remote-repository-using-resources-getremote/49156/2 "2024-04-03T17:16:53Z")

</div>

```auto
{{ $url := $.Page.Params.rnurl }}
{{ with resources.GetRemote $url }}
  {{ with .Err }}
    {{ errorf "%s" . }}
  {{ else }}
{{ .Content }}
  {{ end }}
{{ else }}
  {{ errorf "Unable to get remote resource." }}
{{ end }}

```

And call it with using the `{{% %}}` notation.

Note that the `{{ .Content }}` line must not be indented.

---

<div class="post-metadata">

**Author:** ![jimmyhurr](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@jimmyhurr](https://discourse.gohugo.io/u/jimmyhurr)\
**Post date:** [April 3, 2024, 5:25pm UTC](https://discourse.gohugo.io/t/trying-to-fetch-markdown-from-a-remote-repository-using-resources-getremote/49156/3 "2024-04-03T17:25:26Z")

</div>

Genius! Thank you so much, that is EXACTLY what I was trying to achieve… If I could send you a beer or something to say thank you, I would!

Do you have a moment to explain what I was doing wrong - I presume that the `$.Page.RenderString` was doing something that it shouldn’t?

And the indentation? I hadn’t realised that was important, so thanks for that.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [April 3, 2024, 5:31pm UTC](https://discourse.gohugo.io/t/trying-to-fetch-markdown-from-a-remote-repository-using-resources-getremote/49156/4 "2024-04-03T17:31:20Z")

</div>

Regarding the call notation…

[https://gohugo.io/troubleshooting/faq/#why-are-there-two-ways-to-call-a-shortcode](https://gohugo.io/troubleshooting/faq/#why-are-there-two-ways-to-call-a-shortcode)

And now that you inserting raw markdown, anything indented by four or more spaces (or a tab) is rendered as an indented code block.

---

<div class="post-metadata">

**Author:** ![jimmyhurr](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@jimmyhurr](https://discourse.gohugo.io/u/jimmyhurr)\
**Post date:** [April 3, 2024, 6:15pm UTC](https://discourse.gohugo.io/t/trying-to-fetch-markdown-from-a-remote-repository-using-resources-getremote/49156/5 "2024-04-03T18:15:25Z")

</div>

Thank you.

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [April 5, 2024, 6:16pm UTC](https://discourse.gohugo.io/t/trying-to-fetch-markdown-from-a-remote-repository-using-resources-getremote/49156/6 "2024-04-05T18:16:01Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
