Skip to content

Instantly share code, notes, and snippets.

@rys
Created February 6, 2018 00:00
Show Gist options
  • Save rys/4396450a6585d8f5bc4cb2ee6f323d4e to your computer and use it in GitHub Desktop.
Save rys/4396450a6585d8f5bc4cb2ee6f323d4e to your computer and use it in GitHub Desktop.
Hugo template to list all posts where you used the Instagram shortcode
<ul>
{{ $files := readDir "/content/post" }}
{{ range $file := $files }}
{{ if in .Name ".md" }}
{{ $match := printf "/content/post/%s" .Name | readFile | findRE "{{< instagram" }}
{{ if $match }}
<li><a href="/post/{{ strings.TrimSuffix ".md" .Name }}">{{ strings.TrimSuffix ".md" .Name }}</a></li>
{{ end }}
{{ end }}
{{ end }}
</ul>
@rys
Copy link
Author

rys commented Feb 6, 2018

If you use the instagram shortcode and want to list them somehow from another page, drop the above into a file in your shortcodes template directory and call it like:

{{< instalist >}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment