This commit is contained in:
hazycora 2023-08-02 17:17:21 -05:00
parent d684ad6045
commit a72e440222
No known key found for this signature in database
GPG key ID: 215AF1F81F86940E

View file

@ -2,7 +2,7 @@ import html2png from '@besties/html2png'
import express from 'express'
import fs from 'node:fs'
const app = express();
const app = express()
const figtreeRegular = fs.readFileSync('./assets/Figtree-Regular.woff')
const figtreeMedium = fs.readFileSync('./assets/Figtree-Medium.woff')
@ -10,8 +10,6 @@ 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
@ -30,20 +28,31 @@ function escape(value, is_attr = false) {
return escaped + str.slice(Math.max(0, last))
}
app.get('/', function(req, res) {
res.redirect("https://git.gay/gitgay/og.git");
});
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 = `
<p style="font-size: 36px; color: #9A8FA7;">${escape(repo.owner.full_name)} ${escape(`@${repo.owner.login}`)}</p>
<p style="font-weight: 800; font-size: 4.5rem; line-height: 1.2em;">${escape(repo.name)}</p>
`;
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 = `
<p style="font-size: 36px; color: #9A8FA7;">${escape(
repo.owner.full_name
)} ${escape(`@${repo.owner.login}`)}</p>
<p style="font-weight: 800; font-size: 4.5rem; line-height: 1.2em;">${escape(
repo.name
)}</p>
`
if (repo.description) infoHtml = `${infoHtml}<p style="font-size: 42px; font-weight: 500; color: #9A8FA7;">${escape(repo.description)}</p>`;
if (repo.description)
infoHtml = `${infoHtml}<p style="font-size: 42px; font-weight: 500; color: #9A8FA7;">${escape(
repo.description
)}</p>`
let img = await html2png(
let img = await html2png(
`<div class="main">
<div class="contents">
<div class="info">
@ -117,9 +126,9 @@ app.get('/:owner/:repo', async function(req, res) {
}
]
}
);
)
res.send(img);
res.send(img)
})
app.listen(8085);
app.listen(8085)