import html2png from '@besties/html2png' import express from 'express' import fs from 'node:fs' const app = express() const figtreeRegular = fs.readFileSync('./assets/Figtree-Regular.woff') const figtreeMedium = fs.readFileSync('./assets/Figtree-Medium.woff') const figtreeExtraBold = fs.readFileSync('./assets/Figtree-ExtraBold.woff') const ATTR_REGEX = /["&]/g const CONTENT_REGEX = /[&<]/g function escape(value, is_attr = false) { const str = String(value) const pattern = is_attr ? ATTR_REGEX : CONTENT_REGEX pattern.lastIndex = 0 let escaped = '' let last = 0 while (pattern.test(str)) { const i = pattern.lastIndex - 1 const ch = str[i] escaped += // eslint-disable-next-line unicorn/prefer-string-slice str.substring(last, i) + (ch === '&' ? '&' : ch === '"' ? '"' : '<') last = i + 1 } return escaped + str.slice(Math.max(0, last)) } app.get('/', function (req, res) { res.redirect('https://git.gay/gitgay/og.git') }) app.get('/:owner/:repo', async function (req, res) { let repo = await ( await fetch( `https://git.gay/api/v1/repos/${req.params.owner}/${req.params.repo}` ) ).json() let infoHtml = `
${escape( repo.owner.full_name )} ${escape(`@${repo.owner.login}`)}
${escape( repo.name )}
` if (repo.description) infoHtml = `${infoHtml}${escape( repo.description )}
` let img = await html2png( `