Bump script ver and refactor md metadata gen
Signed-off-by: Paul W. <lambdapaul@protonmail.com>
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
import style from '../styles/title.module.css';
|
||||
|
||||
type propsObj = {
|
||||
name: string,
|
||||
title?: string,
|
||||
ancestors?: Array<{ name: string, path: string }>
|
||||
};
|
||||
import SiteMap from '../public/sitemap.json';
|
||||
import Head from 'next/head';
|
||||
import { SiteSubPages } from '../lib/site';
|
||||
|
||||
function createPathElements(ancestors: Array<{ name: string, path: string }>) {
|
||||
let currentPath = '';
|
||||
@@ -21,19 +19,42 @@ function createPathElements(ancestors: Array<{ name: string, path: string }>) {
|
||||
});
|
||||
};
|
||||
|
||||
function Title({ name, title, ancestors }: propsObj) {
|
||||
const pathElements = ancestors && createPathElements(ancestors) || <></>;
|
||||
function Title() {
|
||||
|
||||
const router = useRouter();
|
||||
const pagePath = router.asPath;
|
||||
const splitPath: Array<{ name: string, path: string }> = [];
|
||||
|
||||
let currRoot: SiteSubPages = SiteMap.subpages;
|
||||
let title: string | null = null;
|
||||
if (pagePath !== '/') {
|
||||
const subPaths = pagePath.split('/');
|
||||
for (const p of subPaths.slice(1, subPaths.length)) {
|
||||
splitPath.push({ name: currRoot[p].title, path: p });
|
||||
if (currRoot === undefined
|
||||
|| currRoot[p] === undefined
|
||||
|| currRoot[p].subpages !== undefined)
|
||||
currRoot = currRoot[p].subpages!;
|
||||
}
|
||||
if (splitPath !== undefined && splitPath.length > 0)
|
||||
title = splitPath.pop()!.name;
|
||||
|
||||
}
|
||||
|
||||
const pathElements = splitPath && createPathElements(splitPath) || <></>;
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>{title && `${title} | PaulW.XYZ` || 'PaulW.XYZ'}</title>
|
||||
</Head>
|
||||
<div className={style.container}>
|
||||
<h1 className={style.title}>
|
||||
{title || name}
|
||||
{title || 'PaulW.XYZ'}
|
||||
</h1>
|
||||
</div>
|
||||
<div className={`${style.nav} h1`}>
|
||||
{name
|
||||
? <><Link href='/'>PaulW.XYZ</Link> / {pathElements}{name}</>
|
||||
{title
|
||||
? <><Link href='/'>PaulW.XYZ</Link> / {pathElements}{title}</>
|
||||
: <>PaulW.XYZ /</>}
|
||||
</div>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user