From a95e20e0b41999e0e7bf260f435ae86c4b2c067e Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Thu, 9 Mar 2023 20:23:15 -0800 Subject: [PATCH] Insert post timestamp on article page --- script.js | 8 ++++++++ 1 file changed, 8 insertions(+) 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: '', -- 2.47.3