Fix type and other minor issues
This commit is contained in:
parent
41d67d7a98
commit
4f25a3bc3d
33
lib/date.ts
33
lib/date.ts
@ -16,11 +16,21 @@ const months = [
|
||||
|
||||
function get12HourTime(pdate: Date | string): string {
|
||||
const date = (typeof pdate === 'string') ? new Date(pdate) : pdate;
|
||||
if (date.getHours() > 12)
|
||||
return `${date.getHours() - 12}:${date.getMinutes()} PM`;
|
||||
else if (date.getHours() === 0)
|
||||
return `12:${date.getMinutes()} AM`;
|
||||
return `${date.getHours()}:${date.getMinutes()} AM`;
|
||||
let hours = date.getHours();
|
||||
const minutes = date.getMinutes();
|
||||
let meridiem = 'A.M.';
|
||||
|
||||
let strhours = ''
|
||||
|
||||
if (hours > 12) {
|
||||
hours -= 12;
|
||||
meridiem = 'P.M.';
|
||||
}
|
||||
|
||||
if (hours === 0)
|
||||
hours = 12;
|
||||
|
||||
return `${hours}:${minutes < 10 ? '0' : ''}${minutes} ${meridiem}`;
|
||||
|
||||
}
|
||||
|
||||
@ -30,10 +40,11 @@ function toHumanReadableDate(date: Date | string, disable?: { year?: boolean, mo
|
||||
const year = oDate.getFullYear();
|
||||
const month = months[oDate.getMonth()];
|
||||
const day = oDate.getDate();
|
||||
|
||||
let out = !disable?.day ? `${day}${getOrdinalDaySuffix(day)}` : '';
|
||||
out = !disable?.month ? `${out} ${month}` : out;
|
||||
out = !disable?.year ? `${out} ${year}` : out;
|
||||
const suffix = getOrdinalDaySuffix(day)
|
||||
let out = '';
|
||||
out = !disable?.month ? `${month}` : '';
|
||||
out = !disable?.day ? `${out} ${day}${suffix}` : out;
|
||||
out = !disable?.year ? `${out}, ${year}` : out;
|
||||
|
||||
return out;
|
||||
}
|
||||
@ -57,8 +68,8 @@ export function getOrdinalDaySuffix(day: number): string {
|
||||
}
|
||||
|
||||
export function toLocaleString(pdate: Date | string): string {
|
||||
const date = (typeof pDate === 'string') ? new Date(pdate) : pdate;
|
||||
return `${toHumanReadableDate(date)}, ${get12HourTime(date)}`;
|
||||
const date = (typeof pdate === 'string') ? new Date(pdate) : pdate;
|
||||
return `${toHumanReadableDate(date)} at ${get12HourTime(date)}`;
|
||||
}
|
||||
|
||||
export function toRelativeDate(date: Date | string): string {
|
||||
|
@ -16,6 +16,7 @@ import style from '../../styles/note.module.css';
|
||||
interface Note {
|
||||
title: string,
|
||||
mtime: string,
|
||||
content?: string,
|
||||
}
|
||||
|
||||
interface Notes {
|
||||
@ -50,7 +51,7 @@ function Markdown({ content }: any) {
|
||||
>{content}</ReactMarkdown>
|
||||
}
|
||||
|
||||
function Note({ note }: any) {
|
||||
function Note({ note }: { note: Note } ) {
|
||||
return (<>
|
||||
<Layout >
|
||||
<span className={style['last-updated']}>
|
||||
@ -64,7 +65,7 @@ function Note({ note }: any) {
|
||||
);
|
||||
}
|
||||
|
||||
export async function getStaticProps({ params }: any) {
|
||||
export async function getStaticProps({ params }: { params: { note: string } }) {
|
||||
const note: string = params.note;
|
||||
const notesInfo: Notes = NotesInfo;
|
||||
const noteInfo: Note = notesInfo[note];
|
||||
|
@ -10,13 +10,27 @@ function traverseMap(head: Site, cwd = '', depth = 0) {
|
||||
for (const [slug, info] of Object.entries(head.subpages)) {
|
||||
if (slug === 'sitemap')
|
||||
continue;
|
||||
const path = `${cwd}/${slug}`;
|
||||
const children = (<><dl style={{marginLeft: '3rem'}}> {traverseMap(info, path, depth + 1)}</dl></>);
|
||||
elements.push(<>
|
||||
if (slug.startsWith('http://')) {
|
||||
elements.push(<>
|
||||
<dt>{info.title}</dt>
|
||||
<dd><Link href={path}>paulw.xyz{path}</Link></dd>
|
||||
{children}
|
||||
</>);
|
||||
<dd><Link href={slug}>{slug.substring(7)}</Link></dd>
|
||||
</>);
|
||||
}
|
||||
else if (slug.startsWith('https://')) {
|
||||
elements.push(<>
|
||||
<dt>{info.title}</dt>
|
||||
<dd><Link href={slug}>{slug.substring(8)}</Link></dd>
|
||||
</>);
|
||||
}
|
||||
else {
|
||||
const path = `${cwd}/${slug}`;
|
||||
const children = (<><dl style={{marginLeft: '3rem'}}> {traverseMap(info, path, depth + 1)}</dl></>);
|
||||
elements.push(<>
|
||||
<dt>{info.title}</dt>
|
||||
<dd><Link href={path}>paulw.xyz{path}</Link></dd>
|
||||
{children}
|
||||
</>);
|
||||
}
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user