javascriptsyntax-highlightingbloggergistblogger-dynamic-views

Gist in blogger dynamic views


I want to embed my gists (gist.github) in my blogger blog. But as explained in this question dynamic views directly don't support javascript.

From the moski's(as mentioned in the answer) blog its possible to embed a gist.

What if I want to only embed only one file of my gist?

For example:

<script src="https://gist.github.com/3975635.js?file=regcomp.c"></script>

Solution

  • Looking at moski's blog, his description and gist snippets (gistLoader.js and gistBlogger.js), I can suppose that to reach your goal you have to edit that code a little bit.

    Currently, when you add

    <script src="https://raw.github.com/moski/gist-Blogger/master/public/gistLoader.js" type="text/javascript"></script>
    

    at the bottom of your posts, what this script does is looking for this other code you added into your blog

    <div class="gistLoad" data-id="GistID" id="gist-GistID">Loading ....</div>
    

    retrieves the data-id attribute, and injects the required code to load the script with src set to

    'https://gist.github.com/' + id + '.js'
    

    Now, if I correctly figured out what the code does, editing the second moski's HTML code in this way:

    <div class="gistLoad" data-id="GistID" data-file="GistFile" id="gist-GistID">Loading ....</div>
    

    and the function in moski's gistBlogger.js in order to retrieve (when defined) the new data-file attribute, you can generate a new src to inject, like that:

    'https://gist.github.com/' + id + '.js?file=' + file
    

    It should works.