mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-07-07 17:15:15 +02:00
Added simple-icons role draft
This commit is contained in:
parent
c537a1f5b6
commit
eed72368c1
25
roles/docker-simpleicons/templates/Dockerfile
Normal file
25
roles/docker-simpleicons/templates/Dockerfile
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# ---- Builder Stage ----
|
||||||
|
FROM node:latest AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
# Nur package.json und package-lock.json kopieren für schnellere Caching-Layers
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# simple-icons installieren
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
# ---- Runtime Stage ----
|
||||||
|
FROM node:latest
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
# Nur node_modules aus dem Builder übernehmen
|
||||||
|
COPY --from=builder /app/node_modules ./node_modules
|
||||||
|
# Kopiere den Server-Code
|
||||||
|
COPY server.js .
|
||||||
|
|
||||||
|
# Port, auf dem der Server lauscht
|
||||||
|
ENV PORT=3000
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Startbefehl
|
||||||
|
CMD ["node", "server.js"]
|
14
roles/docker-simpleicons/templates/docker-compose.yml
Normal file
14
roles/docker-simpleicons/templates/docker-compose.yml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
icons:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
image: simpleicons-server:latest
|
||||||
|
container_name: simpleicons-server
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
environment:
|
||||||
|
- PORT=3000
|
||||||
|
restart: unless-stopped
|
9
roles/docker-simpleicons/templates/package.json
Normal file
9
roles/docker-simpleicons/templates/package.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"name": "simpleicons-server",
|
||||||
|
"type": "module",
|
||||||
|
"dependencies": {
|
||||||
|
"express": "^4.18.2",
|
||||||
|
"simple-icons": "^9.0.0",
|
||||||
|
"sharp": "^0.32.0"
|
||||||
|
}
|
||||||
|
}
|
55
roles/docker-simpleicons/templates/server.js
Normal file
55
roles/docker-simpleicons/templates/server.js
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import express from 'express';
|
||||||
|
import * as icons from 'simple-icons';
|
||||||
|
import sharp from 'sharp';
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
const port = process.env.PORT || 3000;
|
||||||
|
|
||||||
|
// Helper: turn 'nextcloud' → 'siNextcloud'
|
||||||
|
function getExportName(slug) {
|
||||||
|
return 'si' + slug
|
||||||
|
.split('-')
|
||||||
|
.map(part => part[0].toUpperCase() + part.slice(1))
|
||||||
|
.join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /icons/:slug.svg
|
||||||
|
app.get('/icons/:slug.svg', (req, res) => {
|
||||||
|
const slug = req.params.slug.toLowerCase();
|
||||||
|
const exportName = getExportName(slug);
|
||||||
|
const icon = icons[exportName];
|
||||||
|
|
||||||
|
if (!icon) {
|
||||||
|
return res.status(404).send('Icon not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
res.type('image/svg+xml').send(icon.svg);
|
||||||
|
});
|
||||||
|
|
||||||
|
// GET /icons/:slug.png?size=...
|
||||||
|
app.get('/icons/:slug.png', async (req, res) => {
|
||||||
|
const slug = req.params.slug.toLowerCase();
|
||||||
|
const size = parseInt(req.query.size, 10) || 128;
|
||||||
|
const exportName = getExportName(slug);
|
||||||
|
const icon = icons[exportName];
|
||||||
|
|
||||||
|
if (!icon) {
|
||||||
|
return res.status(404).send('Icon not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const png = await sharp(Buffer.from(icon.svg))
|
||||||
|
.resize(size, size)
|
||||||
|
.png()
|
||||||
|
.toBuffer();
|
||||||
|
|
||||||
|
res.type('image/png').send(png);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('PNG generation error:', err);
|
||||||
|
res.status(500).send('PNG generation error');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.listen(port, () => {
|
||||||
|
console.log(`Simple-Icons server listening at http://0.0.0.0:${port}`);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user