Skip to content

Instantly share code, notes, and snippets.

@myobie
Last active July 10, 2018 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myobie/6924af187ae3f1f42f537b613cfa4844 to your computer and use it in GitHub Desktop.
Save myobie/6924af187ae3f1f42f537b613cfa4844 to your computer and use it in GitHub Desktop.
Embed things into the markdown content of a hugo site
<div class="embed">
{{ $file := .Get "src" }}
{{ if fileExists $file }}
{{ if eq (.Get "markdown") "true" }}
{{ $file | readFile | markdownify }}
{{ else }}
{{ if or (eq (.Get "javascript") "true") (eq (.Get "js") "true") }}
<script>
{{ $file | readFile | safeJS }}
</script>
{{ else }}
{{ $file | readFile | safeHTML }}
{{ end }}
{{ end }}
{{ else }}
<p><em>Cannot find file <code>{{ $file }}</code></em></p>
{{ end }}
</div>
title
Test HTML and JS Embed!

This should have the content of test.html below here:

{{< embed src="/resources/test.html" >}}

And the js should be inserted below here:

{{< embed src="/resources/test.js" js="true" >}}

Hooray üéâ

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