Add last updated to note pages
This commit is contained in:
		
							
								
								
									
										18
									
								
								lib/date.ts
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								lib/date.ts
									
									
									
									
									
								
							@@ -14,6 +14,16 @@ const months = [
 | 
				
			|||||||
    'December'
 | 
					    'December'
 | 
				
			||||||
];
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function toHumanReadableDate(date: Date | string, disable?: { year?: boolean, month?: boolean, day?: boolean }) {
 | 
					function toHumanReadableDate(date: Date | string, disable?: { year?: boolean, month?: boolean, day?: boolean }) {
 | 
				
			||||||
    const oDate = (typeof date === 'string') ? new Date(date) : date;
 | 
					    const oDate = (typeof date === 'string') ? new Date(date) : date;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -29,7 +39,7 @@ function toHumanReadableDate(date: Date | string, disable?: { year?: boolean, mo
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function getOrdinalDaySuffix(day: number) {
 | 
					export function getOrdinalDaySuffix(day: number): string {
 | 
				
			||||||
    switch (day) {
 | 
					    switch (day) {
 | 
				
			||||||
        case 1:
 | 
					        case 1:
 | 
				
			||||||
        case 21:
 | 
					        case 21:
 | 
				
			||||||
@@ -46,6 +56,11 @@ export function getOrdinalDaySuffix(day: number) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function toLocaleString(pdate: Date | string): string {
 | 
				
			||||||
 | 
					    const date = (typeof pDate === 'string') ? new Date(pdate) : pdate;
 | 
				
			||||||
 | 
					    return `${toHumanReadableDate(date)}, ${get12HourTime(date)}`;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function toRelativeDate(date: Date | string): string {
 | 
					export function toRelativeDate(date: Date | string): string {
 | 
				
			||||||
    const oDate = (typeof date === 'string') ? new Date(date) : date;
 | 
					    const oDate = (typeof date === 'string') ? new Date(date) : date;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -100,6 +115,7 @@ const DateTool = {
 | 
				
			|||||||
    getFullMonth,
 | 
					    getFullMonth,
 | 
				
			||||||
    isValid,
 | 
					    isValid,
 | 
				
			||||||
    getOrdinalDaySuffix,
 | 
					    getOrdinalDaySuffix,
 | 
				
			||||||
 | 
					    toLocaleString,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default DateTool;
 | 
					export default DateTool;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -45,7 +45,7 @@ MimeType=text/plain; # $XDG_PATH contains the paths used to fetch icons, extensi
 | 
				
			|||||||
      menu. 
 | 
					      menu. 
 | 
				
			||||||
    - Sample code for the electron app (assuming you can build linux binaries
 | 
					    - Sample code for the electron app (assuming you can build linux binaries
 | 
				
			||||||
      for the target platform):
 | 
					      for the target platform):
 | 
				
			||||||
      ```javascript
 | 
					    ```javascript
 | 
				
			||||||
      // sample code to get started
 | 
					      // sample code to get started
 | 
				
			||||||
      const { app, BrowserWindow } = require('electron');
 | 
					      const { app, BrowserWindow } = require('electron');
 | 
				
			||||||
      app
 | 
					      app
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,8 +8,11 @@ import remarkGithubAdmonitionsToDirectives from 'remark-github-admonitions-to-di
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import Layout from '../../components/layout';
 | 
					import Layout from '../../components/layout';
 | 
				
			||||||
import readMarkdown from '../../lib/read-markdown';
 | 
					import readMarkdown from '../../lib/read-markdown';
 | 
				
			||||||
 | 
					import { toLocaleString } from '../../lib/date';
 | 
				
			||||||
import NotesInfo from '../../public/notes.json';
 | 
					import NotesInfo from '../../public/notes.json';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import style from '../../styles/note.module.css';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface Note {
 | 
					interface Note {
 | 
				
			||||||
    title: string,
 | 
					    title: string,
 | 
				
			||||||
    mtime: string,
 | 
					    mtime: string,
 | 
				
			||||||
@@ -50,6 +53,9 @@ function Markdown({ content }: any) {
 | 
				
			|||||||
function Note({ note }: any) {
 | 
					function Note({ note }: any) {
 | 
				
			||||||
    return (<>
 | 
					    return (<>
 | 
				
			||||||
        <Layout >
 | 
					        <Layout >
 | 
				
			||||||
 | 
					            <span className={style['last-updated']}>
 | 
				
			||||||
 | 
					                Last updated: {toLocaleString(note.mtime)}
 | 
				
			||||||
 | 
					            </span>
 | 
				
			||||||
            <section className='block'>
 | 
					            <section className='block'>
 | 
				
			||||||
                <Markdown content={note.content} />
 | 
					                <Markdown content={note.content} />
 | 
				
			||||||
            </section>
 | 
					            </section>
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										7
									
								
								styles/note.module.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								styles/note.module.css
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					.last-updated {
 | 
				
			||||||
 | 
					    text-align: right;
 | 
				
			||||||
 | 
					    display: block;
 | 
				
			||||||
 | 
					    font-style: italic;
 | 
				
			||||||
 | 
					    font-size: 1rem;
 | 
				
			||||||
 | 
					    margin: 0.5rem 0.75rem;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user