Commit 3e9c1f0

HPCesia <me@hpcesia.com>
2025-02-10 05:35:21
feat: wrap time with time tag
1 parent 6847e43
Changed files (4)
src/components/misc/License.astro
@@ -15,6 +15,7 @@ const infomations = [
   {
     key: i18n(I18nKey.publishedAt),
     value: time.toLocaleDateString(siteConfig.lang.replace('_', '-')),
+    time: time,
   },
   {
     key: i18n(I18nKey.author),
@@ -35,13 +36,20 @@ const infomations = [
       infomations.map((info) => (
         <Fragment>
           <span class="mr-4 text-right font-bold">{info.key}</span>
-          {info.link ? (
-            <a href={info.link} class="text-primary hover:underline">
-              {info.value}
-            </a>
-          ) : (
-            <span>{info.value}</span>
-          )}
+          {(() => {
+            const text = info.time ? (
+              <time datetime={info.time?.toISOString()}>{info.value}</time>
+            ) : (
+              <span>{info.value}</span>
+            );
+            return info.link ? (
+              <a href={info.link} title={info.value} class="text-primary hover:underline">
+                {text}
+              </a>
+            ) : (
+              text
+            );
+          })()}
         </Fragment>
       ))
     }
src/components/misc/PostInfo.astro
@@ -25,10 +25,11 @@ const {
   class: className,
 } = Astro.props;
 
-const metas: ({ icon: string; text: string; link?: string } | undefined)[] = [
+const metas: ({ icon: string; text: string; link?: string; time?: Date } | undefined)[] = [
   {
     icon: 'material-symbols:calendar-clock-outline-rounded',
     text: publishedAt.toLocaleDateString(),
+    time: publishedAt,
   },
   articleConfig.wordCount
     ? {
@@ -68,13 +69,20 @@ const metas: ({ icon: string; text: string; link?: string } | undefined)[] = [
           meta && (
             <div class="text-base-content/60 flex items-center text-sm">
               <MetaIcon name={meta.icon} />
-              {meta.link ? (
-                <a href={meta.link} title={meta.text}>
-                  {meta.text}
-                </a>
-              ) : (
-                <span>{meta.text}</span>
-              )}
+              {(() => {
+                const text = meta.time ? (
+                  <time datetime={meta.time?.toISOString()}>{meta.text}</time>
+                ) : (
+                  <span>{meta.text}</span>
+                );
+                return meta.link ? (
+                  <a href={meta.link} title={meta.text}>
+                    {text}
+                  </a>
+                ) : (
+                  text
+                );
+              })()}
             </div>
           )
         );
src/components/widgets/PostCard.astro
@@ -21,10 +21,11 @@ const className = Astro.props.class;
 
 const hasCover = cover !== '' && cover !== undefined && cover !== null;
 
-const metas: ({ icon: string; text: string; link?: string } | undefined)[] = [
+const metas: ({ icon: string; text: string; link?: string; time?: Date } | undefined)[] = [
   {
     icon: 'material-symbols:calendar-clock-outline-rounded',
     text: published.toLocaleDateString(),
+    time: published,
   },
   updated && {
     icon: 'material-symbols:edit-calendar-outline-rounded',
@@ -62,13 +63,20 @@ const metas: ({ icon: string; text: string; link?: string } | undefined)[] = [
             meta && (
               <div class="flex items-center gap-1">
                 <MetaIcon name={meta.icon} />
-                {meta.link ? (
-                  <a href={meta.link} class="meta-text" title={meta.text}>
-                    {meta.text}
-                  </a>
-                ) : (
-                  <span class="meta-text">{meta.text}</span>
-                )}
+                {(() => {
+                  const text = meta.time ? (
+                    <time datetime={meta.time?.toISOString()}>{meta.text}</time>
+                  ) : (
+                    <span>{meta.text}</span>
+                  );
+                  return meta.link ? (
+                    <a href={meta.link} title={meta.text}>
+                      {text}
+                    </a>
+                  ) : (
+                    text
+                  );
+                })()}
               </div>
             )
           );
src/pages/archives/[...time].astro
@@ -156,9 +156,9 @@ const postCount = await getPostsCount();
                       ))}
                     </div>
                   </div>
-                  <span class="text-base-content/60">
+                  <time datetime={data.published.toISOString()} class="text-base-content/60">
                     {data.published.toLocaleDateString(siteConfig.lang)}
-                  </span>
+                  </time>
                 </li>
               ))}
             </ul>