refactor debug mode

This commit is contained in:
hazycora 2023-08-02 18:54:54 -05:00
parent 09d6c4045e
commit a0cda32d67
No known key found for this signature in database
GPG key ID: 215AF1F81F86940E
3 changed files with 11 additions and 13 deletions

View file

@ -1,4 +1,4 @@
import html2png from '@besties/html2png'
import html2png, { renderHtml as htmlParser } from '@besties/html2png'
import fs from 'node:fs'
const figtreeRegular = fs.readFileSync('./assets/Figtree-Regular.woff')
@ -33,3 +33,10 @@ const renderOptions = {
export default async function (html) {
return html2png(html, css, renderOptions)
}
export async function renderHtml(html) {
return htmlParser(
html,
await fs.promises.readFile('./assets/style.css', 'utf8')
).outerHTML
}

View file

@ -1,7 +1,6 @@
import express from 'express'
import { Eta } from 'eta'
import fs from 'node:fs/promises'
import render from './lib/render.js'
import render, { renderHtml } from './lib/render.js'
const debug = process.env.DEBUG ? true : false
@ -16,13 +15,6 @@ app.get('/', function (req, res) {
res.redirect('https://git.gay/gitgay/og.git')
})
if (debug) {
app.get('/style.css', async (req, res) => {
res.type('css')
res.send(await fs.readFile('./assets/style.css'))
})
}
app.get('/:owner/:repo', async function (req, res) {
const repoResp = await fetch(
`https://git.gay/api/v1/repos/${req.params.owner}/${req.params.repo}`
@ -33,7 +25,7 @@ app.get('/:owner/:repo', async function (req, res) {
debug
})
if (debug) {
res.send(html)
res.send(renderHtml(html))
return
}
res.type('png')
@ -51,7 +43,7 @@ app.get('/:owner/:repo/:type/:num', async function (req, res) {
debug
})
if (debug) {
res.send(html)
res.send(renderHtml(html))
return
}
res.type('png')

View file

@ -18,7 +18,6 @@
height: 100%;
}
</style>
<link rel="stylesheet" href="/style.css">
<title>OpenGraph Debug Preview</title>
</head>
<% } %>