Improve placeholder generation

This commit is contained in:
linguist
2021-01-03 16:33:13 +01:00
parent 23aa69d0ae
commit 2186611784
3 changed files with 39 additions and 13 deletions

View File

@@ -60,7 +60,6 @@
}
//Cache headers middleware
middlewares.push((req, res, next) => {
console.log(["/placeholder"].includes(req.path))
if (!["/placeholder"].includes(req.path))
res.header("Cache-Control", cached ? `public, max-age=${cached}` : "no-store, no-cache")
next()
@@ -112,6 +111,12 @@
//Metrics
app.get("/:login", ...middlewares, async (req, res) => {
//Placeholder hash
const placeholder = Object.entries(parse(req.query)).filter(([key, value]) =>
((key in Plugins)&&(!!value))||
((key === "template")&&(value in Templates))||
(/base[.](header|activity|community|repositories|metadata)/.test(key))
).map(([key, value]) => `${key}${key === "template" ? `#${value}` : ""}`).sort().join("+")
//Request params
const {login} = req.params
@@ -121,8 +126,8 @@
}
//Read cached data if possible
//Placeholder
if ((login === "placeholder")&&(cache.placeholder.get(Object.keys(req.query).sort().join("-")))) {
const {rendered, mime} = cache.placeholder.get(Object.keys(req.query).sort().join("-"))
if ((login === "placeholder")&&(cache.placeholder.get(placeholder))) {
const {rendered, mime} = cache.placeholder.get(placeholder)
res.header("Content-Type", mime)
res.send(rendered)
return
@@ -153,7 +158,7 @@
}, {Plugins, Templates})
//Cache
if (login === "placeholder")
cache.placeholder.put(Object.keys(req.query).sort().join("-"), rendered)
cache.placeholder.put(placeholder, {rendered, mime})
if ((!debug)&&(cached))
cache.put(login, {rendered, mime}, cached)
//Send response

View File

@@ -13,13 +13,13 @@
<body>
<!-- Vue app -->
<main :class="[palette]">
<template>
<!-- Title -->
<h1 class="title">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path></svg>
<a href="https://github.com/lowlighter/metrics">Metrics v{{ version }}</a>
</h1>
<!-- Content -->
<template>
<!-- Tabs -->
<nav>
@@ -71,6 +71,21 @@
</div>
</div>
<!-- Palette -->
<div class="step">
<h2>🌎 Color palette</h2>
<div class="templates">
<label>
<input type="radio" v-model="palette" value="light">
☀️ Light
</label>
<label>
<input type="radio" v-model="palette" value="dark">
🌕 Dark
</label>
</div>
</div>
<!-- Base content -->
<div class="step" v-if="plugins.base.length">
<h2>🗃️ Base content</h2>
@@ -223,10 +238,11 @@
<div class="body">
<div class="readme">
<svg viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M1.326 1.973a1.2 1.2 0 011.49-.832c.387.112.977.307 1.575.602.586.291 1.243.71 1.7 1.296.022.027.042.056.061.084A13.22 13.22 0 018 3c.67 0 1.289.037 1.861.108l.051-.07c.457-.586 1.114-1.004 1.7-1.295a9.654 9.654 0 011.576-.602 1.2 1.2 0 011.49.832c.14.493.356 1.347.479 2.29.079.604.123 1.28.07 1.936.541.977.773 2.11.773 3.301C16 13 14.5 15 8 15s-8-2-8-5.5c0-1.034.238-2.128.795-3.117-.08-.712-.034-1.46.052-2.12.122-.943.34-1.797.479-2.29zM8 13.065c6 0 6.5-2 6-4.27C13.363 5.905 11.25 5 8 5s-5.363.904-6 3.796c-.5 2.27 0 4.27 6 4.27z"></path><path d="M4 8a1 1 0 012 0v1a1 1 0 01-2 0V8zm2.078 2.492c-.083-.264.146-.492.422-.492h3c.276 0 .505.228.422.492C9.67 11.304 8.834 12 8 12c-.834 0-1.669-.696-1.922-1.508zM10 8a1 1 0 112 0v1a1 1 0 11-2 0V8z"></path></svg>
<span>lowlighter</span><span class="slash">/</span>README<span class="md">.md</span>
<span>{{ user }}</span><span class="slash">/</span>README<span class="md">.md</span>
</div>
<!-- Overview -->
<section class="preview" v-if="tab == 'overview'">
Once generated, click on tabs above to see the code to embed them on your real readme !
<template v-if="generated.content">
<img class="metrics" :src="generated.content" alt="metrics">
</template>

View File

@@ -22,12 +22,12 @@
background-color: var(--color-header-bg);
}
.title a {
color: var(--color-text-primary) !important;
color: #fff !important;
font-weight: normal;
}
.title svg {
margin-right: 2rem;
fill: currentColor;
fill: #fff !important;
width: 2rem;
height: 2rem;
}
@@ -267,6 +267,11 @@
.gh-requests {
font-size: .8rem;
}
/* Metrics */
.metrics {
width: 100%;
max-width: 480px;
}
/* Media screen */
@media only screen and (min-width: 700px) {