From 03a903d9245a1bc00a8d8dbf24763e3045ec897c Mon Sep 17 00:00:00 2001 From: Marc Bernard <59966492+mbtools@users.noreply.github.com> Date: Mon, 15 Jul 2024 17:41:02 -0400 Subject: [PATCH] fix favicon --- config.yaml | 13 +++++---- .../src/middlewares/web/render-web.ts | 10 ++++++- .../src/middlewares/web/utils/renderHTML.ts | 2 ++ packages/middleware/test/config/favicon.ico | Bin 0 -> 15086 bytes .../middleware/test/config/file-logo.yaml | 1 + .../middleware/test/config/http-logo.yaml | 26 ++++++++++++++++++ packages/middleware/test/config/no-logo.yaml | 1 + packages/middleware/test/render.spec.ts | 16 +++++++++++ 8 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 packages/middleware/test/config/favicon.ico create mode 100644 packages/middleware/test/config/http-logo.yaml diff --git a/config.yaml b/config.yaml index bc4744309..85bda98ee 100644 --- a/config.yaml +++ b/config.yaml @@ -23,9 +23,10 @@ plugins: /verdaccio/plugins web: enable: true title: apm - A Package Manager for ABAP - logo: /verdaccio/abappm/apm_banner_gray.png + logo: /verdaccio/abappm/apm_banner.png + logoDark: /verdaccio/abappm/apm_banner_gray.png favicon: /verdaccio/abappm/apm.ico - primary_color: '#a0a0a0' + primaryColor: '#c0c0c0' darkMode: true gravatar: true # by default packages are ordercer ascendant (asc|desc) @@ -38,7 +39,8 @@ web: pkgManagers: - apm showInfo: false - # showSettings: true + showUplinks: false + showSettings: false # In combination with darkMode you can force specific theme # showThemeSwitch: true # showFooter: true @@ -51,13 +53,14 @@ web: # HTML tags injected before ends metaScripts: - '' + - '' # - '' # - '' # HTML tags injected first child at scriptsbodyBefore: - - '
***BETA*** All published packages will be deleted before go-live! ***BETA***
' + - '
***PLAYGROUND*** Packages will be deleted every Sunday night! ***PLAYGROUND***
' # Public path for template manifest scripts (only manifest) - publicPath: https://registry.abappm.com/ + publicPath: https://playground.abappm.com/ auth: htpasswd: diff --git a/packages/middleware/src/middlewares/web/render-web.ts b/packages/middleware/src/middlewares/web/render-web.ts index 3064a42d3..a52c0588e 100644 --- a/packages/middleware/src/middlewares/web/render-web.ts +++ b/packages/middleware/src/middlewares/web/render-web.ts @@ -37,7 +37,15 @@ export function renderWebMiddleware(config, tokenMiddleware, pluginOptions) { // any match within the static is routed to the file system router.get('/-/static/*', function (req, res, next) { const filename = req.params[0]; - const file = `${staticPath}/${filename}`; + let file = `${staticPath}/${filename}`; + if (filename === 'favicon.ico' && config?.web?.favicon) { + file = config?.web?.favicon; + if (isURLhasValidProtocol(file)) { + debug('redirect to favicon %s', file); + req.url = file; + return next(); + } + } debug('render static file %o', file); res.sendFile(file, sendFileCallback(next)); }); diff --git a/packages/middleware/src/middlewares/web/utils/renderHTML.ts b/packages/middleware/src/middlewares/web/utils/renderHTML.ts index 65f1f1077..3d8976285 100644 --- a/packages/middleware/src/middlewares/web/utils/renderHTML.ts +++ b/packages/middleware/src/middlewares/web/utils/renderHTML.ts @@ -65,6 +65,7 @@ export default function renderHTML( const title = config?.web?.title ?? WEB_TITLE; const login = hasLogin(config); const scope = config?.web?.scope ?? ''; + const favicon = resolveLogo(config?.web?.favicon, config?.url_prefix, requestOptions); const logo = resolveLogo(config?.web?.logo, config?.url_prefix, requestOptions); const logoDark = resolveLogo(config?.web?.logoDark, config?.url_prefix, requestOptions); const pkgManagers = config?.web?.pkgManagers ?? ['yarn', 'pnpm', 'npm']; @@ -114,6 +115,7 @@ export default function renderHTML( version, logo, logoDark, + favicon, flags, login, pkgManagers, diff --git a/packages/middleware/test/config/favicon.ico b/packages/middleware/test/config/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..1a4beb4b677465975cb41cf7dc28ea1b3a745038 GIT binary patch literal 15086 zcmdU0TWnNS6ulK9iHXRcCdODJ8b65fLlJ4kmPb**SH;?DLBIzEiJ*dtQK`=lKNLk2 z1T91mHToe4sA#AXYZXiB1H^)KkcWLj3v^~kl*Y1dt+ahj=pdX=V))HE$KGx2+vrXA#G!#KtJlEIqxI%l|s^KcPu1`D36 z&u~3S=WjF`y|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Xrj5vjHgPk8HeYkDT+@&}-XRb2nv3%oyMq6R zrP8L1{kY}4D1$msSD>;or*j>G*-7sUZ@o&7zw(Sd2Cm1%w@04uD}Lm)k@tbTM&hj5 zPKT4Nu*PA1!#)aYYvKHvJ=WGleRg)HZ57**s=3xdU5HiN}AidvDO{z zq-R$~=&9w6w7sg$C@=k4$_GtlETq$aF$U5ZKPZonj0LAY$=qzmZwJSQ%Q;S3nxTtc MoAY1EhcYPpKk8q&4gdfE literal 0 HcmV?d00001 diff --git a/packages/middleware/test/config/file-logo.yaml b/packages/middleware/test/config/file-logo.yaml index 468ad357a..50441befc 100644 --- a/packages/middleware/test/config/file-logo.yaml +++ b/packages/middleware/test/config/file-logo.yaml @@ -15,6 +15,7 @@ web: primary_color: '#ffffff' logo: './test/config/dark-logo.png' logoDark: './test/config/dark-logo.png' + favicon: './test/config/favicon.ico' html_cache: false url_prefix: /prefix diff --git a/packages/middleware/test/config/http-logo.yaml b/packages/middleware/test/config/http-logo.yaml new file mode 100644 index 000000000..6f59e43d7 --- /dev/null +++ b/packages/middleware/test/config/http-logo.yaml @@ -0,0 +1,26 @@ +web: + title: verdaccio web + login: true + scope: '@scope' + pkgManagers: + - pnpm + - yarn + showInfo: true + showSettings: true + showSearch: true + showFooter: true + showThemeSwitch: true + showDownloadTarball: true + showRaw: true + primary_color: '#ffffff' + logo: https://raw.githubusercontent.com/verdaccio/verdaccio/master/assets/svg/logo-small.svg + logoDark: https://raw.githubusercontent.com/verdaccio/verdaccio/master/assets/svg/logo-blackwhite.svg + favicon: https://raw.githubusercontent.com/verdaccio/verdaccio/master/website/static/img/favicon/favicon.ico + html_cache: false + +url_prefix: /prefix + +log: { type: stdout, format: pretty, level: trace } + +flags: + changePassword: true diff --git a/packages/middleware/test/config/no-logo.yaml b/packages/middleware/test/config/no-logo.yaml index 794b8a441..0a7c19308 100644 --- a/packages/middleware/test/config/no-logo.yaml +++ b/packages/middleware/test/config/no-logo.yaml @@ -14,6 +14,7 @@ web: showRaw: true primary_color: '#ffffff' logo: + favicon: html_cache: false url_prefix: /prefix diff --git a/packages/middleware/test/render.spec.ts b/packages/middleware/test/render.spec.ts index 810f3adb8..96916abcd 100644 --- a/packages/middleware/test/render.spec.ts +++ b/packages/middleware/test/render.spec.ts @@ -86,6 +86,21 @@ describe('test web server', () => { expect(__VERDACCIO_BASENAME_UI_OPTIONS.logoDark).toMatch('/prefix/-/static/dark-logo.png'); }); + test('should render favicon as file', async () => { + const { + window: { __VERDACCIO_BASENAME_UI_OPTIONS }, + } = await render('file-logo.yaml'); + expect(__VERDACCIO_BASENAME_UI_OPTIONS.favicon).toMatch('/prefix/-/static/favicon.ico'); + }); + + test('should render logo and favicon as URL', async () => { + const { + window: { __VERDACCIO_BASENAME_UI_OPTIONS }, + } = await render('http-logo.yaml'); + expect(__VERDACCIO_BASENAME_UI_OPTIONS.logo).toMatch(/https:.*logo-small.svg/i); + expect(__VERDACCIO_BASENAME_UI_OPTIONS.favicon).toMatch(/https:.*favicon.ico/i); + }); + test('should not render logo as absolute file is wrong', async () => { const { window: { __VERDACCIO_BASENAME_UI_OPTIONS }, @@ -98,6 +113,7 @@ describe('test web server', () => { window: { __VERDACCIO_BASENAME_UI_OPTIONS }, } = await render('no-logo.yaml'); expect(__VERDACCIO_BASENAME_UI_OPTIONS.logo).toEqual(''); + expect(__VERDACCIO_BASENAME_UI_OPTIONS.favicon).toEqual(''); }); test.todo('should default title');