Search code examples
githubgistghost

Github Gist Ghost Injection, Single Snipplet


I have my blog made by 'Ghost', and I'm trying to inject Github Gist in my post using the javascript github provides.

However, I usually keep a lot code snipplets in a single gist.

https://gist.github.com/devlphj/6631dc284065a5e61752d3970d74303b

Like the link above, this gist contains 2 code snipplets.

However, I want to post only 1 of the 2 snipplets.

By the Github guide, normally you inject your gist like

<script src="https://gist.github.com/devlphj/6631dc284065a5e61752d3970d74303b.js"></script>

However, by this method, both the 2 snipplets show on my blog.

I tried like,

However, this doesn't showed snipplets at all.

Anyone knows a solution for this?


Solution

  • How about this? You can use a query parameter of file= for the URL.

    When you want to embed 2.cpp from the gist, you can use a following code.

    <script src="https://gist.github.com/devlphj/6631dc284065a5e61752d3970d74303b.js?file=2.cpp"></script>
    

    When you want to embed temp.cpp from the gist, you can use a following code.

    <script src="https://gist.github.com/devlphj/6631dc284065a5e61752d3970d74303b.js?file=temp.cpp"></script>
    

    If I misunderstand your question, I'm sorry.