From a0cda32d6790dab2bfda44fff036c0303c3803a8 Mon Sep 17 00:00:00 2001 From: hazycora Date: Wed, 2 Aug 2023 18:54:54 -0500 Subject: [PATCH] refactor debug mode --- lib/render.js | 9 ++++++++- server.js | 14 +++----------- views/layout.eta | 1 - 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/render.js b/lib/render.js index b42c5a6..298ea15 100644 --- a/lib/render.js +++ b/lib/render.js @@ -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 +} diff --git a/server.js b/server.js index bcd4545..3115794 100644 --- a/server.js +++ b/server.js @@ -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') diff --git a/views/layout.eta b/views/layout.eta index 805c0b1..aadd29d 100644 --- a/views/layout.eta +++ b/views/layout.eta @@ -18,7 +18,6 @@ height: 100%; } - OpenGraph Debug Preview <% } %>