Is there a way to embed raw github url in hugo?

Here’s an example of retrieving some source code. The lexer for syntax highlighting is determined by the file extension.

{{ $u := "https://raw.githubusercontent.com/gohugoio/hugo/master/commands/env.go" }}
{{ with resources.GetRemote $u }}
  {{ with .Err }}
    {{ errorf "%s" . }}
  {{ else }}
    {{ $lang := path.Ext $u | strings.TrimPrefix "." }}
    {{ highlight .Content $lang }}
  {{ end }}
{{ else }}
  {{ errorf "Unable to get remote resource." }}
{{ end }}

If you are retrieving markdown and wish to render rather than highlight:

{{ $u := "https://raw.githubusercontent.com/gohugoio/hugo/master/README.md" }}
{{ with resources.GetRemote $u }}
  {{ with .Err }}
    {{ errorf "%s" . }}
  {{ else }}
    {{ .Content | $.Page.RenderString }}
  {{ end }}
{{ else }}
  {{ errorf "Unable to get remote resource." }}
{{ end }}
1 Like