Add Comic Sans easter egg
This commit is contained in:
parent
3cb301360e
commit
7d6cf5b09f
7 changed files with 55 additions and 18 deletions
BIN
assets/ComicSans/ComicSans-Bold.ttf
Normal file
BIN
assets/ComicSans/ComicSans-Bold.ttf
Normal file
Binary file not shown.
BIN
assets/ComicSans/ComicSans-BoldItalic.ttf
Normal file
BIN
assets/ComicSans/ComicSans-BoldItalic.ttf
Normal file
Binary file not shown.
BIN
assets/ComicSans/ComicSans-Italic.ttf
Normal file
BIN
assets/ComicSans/ComicSans-Italic.ttf
Normal file
Binary file not shown.
BIN
assets/ComicSans/ComicSans-Regular.ttf
Normal file
BIN
assets/ComicSans/ComicSans-Regular.ttf
Normal file
Binary file not shown.
27
lib/fonts.js
27
lib/fonts.js
|
@ -110,3 +110,30 @@ export const DMSans = [
|
|||
style: 'normal'
|
||||
}
|
||||
]
|
||||
|
||||
export const ComicSans = [
|
||||
{
|
||||
name: 'Comic Sans MS',
|
||||
data: fs.readFileSync('./assets/ComicSans/ComicSans-Regular.ttf'),
|
||||
weight: 400,
|
||||
style: 'normal'
|
||||
},
|
||||
{
|
||||
name: 'Comic Sans MS',
|
||||
data: fs.readFileSync('./assets/ComicSans/ComicSans-Italic.ttf'),
|
||||
weight: 400,
|
||||
style: 'italic'
|
||||
},
|
||||
{
|
||||
name: 'Comic Sans MS',
|
||||
data: fs.readFileSync('./assets/ComicSans/ComicSans-Bold.ttf'),
|
||||
weight: 700,
|
||||
style: 'normal'
|
||||
},
|
||||
{
|
||||
name: 'Comic Sans MS',
|
||||
data: fs.readFileSync('./assets/ComicSans/ComicSans-BoldItalic.ttf'),
|
||||
weight: 700,
|
||||
style: 'italic'
|
||||
}
|
||||
]
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
import html2png, { renderHtml as htmlParser } from '@besties/html2png'
|
||||
import fs from 'node:fs'
|
||||
import { DMSans } from './fonts.js'
|
||||
|
||||
const css = fs.readFileSync('./assets/style.css', 'utf8')
|
||||
|
||||
const renderOptions = {
|
||||
fonts: DMSans
|
||||
}
|
||||
|
||||
export default async function (html, options = {}) {
|
||||
return html2png(html, css, { ...renderOptions, ...options })
|
||||
return html2png(html, css, options)
|
||||
}
|
||||
|
||||
export async function renderHtml(html) {
|
||||
|
|
39
server.js
39
server.js
|
@ -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']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue