Commit 68cb97a

HPCesia <me@hpcesia.com>
2025-01-23 08:18:53
feat: license card
1 parent b740854
Changed files (2)
src
components
pages
src/components/License.astro
@@ -0,0 +1,49 @@
+---
+import { licenseConfig, profileConfig, siteConfig } from '@/config';
+import I18nKey from '@i18n/I18nKey';
+import { i18n } from '@i18n/translation';
+
+interface Props {
+  time: Date;
+  license?: string;
+  licenseUrl?: string;
+}
+
+const { time, license, licenseUrl } = Astro.props;
+
+const infomations = [
+  {
+    key: i18n(I18nKey.publishedAt),
+    value: time.toLocaleDateString(siteConfig.lang.replace('_', '-')),
+  },
+  {
+    key: i18n(I18nKey.author),
+    value: profileConfig.name,
+    link: '/about/',
+  },
+  {
+    key: i18n(I18nKey.license),
+    value: license || licenseConfig.name,
+    link: licenseUrl || licenseConfig.url,
+  },
+];
+---
+
+<div class="theme-card-bg-hl-trans theme-border my-4 flex items-center rounded-xl border-2 p-4">
+  <div class="mx-auto grid grid-cols-2 gap-x-4">
+    {
+      infomations.map((info) => (
+        <Fragment>
+          <span class="mr-4 text-right font-bold">{info.key}</span>
+          {info.link ? (
+            <a href={info.link} class="theme-text-hl-contrast">
+              {info.value}
+            </a>
+          ) : (
+            <span>{info.value}</span>
+          )}
+        </Fragment>
+      ))
+    }
+  </div>
+</div>
src/pages/posts/[article].astro
@@ -1,5 +1,6 @@
 ---
 import '@/styles/article.scss';
+import License from '@components/License.astro';
 import ProfileCard from '@components/widgets/ProfileCard.astro';
 import TOC from '@components/widgets/TOC.astro';
 import GridLayout from '@layouts/GridLayout.astro';
@@ -22,6 +23,7 @@ const { Content, headings } = await render(article);
     <article>
       <Content />
     </article>
+    <License time={article.data.published} />
   </div>
   <Fragment slot="aside-fixed">
     <ProfileCard />