From c2e35c445f1599939c067f2e8f7cccca198aa2ea Mon Sep 17 00:00:00 2001 From: Pierre Borgmann Date: Sun, 28 May 2023 01:53:32 +0200 Subject: [PATCH] #52: serve Quantico font --- package.json | 1 + src/server/dependencies.js | 18 +++++++++++++++++- src/server/helpers/send-static-file.js | 8 -------- yarn.lock | 5 +++++ 4 files changed, 23 insertions(+), 9 deletions(-) delete mode 100644 src/server/helpers/send-static-file.js diff --git a/package.json b/package.json index 2a04c40..fbc086b 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "type": "module", "main": "src/server/index.js", "dependencies": { + "@fontsource/quantico": "^5.0.1", "koa": "^2.14.1", "koa-bodyparser": "^4.3.0", "koa-compress": "^5.1.1", diff --git a/src/server/dependencies.js b/src/server/dependencies.js index 047f3de..fecd28b 100644 --- a/src/server/dependencies.js +++ b/src/server/dependencies.js @@ -1,7 +1,23 @@ -import { sendStaticFile } from './helpers/send-static-file.js' +import send from 'koa-send' export const registerDependencyRoutes = (router) => { router.get('/dependencies/vue.js', sendStaticFile('node_modules/vue/dist/vue.esm-browser.js')) router.get('/dependencies/vue3-sfc-loader.js', sendStaticFile('node_modules/vue3-sfc-loader/dist/vue3-sfc-loader.esm.js')) + router.get('/dependencies/normalize.css', sendStaticFile('node_modules/normalize.css/normalize.css')) + + serveFontsourceFont(router, 'quantico') +} + +// NB! Do _not_ use this with user-supplied values for localFile! +export const sendStaticFile = (localFile) => async (context) => { + await send(context, localFile) +} + +export const serveFontsourceFont = (router, fontName) => { + const prefix = `/dependencies/${fontName}/` + + router.get(`${prefix}:path*`, async (context) => { + await send(context, context.path.substring(prefix.length), { root: `node_modules/@fontsource/${fontName}` }) + }) } diff --git a/src/server/helpers/send-static-file.js b/src/server/helpers/send-static-file.js deleted file mode 100644 index 97c5924..0000000 --- a/src/server/helpers/send-static-file.js +++ /dev/null @@ -1,8 +0,0 @@ -import send from 'koa-send' - -import { rootDirectory } from './paths.js' - -// NB! Do _not_ use this with user-supplied values for localFile! -export const sendStaticFile = (localFile) => async (context) => { - await send(context, localFile, { root: rootDirectory }) -} diff --git a/yarn.lock b/yarn.lock index 8d7db6d..d875f99 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7,6 +7,11 @@ resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.21.2.tgz#dacafadfc6d7654c3051a66d6fe55b6cb2f2a0b3" integrity sha512-URpaIJQwEkEC2T9Kn+Ai6Xe/02iNaVCuT/PtoRz3GPVJVDpPd7mLo+VddTbhCRU9TXqW5mSrQfXZyi8kDKOVpQ== +"@fontsource/quantico@^5.0.1": + version "5.0.1" + resolved "https://registry.yarnpkg.com/@fontsource/quantico/-/quantico-5.0.1.tgz#a83935a353e6d32eb3236c7df193456e9a9beffa" + integrity sha512-Nd2hsZysPSZ0ffMUg0aeSzj9q0P/K/2tHcjqg6IdOdtVFXiMxNEq5qpwUtli1OiTvOu9EKcknQ2JzVkHDOMwtA== + "@vue/compiler-core@3.2.47": version "3.2.47" resolved "https://registry.yarnpkg.com/@vue/compiler-core/-/compiler-core-3.2.47.tgz#3e07c684d74897ac9aa5922c520741f3029267f8"