{"url":"https://api.github.com/gists/cd6d137f872b5f9c9423","forks_url":"https://api.github.com/gists/cd6d137f872b5f9c9423/forks","commits_url":"https://api.github.com/gists/cd6d137f872b5f9c9423/commits","id":"cd6d137f872b5f9c9423","git_pull_url":"https://gist.github.com/cd6d137f872b5f9c9423.git","git_push_url":"https://gist.github.com/cd6d137f872b5f9c9423.git","html_url":"https://gist.github.com/cd6d137f872b5f9c9423","files":{"Turn-Your-Gist-To-Html.md":{"filename":"Turn-Your-Gist-To-Html.md","type":"text/plain","language":"Markdown","raw_url":"https://gist.githubusercontent.com/kosamari/cd6d137f872b5f9c9423/raw/b463d9429ede3b04fe984394b9dc90349b819682/Turn-Your-Gist-To-Html.md","size":3855,"truncated":false,"content":"# Turn Your Gist To HTML\n\n**TL;DR; I needed a blog & solved it in wee bit tedious but simple way**\n\nLately, I've been doing a lot of side projects & talks. While I tweet most of my progress and research, when I finish a project, people ask if I documented the process somewhere.\n\nI'm most comfortable writing long form docs in markdown format and I already have many notes on my gist as markdown file. So I made a script to pull .md file from gist and convert to HTML.\n\n## Using gist API is very simple\nIf you already have gist id (https://gist.github.com/[username]/[ID]), getting data via API is very simple. Just make GET request to `https://api.github.com/gists/[id]` and you'll get JSON back - check [this out](https://api.github.com/gists/cd6d137f872b5f9c9423).\n_No API key, No authentication necessary._ (This applies to secret gist as well) \n*When you are calling API from command line, you must set user-agent in the headder.\n\n## Markdown to HTML parser\nI've tried few markdown to HTML parser and settled on [markdown-it](https://github.com/markdown-it/markdown-it). \"markdown-it\" parse code block in github favored markdown to hilight.js compatible HTML. This was major win for my documentation purpose which will have many code samples.\n\nThis code block turn into...\n```markdown\n ```javascript\n var sample ='sample'\n ```\n```\nThis HTML.\n```html\n
\n  var sample ='sample'\n
\n```\n\n## Inject converted HTML to a template\nOnce you have a converted HTML, you can inject it to any file by doing handy dandy `String.replace()`.\n\nI made a template HTML with some place holder like `{{content}}` `{{date}}` `{{description}}` which will be populated with data returned from gist API.\n\n## Publish\nAfter I convert gist markdown into HTML, I edit blog directory page, then manually deploy to my server.\nIt is a little bit tedious, but then, I'm only going to publish once in few month, so this process is good enough.\n\n\n## The Script\nHere is the script! To run it, I do following command and pass gist id as argument\n\n`node gist2HTML.js [gist id]`\n\n#### gist2HTML.js\n```javascript\nvar fs = require('fs');\nvar md = require('markdown-it')();\n\nvar gistID = process.argv[2]\n\nfs.readFile('template.html','utf8', function (err, data) {\n if (err) throw err;\n var template = data;\n\n var options = {\n host: 'api.github.com',\n path: '/gists/'+gistID,\n headers: {'user-agent': 'nodescript'}\n };\n\n https.request(options, function(response) {\n var str = '';\n\n response.on('data', function (chunk) {\n str += chunk;\n });\n\n response.on('end', function () {\n var res = JSON.parse(str);\n var file = res.files[Object.keys(res.files)[0]];\n var html = md.render(file.content);\n var filename = file.filename.split('.')[0];\n var date = new Date(res.created_at)\n template = template\n .replace(/{{date}}/g,date.toISOString().split('T')[0])\n .replace('{{content}}',html)\n .replace('{{title}}', filename.split('-').join(' '))\n .replace('{{description}}', res.description)\n\n fs.writeFile(filename+'.html', template , function (err) {\n if (err) throw err;\n console.log('file created: ' +filename);\n });\n\n });\n }).end();\n});\n```\n#### template.html\n```html\n\n\n \n {{title}}\n \n \n \n
\n \n {{content}}\n
\n \n\n\n```\n"}},"public":false,"created_at":"2015-08-15T16:15:48Z","updated_at":"2015-08-29T14:27:27Z","description":"Writing markdown file on gist as blogging platform","comments":0,"user":null,"comments_url":"https://api.github.com/gists/cd6d137f872b5f9c9423/comments","owner":{"login":"kosamari","id":4581495,"avatar_url":"https://avatars0.githubusercontent.com/u/4581495?v=4","gravatar_id":"","url":"https://api.github.com/users/kosamari","html_url":"https://github.com/kosamari","followers_url":"https://api.github.com/users/kosamari/followers","following_url":"https://api.github.com/users/kosamari/following{/other_user}","gists_url":"https://api.github.com/users/kosamari/gists{/gist_id}","starred_url":"https://api.github.com/users/kosamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kosamari/subscriptions","organizations_url":"https://api.github.com/users/kosamari/orgs","repos_url":"https://api.github.com/users/kosamari/repos","events_url":"https://api.github.com/users/kosamari/events{/privacy}","received_events_url":"https://api.github.com/users/kosamari/received_events","type":"User","site_admin":false},"forks":[],"history":[{"user":{"login":"kosamari","id":4581495,"avatar_url":"https://avatars0.githubusercontent.com/u/4581495?v=4","gravatar_id":"","url":"https://api.github.com/users/kosamari","html_url":"https://github.com/kosamari","followers_url":"https://api.github.com/users/kosamari/followers","following_url":"https://api.github.com/users/kosamari/following{/other_user}","gists_url":"https://api.github.com/users/kosamari/gists{/gist_id}","starred_url":"https://api.github.com/users/kosamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kosamari/subscriptions","organizations_url":"https://api.github.com/users/kosamari/orgs","repos_url":"https://api.github.com/users/kosamari/repos","events_url":"https://api.github.com/users/kosamari/events{/privacy}","received_events_url":"https://api.github.com/users/kosamari/received_events","type":"User","site_admin":false},"version":"a4b0b2dfa4fa9a4709b4ace6fa27421c894b314b","committed_at":"2015-08-15T19:18:21Z","change_status":{"total":2,"additions":1,"deletions":1},"url":"https://api.github.com/gists/cd6d137f872b5f9c9423/a4b0b2dfa4fa9a4709b4ace6fa27421c894b314b"},{"user":{"login":"kosamari","id":4581495,"avatar_url":"https://avatars0.githubusercontent.com/u/4581495?v=4","gravatar_id":"","url":"https://api.github.com/users/kosamari","html_url":"https://github.com/kosamari","followers_url":"https://api.github.com/users/kosamari/followers","following_url":"https://api.github.com/users/kosamari/following{/other_user}","gists_url":"https://api.github.com/users/kosamari/gists{/gist_id}","starred_url":"https://api.github.com/users/kosamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kosamari/subscriptions","organizations_url":"https://api.github.com/users/kosamari/orgs","repos_url":"https://api.github.com/users/kosamari/repos","events_url":"https://api.github.com/users/kosamari/events{/privacy}","received_events_url":"https://api.github.com/users/kosamari/received_events","type":"User","site_admin":false},"version":"e6be89868f100ea689c4d0cf5ba93b6ff300ed9c","committed_at":"2015-08-15T19:17:57Z","change_status":{"total":8,"additions":4,"deletions":4},"url":"https://api.github.com/gists/cd6d137f872b5f9c9423/e6be89868f100ea689c4d0cf5ba93b6ff300ed9c"},{"user":{"login":"kosamari","id":4581495,"avatar_url":"https://avatars0.githubusercontent.com/u/4581495?v=4","gravatar_id":"","url":"https://api.github.com/users/kosamari","html_url":"https://github.com/kosamari","followers_url":"https://api.github.com/users/kosamari/followers","following_url":"https://api.github.com/users/kosamari/following{/other_user}","gists_url":"https://api.github.com/users/kosamari/gists{/gist_id}","starred_url":"https://api.github.com/users/kosamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kosamari/subscriptions","organizations_url":"https://api.github.com/users/kosamari/orgs","repos_url":"https://api.github.com/users/kosamari/repos","events_url":"https://api.github.com/users/kosamari/events{/privacy}","received_events_url":"https://api.github.com/users/kosamari/received_events","type":"User","site_admin":false},"version":"64f12c4f687726a4d1c2ae6ed4ffae8bfe51f3f4","committed_at":"2015-08-15T17:15:10Z","change_status":{"total":2,"additions":1,"deletions":1},"url":"https://api.github.com/gists/cd6d137f872b5f9c9423/64f12c4f687726a4d1c2ae6ed4ffae8bfe51f3f4"},{"user":{"login":"kosamari","id":4581495,"avatar_url":"https://avatars0.githubusercontent.com/u/4581495?v=4","gravatar_id":"","url":"https://api.github.com/users/kosamari","html_url":"https://github.com/kosamari","followers_url":"https://api.github.com/users/kosamari/followers","following_url":"https://api.github.com/users/kosamari/following{/other_user}","gists_url":"https://api.github.com/users/kosamari/gists{/gist_id}","starred_url":"https://api.github.com/users/kosamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kosamari/subscriptions","organizations_url":"https://api.github.com/users/kosamari/orgs","repos_url":"https://api.github.com/users/kosamari/repos","events_url":"https://api.github.com/users/kosamari/events{/privacy}","received_events_url":"https://api.github.com/users/kosamari/received_events","type":"User","site_admin":false},"version":"aa080651067a535cb1707fe88721c131619d4439","committed_at":"2015-08-15T17:14:04Z","change_status":{"total":4,"additions":2,"deletions":2},"url":"https://api.github.com/gists/cd6d137f872b5f9c9423/aa080651067a535cb1707fe88721c131619d4439"},{"user":{"login":"kosamari","id":4581495,"avatar_url":"https://avatars0.githubusercontent.com/u/4581495?v=4","gravatar_id":"","url":"https://api.github.com/users/kosamari","html_url":"https://github.com/kosamari","followers_url":"https://api.github.com/users/kosamari/followers","following_url":"https://api.github.com/users/kosamari/following{/other_user}","gists_url":"https://api.github.com/users/kosamari/gists{/gist_id}","starred_url":"https://api.github.com/users/kosamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kosamari/subscriptions","organizations_url":"https://api.github.com/users/kosamari/orgs","repos_url":"https://api.github.com/users/kosamari/repos","events_url":"https://api.github.com/users/kosamari/events{/privacy}","received_events_url":"https://api.github.com/users/kosamari/received_events","type":"User","site_admin":false},"version":"7ec178f7a700c5b0b858bdb2ff866022677c7f43","committed_at":"2015-08-15T17:12:06Z","change_status":{"total":8,"additions":4,"deletions":4},"url":"https://api.github.com/gists/cd6d137f872b5f9c9423/7ec178f7a700c5b0b858bdb2ff866022677c7f43"},{"user":{"login":"kosamari","id":4581495,"avatar_url":"https://avatars0.githubusercontent.com/u/4581495?v=4","gravatar_id":"","url":"https://api.github.com/users/kosamari","html_url":"https://github.com/kosamari","followers_url":"https://api.github.com/users/kosamari/followers","following_url":"https://api.github.com/users/kosamari/following{/other_user}","gists_url":"https://api.github.com/users/kosamari/gists{/gist_id}","starred_url":"https://api.github.com/users/kosamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kosamari/subscriptions","organizations_url":"https://api.github.com/users/kosamari/orgs","repos_url":"https://api.github.com/users/kosamari/repos","events_url":"https://api.github.com/users/kosamari/events{/privacy}","received_events_url":"https://api.github.com/users/kosamari/received_events","type":"User","site_admin":false},"version":"6811e3dc850bb90fde0a9f707e8f0dfeeaff4d49","committed_at":"2015-08-15T17:11:04Z","change_status":{"total":9,"additions":4,"deletions":5},"url":"https://api.github.com/gists/cd6d137f872b5f9c9423/6811e3dc850bb90fde0a9f707e8f0dfeeaff4d49"},{"user":{"login":"kosamari","id":4581495,"avatar_url":"https://avatars0.githubusercontent.com/u/4581495?v=4","gravatar_id":"","url":"https://api.github.com/users/kosamari","html_url":"https://github.com/kosamari","followers_url":"https://api.github.com/users/kosamari/followers","following_url":"https://api.github.com/users/kosamari/following{/other_user}","gists_url":"https://api.github.com/users/kosamari/gists{/gist_id}","starred_url":"https://api.github.com/users/kosamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kosamari/subscriptions","organizations_url":"https://api.github.com/users/kosamari/orgs","repos_url":"https://api.github.com/users/kosamari/repos","events_url":"https://api.github.com/users/kosamari/events{/privacy}","received_events_url":"https://api.github.com/users/kosamari/received_events","type":"User","site_admin":false},"version":"2e98e62069d3039fe76a827c83b3991e57272344","committed_at":"2015-08-15T17:06:32Z","change_status":{"total":2,"additions":1,"deletions":1},"url":"https://api.github.com/gists/cd6d137f872b5f9c9423/2e98e62069d3039fe76a827c83b3991e57272344"},{"user":{"login":"kosamari","id":4581495,"avatar_url":"https://avatars0.githubusercontent.com/u/4581495?v=4","gravatar_id":"","url":"https://api.github.com/users/kosamari","html_url":"https://github.com/kosamari","followers_url":"https://api.github.com/users/kosamari/followers","following_url":"https://api.github.com/users/kosamari/following{/other_user}","gists_url":"https://api.github.com/users/kosamari/gists{/gist_id}","starred_url":"https://api.github.com/users/kosamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kosamari/subscriptions","organizations_url":"https://api.github.com/users/kosamari/orgs","repos_url":"https://api.github.com/users/kosamari/repos","events_url":"https://api.github.com/users/kosamari/events{/privacy}","received_events_url":"https://api.github.com/users/kosamari/received_events","type":"User","site_admin":false},"version":"2d3542719d021a777eaf5f82307c86efe3f2b0b0","committed_at":"2015-08-15T17:01:50Z","change_status":{"total":0,"additions":0,"deletions":0},"url":"https://api.github.com/gists/cd6d137f872b5f9c9423/2d3542719d021a777eaf5f82307c86efe3f2b0b0"},{"user":{"login":"kosamari","id":4581495,"avatar_url":"https://avatars0.githubusercontent.com/u/4581495?v=4","gravatar_id":"","url":"https://api.github.com/users/kosamari","html_url":"https://github.com/kosamari","followers_url":"https://api.github.com/users/kosamari/followers","following_url":"https://api.github.com/users/kosamari/following{/other_user}","gists_url":"https://api.github.com/users/kosamari/gists{/gist_id}","starred_url":"https://api.github.com/users/kosamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kosamari/subscriptions","organizations_url":"https://api.github.com/users/kosamari/orgs","repos_url":"https://api.github.com/users/kosamari/repos","events_url":"https://api.github.com/users/kosamari/events{/privacy}","received_events_url":"https://api.github.com/users/kosamari/received_events","type":"User","site_admin":false},"version":"cafb5159903bc03c3e5312d7bdd6225cca14d6c4","committed_at":"2015-08-15T17:00:54Z","change_status":{"total":2,"additions":1,"deletions":1},"url":"https://api.github.com/gists/cd6d137f872b5f9c9423/cafb5159903bc03c3e5312d7bdd6225cca14d6c4"},{"user":{"login":"kosamari","id":4581495,"avatar_url":"https://avatars0.githubusercontent.com/u/4581495?v=4","gravatar_id":"","url":"https://api.github.com/users/kosamari","html_url":"https://github.com/kosamari","followers_url":"https://api.github.com/users/kosamari/followers","following_url":"https://api.github.com/users/kosamari/following{/other_user}","gists_url":"https://api.github.com/users/kosamari/gists{/gist_id}","starred_url":"https://api.github.com/users/kosamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kosamari/subscriptions","organizations_url":"https://api.github.com/users/kosamari/orgs","repos_url":"https://api.github.com/users/kosamari/repos","events_url":"https://api.github.com/users/kosamari/events{/privacy}","received_events_url":"https://api.github.com/users/kosamari/received_events","type":"User","site_admin":false},"version":"cd24c19fcdb8fbc85bea54a639561aacbc8dd67b","committed_at":"2015-08-15T17:00:28Z","change_status":{"total":8,"additions":3,"deletions":5},"url":"https://api.github.com/gists/cd6d137f872b5f9c9423/cd24c19fcdb8fbc85bea54a639561aacbc8dd67b"},{"user":{"login":"kosamari","id":4581495,"avatar_url":"https://avatars0.githubusercontent.com/u/4581495?v=4","gravatar_id":"","url":"https://api.github.com/users/kosamari","html_url":"https://github.com/kosamari","followers_url":"https://api.github.com/users/kosamari/followers","following_url":"https://api.github.com/users/kosamari/following{/other_user}","gists_url":"https://api.github.com/users/kosamari/gists{/gist_id}","starred_url":"https://api.github.com/users/kosamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kosamari/subscriptions","organizations_url":"https://api.github.com/users/kosamari/orgs","repos_url":"https://api.github.com/users/kosamari/repos","events_url":"https://api.github.com/users/kosamari/events{/privacy}","received_events_url":"https://api.github.com/users/kosamari/received_events","type":"User","site_admin":false},"version":"71b485cba44b1f5af2e01ae10eacf438a9f1aa4e","committed_at":"2015-08-15T16:57:52Z","change_status":{},"url":"https://api.github.com/gists/cd6d137f872b5f9c9423/71b485cba44b1f5af2e01ae10eacf438a9f1aa4e"},{"user":{"login":"kosamari","id":4581495,"avatar_url":"https://avatars0.githubusercontent.com/u/4581495?v=4","gravatar_id":"","url":"https://api.github.com/users/kosamari","html_url":"https://github.com/kosamari","followers_url":"https://api.github.com/users/kosamari/followers","following_url":"https://api.github.com/users/kosamari/following{/other_user}","gists_url":"https://api.github.com/users/kosamari/gists{/gist_id}","starred_url":"https://api.github.com/users/kosamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kosamari/subscriptions","organizations_url":"https://api.github.com/users/kosamari/orgs","repos_url":"https://api.github.com/users/kosamari/repos","events_url":"https://api.github.com/users/kosamari/events{/privacy}","received_events_url":"https://api.github.com/users/kosamari/received_events","type":"User","site_admin":false},"version":"a3bd6d298e2075be5a499691c1ec9edc47bb8da1","committed_at":"2015-08-15T16:55:40Z","change_status":{},"url":"https://api.github.com/gists/cd6d137f872b5f9c9423/a3bd6d298e2075be5a499691c1ec9edc47bb8da1"},{"user":{"login":"kosamari","id":4581495,"avatar_url":"https://avatars0.githubusercontent.com/u/4581495?v=4","gravatar_id":"","url":"https://api.github.com/users/kosamari","html_url":"https://github.com/kosamari","followers_url":"https://api.github.com/users/kosamari/followers","following_url":"https://api.github.com/users/kosamari/following{/other_user}","gists_url":"https://api.github.com/users/kosamari/gists{/gist_id}","starred_url":"https://api.github.com/users/kosamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kosamari/subscriptions","organizations_url":"https://api.github.com/users/kosamari/orgs","repos_url":"https://api.github.com/users/kosamari/repos","events_url":"https://api.github.com/users/kosamari/events{/privacy}","received_events_url":"https://api.github.com/users/kosamari/received_events","type":"User","site_admin":false},"version":"425a335a3a8dbd704eeed6c384cb6b4a1151bde1","committed_at":"2015-08-15T16:24:40Z","change_status":{},"url":"https://api.github.com/gists/cd6d137f872b5f9c9423/425a335a3a8dbd704eeed6c384cb6b4a1151bde1"},{"user":{"login":"kosamari","id":4581495,"avatar_url":"https://avatars0.githubusercontent.com/u/4581495?v=4","gravatar_id":"","url":"https://api.github.com/users/kosamari","html_url":"https://github.com/kosamari","followers_url":"https://api.github.com/users/kosamari/followers","following_url":"https://api.github.com/users/kosamari/following{/other_user}","gists_url":"https://api.github.com/users/kosamari/gists{/gist_id}","starred_url":"https://api.github.com/users/kosamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kosamari/subscriptions","organizations_url":"https://api.github.com/users/kosamari/orgs","repos_url":"https://api.github.com/users/kosamari/repos","events_url":"https://api.github.com/users/kosamari/events{/privacy}","received_events_url":"https://api.github.com/users/kosamari/received_events","type":"User","site_admin":false},"version":"5fc05ef2bd8c5d3becd7da46decc13d307ac322d","committed_at":"2015-08-15T16:19:00Z","change_status":{},"url":"https://api.github.com/gists/cd6d137f872b5f9c9423/5fc05ef2bd8c5d3becd7da46decc13d307ac322d"},{"user":{"login":"kosamari","id":4581495,"avatar_url":"https://avatars0.githubusercontent.com/u/4581495?v=4","gravatar_id":"","url":"https://api.github.com/users/kosamari","html_url":"https://github.com/kosamari","followers_url":"https://api.github.com/users/kosamari/followers","following_url":"https://api.github.com/users/kosamari/following{/other_user}","gists_url":"https://api.github.com/users/kosamari/gists{/gist_id}","starred_url":"https://api.github.com/users/kosamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kosamari/subscriptions","organizations_url":"https://api.github.com/users/kosamari/orgs","repos_url":"https://api.github.com/users/kosamari/repos","events_url":"https://api.github.com/users/kosamari/events{/privacy}","received_events_url":"https://api.github.com/users/kosamari/received_events","type":"User","site_admin":false},"version":"45f64e599a5b10d011f7df4a9e6586c998ffacd5","committed_at":"2015-08-15T16:15:48Z","change_status":{},"url":"https://api.github.com/gists/cd6d137f872b5f9c9423/45f64e599a5b10d011f7df4a9e6586c998ffacd5"}],"truncated":false}