How to embed a Gist statically in Vue

Nick Wu
2 min readJul 7, 2018

--

The easy way to include a Gist is to use the embed URL for the Gist provided by GitHub, for instance:

<script src="https://gist.github.com/nickwu241/8f0c4c95aa68fe969dcebddd456b6752.js"></script>

But including this in a Vue component template results in:

Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as they will not be parsed.

Oh no! To fix this, we will include the Gist statically by grabbing the HTML/CSS produced by the Javascript code and make it a Vue component.

Steps to embed a Gist in Vue

Run this command to generate the Gist component Gist.vue, replacing <USERNAME> and <GIST_ID>:

python <(curl https://raw.githubusercontent.com/nickwu241/vue-static-gist-example/master/to_gist_comp.py) <USERNAME>/<GIST_ID> 

For the curious, this command executes the Python script below.

Now just register the component like any other Vue component:

Here’s what alive example looks like:

--

--

Nick Wu
Nick Wu

Written by Nick Wu

Software Engineer @Affirm. Previously @Shopify, @Hootsuite.

No responses yet