From 4795b5d761a6260d58d1858a22f4bee4c5e139fb Mon Sep 17 00:00:00 2001 From: VDawg Date: Sun, 8 Sep 2024 20:11:28 +0300 Subject: [PATCH] Small stuff (#69) * refactor Title refactor title component * featureSlice: nicer max-width * add meta title to news * plugins as toml, no plugin sub-pages fixup toml * plugins: better letter if no icon present * add more plugins to showcase * fix blur script --- scripts/generate-blurred-images.mjs | 24 +++++++++++++++--------- src/routes/api/plugins/+server.js | 21 +++++++-------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/scripts/generate-blurred-images.mjs b/scripts/generate-blurred-images.mjs index 1f0b150..a990d63 100644 --- a/scripts/generate-blurred-images.mjs +++ b/scripts/generate-blurred-images.mjs @@ -21,17 +21,23 @@ const filePaths = await globby(imageDirectories, { extensions: ['svg', 'webp', 'jpg', 'png', 'gif', 'bmp', 'jpeg'] }, gitignore: false -}).then((filePaths) => { - const fileNames = filePaths.map(getFileNameWithoutExtension) +}).then((filePaths) => + filePaths + .filter((filePath) => { + const isGenerated = getFileNameWithoutExtension(filePath).startsWith(generatedPrefix) - return filePaths - .filter( - (file) => - !getFileNameWithoutExtension(file).startsWith(generatedPrefix) && - !fileNames.includes(generatedPrefix + getFileNameWithoutExtension(file)) - ) + if (isGenerated) return false + + const fileName = getFileNameWithoutExtension(filePath) + const fileDirectory = filePath.split('/').slice(0, -2).join('/') + '/' + const generatedFilePath = `${fileDirectory}${generatedPrefix}${fileName}.webp` + + const isAlreadyBlurred = filePaths.includes(generatedFilePath) + + return !isAlreadyBlurred + }) .map((filePath) => new URL(filePath, root)) -}) +) for (const filePathUrl of filePaths) { const extension = filePathUrl.pathname.split('.').at(-1) diff --git a/src/routes/api/plugins/+server.js b/src/routes/api/plugins/+server.js index 08e271a..7556ff8 100644 --- a/src/routes/api/plugins/+server.js +++ b/src/routes/api/plugins/+server.js @@ -2,23 +2,16 @@ import { json } from '@sveltejs/kit' import path from 'path' import { parse } from 'smol-toml' import { readFile } from 'node:fs/promises' +import pluginsToml from '../../../content/plugins.toml?raw' -/** Get the plugins of the `content/plugins/` directory */ async function getPlugins() { - const plugins = await readFile( - path.join(import.meta.dirname, '../../../content/plugins.toml'), - 'utf-8' + const plugins = parse(pluginsToml).plugins.sort( + (a, b) => + (b.featured ?? 0) - (a.featured ?? 0) || + (b.weight ?? 0) - (a.weight ?? 0) || + ((b.logo && 1) ?? 0) - ((a.logo && 1) ?? 0) || + ((b.banner && 1) ?? 0) - ((a.banner && 1) ?? 0) ) - .then(parse) - .then(({ plugins }) => - plugins.sort( - (a, b) => - (b.featured ?? 0) - (a.featured ?? 0) || - (b.weight ?? 0) - (a.weight ?? 0) || - ((b.logo && 1) ?? 0) - ((a.logo && 1) ?? 0) || - ((b.banner && 1) ?? 0) - ((a.banner && 1) ?? 0) - ) - ) return plugins }