Commit 6d21197

HPCesia <me@hpcesia.com>
2025-02-10 07:32:33
fix: locale date format
1 parent 3e9c1f0
Changed files (4)
src/components/misc/License.astro
@@ -5,16 +5,17 @@ import { i18n } from '@i18n/translation';
 
 interface Props {
   time: Date;
+  lang?: string;
   license?: string;
   licenseUrl?: string;
 }
 
-const { time, license, licenseUrl } = Astro.props;
+const { time, license, licenseUrl, lang } = Astro.props;
 
 const infomations = [
   {
     key: i18n(I18nKey.publishedAt),
-    value: time.toLocaleDateString(siteConfig.lang.replace('_', '-')),
+    value: time.toLocaleDateString(lang || siteConfig.lang.replace('_', '-')),
     time: time,
   },
   {
src/components/misc/PostInfo.astro
@@ -1,5 +1,5 @@
 ---
-import { articleConfig } from '@/config';
+import { articleConfig, siteConfig } from '@/config';
 import MetaIcon from '@components/widgets/MetaIcon.astro';
 import I18nKey from '@i18n/I18nKey';
 import { i18n } from '@i18n/translation';
@@ -12,6 +12,7 @@ interface Props {
   tags: string[];
   wordsCount: number;
   readingTime: number;
+  lang?: string;
   class?: string;
 }
 
@@ -22,13 +23,14 @@ const {
   tags,
   wordsCount: wordCount,
   readingTime,
+  lang,
   class: className,
 } = Astro.props;
 
 const metas: ({ icon: string; text: string; link?: string; time?: Date } | undefined)[] = [
   {
     icon: 'material-symbols:calendar-clock-outline-rounded',
-    text: publishedAt.toLocaleDateString(),
+    text: publishedAt.toLocaleDateString(lang || siteConfig.lang.replace('_', '-')),
     time: publishedAt,
   },
   articleConfig.wordCount
src/components/widgets/PostCard.astro
@@ -1,4 +1,5 @@
 ---
+import { siteConfig } from '@/config';
 import { getCategoryUrl, getTagUrl } from '@utils/content-utils';
 import MetaIcon from './MetaIcon.astro';
 import PostCardCover from './PostCardCover.astro';
@@ -24,12 +25,12 @@ const hasCover = cover !== '' && cover !== undefined && cover !== null;
 const metas: ({ icon: string; text: string; link?: string; time?: Date } | undefined)[] = [
   {
     icon: 'material-symbols:calendar-clock-outline-rounded',
-    text: published.toLocaleDateString(),
+    text: published.toLocaleDateString(siteConfig.lang.replace('_', '-')),
     time: published,
   },
   updated && {
     icon: 'material-symbols:edit-calendar-outline-rounded',
-    text: updated.toLocaleDateString(),
+    text: updated.toLocaleDateString(siteConfig.lang.replace('_', '-')),
   },
   category
     ? {
src/pages/posts/[article].astro
@@ -32,6 +32,7 @@ const description = article.data.description || remarkPluginFrontmatter.excerpt;
       tags={article.data.tags}
       wordsCount={remarkPluginFrontmatter.words}
       readingTime={remarkPluginFrontmatter.minutes}
+      lang={article.data.lang}
       class="mx-2 mt-4"
     />
   </Fragment>
@@ -39,7 +40,7 @@ const description = article.data.description || remarkPluginFrontmatter.excerpt;
     <Markdown>
       <Content />
     </Markdown>
-    <License time={article.data.published} />
+    <License time={article.data.published} lang={article.data.lang} />
     {article.data.comment && commentConfig.enable && <Comment />}
   </div>
   <Fragment slot="aside-fixed">