reference/scripts/nodes/header.mjs

103 lines
2.7 KiB
JavaScript
Raw Normal View History

2022-09-30 17:33:13 +08:00
import path from 'path';
import { github, editor } from './logo.mjs';
import { getSVGNode } from '../utils/getSVGNode.mjs';
2022-10-01 02:29:00 +08:00
import { darkMode } from '../utils/darkMode.mjs';
2022-09-27 23:09:51 +08:00
2022-09-30 17:33:13 +08:00
const ICONS_PATH = path.resolve(process.cwd(), 'scripts/assets/quickreference.svg')
2022-09-27 23:09:51 +08:00
export function header({ homePath, githubURL = '' }) {
2022-09-30 17:33:13 +08:00
const svgNode = getSVGNode(ICONS_PATH)
2022-09-27 23:09:51 +08:00
const data = [
{
2022-10-01 02:29:00 +08:00
menu: true,
2022-09-27 23:09:51 +08:00
href: githubURL,
target: '__blank',
label: '编辑',
children: [editor]
},
2022-10-01 02:29:00 +08:00
...darkMode(),
2022-09-27 23:09:51 +08:00
{
2022-10-01 02:29:00 +08:00
menu: true,
2022-09-27 23:09:51 +08:00
href: 'https://github.com/jaywcjlove/reference',
target: '__blank',
children: [github]
}
]
return {
type: 'element',
tagName: 'nav',
properties: {
class: 'header-nav',
},
children: [
{
type: 'element',
tagName: 'div',
properties: {
class: ['max-container'],
},
children: [
{
type: 'element',
tagName: 'a',
properties: {
href: homePath,
class: ['logo'],
},
2022-09-30 17:33:13 +08:00
children: [
...svgNode,
{
type: 'element',
tagName: 'span',
properties: {
class: ['title'],
},
children: [
{ type: 'text', value: 'Quick Reference' }
]
}
],
2022-09-27 23:09:51 +08:00
},
{
type: 'element',
tagName: 'div',
properties: {
class: ['menu'],
},
2022-10-01 02:29:00 +08:00
children: data.map(({ href, label, menu, children = [], ...props }) => {
if (!menu) return { children, ...props };
2022-09-27 23:09:51 +08:00
const childs = {
type: 'element',
tagName: 'a',
properties: { href, class: [], ...props },
children: [
...children,
{
type: 'element',
tagName: 'span',
properties: {},
children: label ? [
{ type: 'text', value: label }
] : []
}
]
}
if (label) {
childs.children = [...children, {
type: 'element',
tagName: 'span',
properties: {},
children: [
{ type: 'text', value: label }
]
}];
} else {
childs.children = children;
}
return childs
}),
},
],
}
],
};
}