diff --git a/lib/date.ts b/lib/date.ts index 6e19e6b..3400c1d 100644 --- a/lib/date.ts +++ b/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 { diff --git a/pages/notes/[note].tsx b/pages/notes/[note].tsx index c67065c..6baa914 100644 --- a/pages/notes/[note].tsx +++ b/pages/notes/[note].tsx @@ -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} } -function Note({ note }: any) { +function Note({ note }: { note: Note } ) { return (<> @@ -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]; diff --git a/pages/sitemap.tsx b/pages/sitemap.tsx index a5b4829..795d225 100644 --- a/pages/sitemap.tsx +++ b/pages/sitemap.tsx @@ -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 = (<>
{traverseMap(info, path, depth + 1)}
); - elements.push(<> + if (slug.startsWith('http://')) { + elements.push(<>
{info.title}
-
paulw.xyz{path}
- {children} - ); +
{slug.substring(7)}
+ ); + } + else if (slug.startsWith('https://')) { + elements.push(<> +
{info.title}
+
{slug.substring(8)}
+ ); + } + else { + const path = `${cwd}/${slug}`; + const children = (<>
{traverseMap(info, path, depth + 1)}
); + elements.push(<> +
{info.title}
+
paulw.xyz{path}
+ {children} + ); + } } return elements; }