]> git.ardis.lu - ardislu.dev/commitdiff
Show article updated date if applicable
authorArdis Lu <ardisglu@gmail.com>
Tue, 28 Feb 2023 04:55:42 +0000 (20:55 -0800)
committerArdis Lu <ardisglu@gmail.com>
Tue, 28 Feb 2023 04:55:42 +0000 (20:55 -0800)
script.js

index 27b607c55a70b82c77f8517fe6a34e6bc1365cfa..f2c59fa6733d6d1daaca1736a02c59b38de4a993 100644 (file)
--- a/script.js
+++ b/script.js
@@ -45,8 +45,8 @@ async function fetchPostMetadata() {
       description: row[1],
       id: row[2],
       linkText: row[3],
-      createdDate: new Date(row[5]).toLocaleDateString(),
-      updatedDate: new Date(row[6]).toLocaleDateString(),
+      createdDate: new Date(row[5]),
+      updatedDate: new Date(row[6]),
       tags: row[7].split(',').map(s => s.trim())
     });
   }
@@ -60,10 +60,13 @@ function buildHomeComponent(metadata) {
   home.classList.add('card-container');
 
   for (const [path, post] of metadata) {
+    const subtitle = post.createdDate.toISOString() === post.updatedDate.toISOString() ?
+      `<time datetime="${post.createdDate.toISOString()}">${post.createdDate.toLocaleDateString()}</time>` :
+      `<time datetime="${post.createdDate.toISOString()}">${post.createdDate.toLocaleDateString()}</time> — Updated <time datetime="${post.updatedDate.toISOString()}">${post.updatedDate.toLocaleDateString()}</time>`;
     home.insertAdjacentHTML('beforeend',
       `<article class="card">
         <h2>${post.title}</h2>
-        <p class="subtitle">${post.createdDate}</p>
+        <p class="subtitle">${subtitle}</p>
         <ul class="tags">${post.tags.map(t => `<li class="tag"><a href="${location.origin}/search?q=${t}">${t}</a></li>`).join('')}</ul>
         <p>${post.description}</p>
         <p><a href="${path}">${post.linkText}</a></p>
This page took 0.043744 seconds and 4 git commands to generate.