Fix type and other minor issues

This commit is contained in:
Paul W. 2024-10-10 02:50:21 -04:00
parent 41d67d7a98
commit 4f25a3bc3d
Signed by: lambdapaul
GPG Key ID: 0D207B4EBC14B1BD
3 changed files with 45 additions and 19 deletions

View File

@ -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 {

View File

@ -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];

View File

@ -10,6 +10,19 @@ function traverseMap(head: Site, cwd = '', depth = 0) {
for (const [slug, info] of Object.entries(head.subpages)) {
if (slug === 'sitemap')
continue;
if (slug.startsWith('http://')) {
elements.push(<>
<dt>{info.title}</dt>
<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(<>
@ -18,6 +31,7 @@ function traverseMap(head: Site, cwd = '', depth = 0) {
{children}
</>);
}
}
return elements;
}