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