website: update dark theme issue.

This commit is contained in:
jaywcjlove
2022-11-20 03:37:25 +08:00
parent 98eae38934
commit 79dcdc7379
4 changed files with 24 additions and 16 deletions

View File

@ -3,11 +3,13 @@ import { getSVGNode } from './getSVGNode.mjs';
const ICONS_PATH = path.resolve(process.cwd(), 'scripts/assets');
export function darkMode() {
export function darkMode({ homePath = '', isHome } = {}) {
const relativePath = homePath.replace(/\/?index.html$/, isHome ? '' : '/');
const iconSunPath = path.resolve(ICONS_PATH, `sun.svg`);
const iconMoonPath = path.resolve(ICONS_PATH, `moon.svg`);
const sunNode = getSVGNode(iconSunPath);
const moonNode = getSVGNode(iconMoonPath);
const darkJSUrl = relativePath + 'js/dark.js';
return [
{
type: 'element',
@ -18,5 +20,12 @@ export function darkMode() {
},
children: [...sunNode, ...moonNode],
},
{
type: 'element',
tagName: 'script',
properties: {
src: darkJSUrl,
},
},
];
}