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'
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
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 }) {
 | 
			
		||||
    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) {
 | 
			
		||||
        case 1:
 | 
			
		||||
        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 {
 | 
			
		||||
    const oDate = (typeof date === 'string') ? new Date(date) : date;
 | 
			
		||||
 | 
			
		||||
@@ -100,6 +115,7 @@ const DateTool = {
 | 
			
		||||
    getFullMonth,
 | 
			
		||||
    isValid,
 | 
			
		||||
    getOrdinalDaySuffix,
 | 
			
		||||
    toLocaleString,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default DateTool;
 | 
			
		||||
 
 | 
			
		||||
@@ -45,7 +45,7 @@ MimeType=text/plain; # $XDG_PATH contains the paths used to fetch icons, extensi
 | 
			
		||||
      menu. 
 | 
			
		||||
    - Sample code for the electron app (assuming you can build linux binaries
 | 
			
		||||
      for the target platform):
 | 
			
		||||
      ```javascript
 | 
			
		||||
    ```javascript
 | 
			
		||||
      // sample code to get started
 | 
			
		||||
      const { app, BrowserWindow } = require('electron');
 | 
			
		||||
      app
 | 
			
		||||
 
 | 
			
		||||
@@ -8,8 +8,11 @@ import remarkGithubAdmonitionsToDirectives from 'remark-github-admonitions-to-di
 | 
			
		||||
 | 
			
		||||
import Layout from '../../components/layout';
 | 
			
		||||
import readMarkdown from '../../lib/read-markdown';
 | 
			
		||||
import { toLocaleString } from '../../lib/date';
 | 
			
		||||
import NotesInfo from '../../public/notes.json';
 | 
			
		||||
 | 
			
		||||
import style from '../../styles/note.module.css';
 | 
			
		||||
 | 
			
		||||
interface Note {
 | 
			
		||||
    title: string,
 | 
			
		||||
    mtime: string,
 | 
			
		||||
@@ -50,6 +53,9 @@ function Markdown({ content }: any) {
 | 
			
		||||
function Note({ note }: any) {
 | 
			
		||||
    return (<>
 | 
			
		||||
        <Layout >
 | 
			
		||||
            <span className={style['last-updated']}>
 | 
			
		||||
                Last updated: {toLocaleString(note.mtime)}
 | 
			
		||||
            </span>
 | 
			
		||||
            <section className='block'>
 | 
			
		||||
                <Markdown content={note.content} />
 | 
			
		||||
            </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