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-10-29 00:24:39 +08:00
|
|
|
const ICONS_PATH = path.resolve(process.cwd(), 'scripts/assets/quickreference.svg');
|
2022-11-20 03:26:06 +08:00
|
|
|
const ICONS_SEARCH_PATH = path.resolve(process.cwd(), 'scripts/assets/search.svg');
|
|
|
|
|
2022-11-20 03:37:25 +08:00
|
|
|
export function header({ homePath, githubURL = '', isHome } = {}) {
|
2022-10-29 00:24:39 +08:00
|
|
|
const svgNode = getSVGNode(ICONS_PATH);
|
2022-11-20 03:26:06 +08:00
|
|
|
const svgSearchNode = getSVGNode(ICONS_SEARCH_PATH);
|
2022-09-27 23:09:51 +08:00
|
|
|
const data = [
|
2022-11-20 03:26:06 +08:00
|
|
|
{
|
|
|
|
menu: true,
|
|
|
|
href: 'javascript:void(0);',
|
|
|
|
class: ['searchbtn'],
|
|
|
|
id: 'searchbtn',
|
|
|
|
children: [
|
|
|
|
...svgSearchNode,
|
|
|
|
{
|
|
|
|
type: 'element',
|
|
|
|
tagName: 'span',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
type: 'text',
|
|
|
|
value: '搜索',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'element',
|
|
|
|
tagName: 'span',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
type: 'text',
|
|
|
|
value: '⌘',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'text',
|
|
|
|
value: 'K',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
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: githubURL,
|
|
|
|
target: '__blank',
|
|
|
|
label: '编辑',
|
2022-10-29 00:24:39 +08:00
|
|
|
children: [editor],
|
2022-09-27 23:09:51 +08:00
|
|
|
},
|
2022-11-20 03:37:25 +08:00
|
|
|
...darkMode({ homePath, isHome }),
|
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',
|
2022-10-29 00:24:39 +08:00
|
|
|
children: [github],
|
|
|
|
},
|
|
|
|
];
|
2022-09-27 23:09:51 +08:00
|
|
|
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'],
|
|
|
|
},
|
2022-10-29 00:24:39 +08:00
|
|
|
children: [{ type: 'text', value: 'Quick Reference' }],
|
|
|
|
},
|
2022-09-30 17:33:13 +08:00
|
|
|
],
|
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: {},
|
2022-10-29 00:24:39 +08:00
|
|
|
children: label ? [{ type: 'text', value: label }] : [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2022-09-27 23:09:51 +08:00
|
|
|
if (label) {
|
2022-10-29 00:24:39 +08:00
|
|
|
childs.children = [
|
|
|
|
...children,
|
|
|
|
{
|
|
|
|
type: 'element',
|
|
|
|
tagName: 'span',
|
|
|
|
properties: {},
|
|
|
|
children: [{ type: 'text', value: label }],
|
|
|
|
},
|
|
|
|
];
|
2022-09-27 23:09:51 +08:00
|
|
|
} else {
|
|
|
|
childs.children = children;
|
|
|
|
}
|
2022-10-29 00:24:39 +08:00
|
|
|
return childs;
|
2022-09-27 23:09:51 +08:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
],
|
2022-10-29 00:24:39 +08:00
|
|
|
},
|
2022-09-27 23:09:51 +08:00
|
|
|
],
|
|
|
|
};
|
2022-10-29 00:24:39 +08:00
|
|
|
}
|