Add Comic Sans easter egg

This commit is contained in:
hazycora 2023-08-03 14:28:31 -05:00
parent 3cb301360e
commit 7d6cf5b09f
No known key found for this signature in database
GPG key ID: 215AF1F81F86940E
7 changed files with 55 additions and 18 deletions

View file

@ -5,6 +5,7 @@ import render, { renderHtml } from './lib/render.js'
import languageColors from './lib/languagecolors.js'
import fetch from 'node-fetch'
import hash from './lib/hash.js'
import { DMSans, ComicSans } from './lib/fonts.js'
// satori is using the native fetch api, causing a warning, so make node-fetch the default
globalThis.fetch = fetch
@ -49,6 +50,8 @@ async function getLanguages(owner, repo) {
return {}
}
const comicSansNames = new Set(['trixie'])
app.get('/:owner/:repo', async function (req, res) {
const [repoResp, commitsResp, languages] = await Promise.all([
fetch(
@ -81,10 +84,13 @@ app.get('/:owner/:repo', async function (req, res) {
res.send(await renderHtml(html))
return
}
const format = req.query.format == 'svg' ? 'svg' : 'png'
res.type(format)
const options = {
fonts: comicSansNames.has(req.params.owner) ? ComicSans : DMSans,
format: req.query.format == 'svg' ? 'svg' : 'png'
}
res.type(options.format)
res.set('Content-Disposition', 'inline')
res.send(await render(html, { format }))
res.send(await render(html, options))
})
app.get('/:owner/:repo/commit/:hash', async function (req, res) {
@ -128,10 +134,13 @@ app.get('/:owner/:repo/commit/:hash', async function (req, res) {
res.send(await renderHtml(html))
return
}
const format = req.query.format == 'svg' ? 'svg' : 'png'
res.type(format)
const options = {
fonts: comicSansNames.has(req.params.owner) ? ComicSans : DMSans,
format: req.query.format == 'svg' ? 'svg' : 'png'
}
res.type(options.format)
res.set('Content-Disposition', 'inline')
res.send(await render(html, { format }))
res.send(await render(html, options))
})
app.get('/:owner/:repo/:type/:num', (req, res, next) => {
@ -174,10 +183,13 @@ app.get('/:owner/:repo/issues/:num', async function (req, res) {
res.send(await renderHtml(html))
return
}
const format = req.query.format == 'svg' ? 'svg' : 'png'
res.type(format)
const options = {
fonts: comicSansNames.has(req.params.owner) ? ComicSans : DMSans,
format: req.query.format == 'svg' ? 'svg' : 'png'
}
res.type(options.format)
res.set('Content-Disposition', 'inline')
res.send(await render(html, { format }))
res.send(await render(html, options))
})
app.get('/:owner/:repo/pulls/:num', async function (req, res) {
@ -226,10 +238,13 @@ app.get('/:owner/:repo/pulls/:num', async function (req, res) {
res.send(await renderHtml(html))
return
}
const format = req.query.format == 'svg' ? 'svg' : 'png'
res.type(format)
const options = {
fonts: comicSansNames.has(req.params.owner) ? ComicSans : DMSans,
format: req.query.format == 'svg' ? 'svg' : 'png'
}
res.type(options.format)
res.set('Content-Disposition', 'inline')
res.send(await render(html, { format }))
res.send(await render(html, options))
})
const [port, host] = [process.env.PORT ?? 9054, process.env.HOST ?? '127.0.0.1']