From: Ardis Lu Date: Fri, 10 Mar 2023 04:23:15 +0000 (-0800) Subject: Insert post timestamp on article page X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=a95e20e0b41999e0e7bf260f435ae86c4b2c067e;p=ardislu.dev Insert post timestamp on article page --- diff --git a/script.js b/script.js index 828cdda..c5c6a48 100644 --- a/script.js +++ b/script.js @@ -95,6 +95,14 @@ async function fetchPostContent(id) { const url = `${proxyUrl}?https://docs.googleapis.com/v1/documents/${id}`; const googleDoc = await fetch(url).then(r => r.json()); + // Insert article creation date and last updated date immediately after title (hardcoded index of 2) + const post = metadata.get(location.pathname); + const postTimestamp = post.createdDate.toISOString() === post.updatedDate.toISOString() ? + `` : + ` — Updated `; + const subtitle = `

${postTimestamp}

\n\n`; // Trailing newlines are required to prevent marked from interpreting the next line as HTML + googleDoc.body.content.splice(2, 0, { paragraph: { elements: [{ textRun: { content: subtitle } }], paragraphStyle: { namedStyleType: 'SUBTITLE' } } }); + const mapping = { TITLE: '# ', SUBTITLE: '',