Skip to content

Commit

Permalink
adds query override, closes #14
Browse files Browse the repository at this point in the history
  • Loading branch information
1wheel committed Oct 3, 2020
1 parent 51c25d3 commit 29fd642
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions routes/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ marked.setOptions({
smartypants: true
})

async function generateHTML (user, id, gist){
async function generateHTML(user, id, gist, query){
if (!gist || !gist.files) return console.log('missing files')

if (gist.files['readme.md'] && !gist.files['README.md']){
Expand Down Expand Up @@ -68,6 +68,11 @@ async function generateHTML (user, id, gist){
})
}

d3.entries(query).forEach(({key, value}) => {
if (value == 'no' || value == 'false' || value == '0') value = false
settings[key] = value
})

if (settings.redirect){
return `<meta http-equiv='Refresh' content='0; url=${settings.redirect}'/>`
}
Expand Down Expand Up @@ -137,7 +142,7 @@ module.exports = async function get(req, res, next) {
var {user, id} = req.params
var url = `https://api.github.com/gists/${id}`
var gist = await fetchCache(url, 'json')
var html = await generateHTML(user, id, gist)
var html = await generateHTML(user, id, gist, req.query)

res.writeHead(200, {'Content-Type': 'text/html'})
res.end(html)
Expand Down

0 comments on commit 29fd642

Please sign in to comment.