add debug option to skip PNG rendering
This commit is contained in:
parent
8e5077e9be
commit
2cf7675588
4 changed files with 35 additions and 3 deletions
|
@ -30,6 +30,6 @@ const renderOptions = {
|
|||
]
|
||||
}
|
||||
|
||||
export default function (html) {
|
||||
export default async function (html) {
|
||||
return html2png(html, css, renderOptions)
|
||||
}
|
||||
|
|
23
server.js
23
server.js
|
@ -1,9 +1,13 @@
|
|||
import express from 'express'
|
||||
import { Eta } from 'eta'
|
||||
import fs from 'node:fs/promises'
|
||||
import render from './lib/render.js'
|
||||
|
||||
const debug = process.env.DEBUG ? true : false
|
||||
|
||||
const eta = new Eta({
|
||||
views: 'views',
|
||||
cache: false
|
||||
cache: !debug
|
||||
})
|
||||
|
||||
const app = express()
|
||||
|
@ -12,14 +16,29 @@ 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}`
|
||||
)
|
||||
const repo = await repoResp.json()
|
||||
const html = await eta.renderAsync('repo', {
|
||||
repo,
|
||||
debug
|
||||
})
|
||||
if (debug) {
|
||||
res.send(html)
|
||||
return
|
||||
}
|
||||
res.type('png')
|
||||
res.set('Content-Disposition', 'inline')
|
||||
res.send(await render(await eta.renderAsync('repo', { repo })))
|
||||
res.send(await render(html))
|
||||
})
|
||||
|
||||
app.listen(8085)
|
||||
|
|
12
views/layout.eta
Normal file
12
views/layout.eta
Normal file
|
@ -0,0 +1,12 @@
|
|||
<% if (it.debug) { %>
|
||||
<style>
|
||||
:root {
|
||||
font-family: 'Figtree', Arial, Helvetica, sans-serif;
|
||||
}
|
||||
* {
|
||||
font-family: inherit;
|
||||
}
|
||||
</style>
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
<% } %>
|
||||
<%~ it.body %>
|
|
@ -1,3 +1,4 @@
|
|||
<% layout('layout') %>
|
||||
<div class="main">
|
||||
<div class="contents">
|
||||
<div class="info">
|
||||
|
|
Loading…
Reference in a new issue