feat: implement ui i18n support
This commit is contained in:
parent
457fb93718
commit
698c411c71
13 changed files with 162 additions and 54 deletions
|
@ -10,6 +10,11 @@ import { ExtractFirstImage } from '../../plugins/extract-images';
|
|||
import AuthorInfo from "../../components/helper/authors/Info.astro";
|
||||
import TableOfContents from "../../components/TableOfContents.astro";
|
||||
import "katex/dist/katex.css"
|
||||
import { getLangFromUrl, useTranslations, useTranslatedPath } from '../../i18n/utils';
|
||||
|
||||
const lang = getLangFromUrl(Astro.url);
|
||||
const t = useTranslations(lang);
|
||||
const translatePath = useTranslatedPath(lang);
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const blogEntries = await getCollection('posts');
|
||||
|
@ -29,6 +34,9 @@ const author = Array.isArray(entry.data.author) ? entry.data.author : (entry.dat
|
|||
const wordcount = remarkPluginFrontmatter.wordcount;
|
||||
const lastUpdated = remarkPluginFrontmatter.lastModified;
|
||||
|
||||
const pubDate = new Date(entry.data.pubDate).toISOString().split('T')[0]
|
||||
const lastUpdatedDate = new Date(lastUpdated).toISOString().split('T')[0]
|
||||
|
||||
// Get author data
|
||||
const authorData = await Promise.all((author).map((singleAuthor) => getEntry(singleAuthor).then(authorEntry => authorEntry?.data)))
|
||||
const authorInfo = authorData.includes(undefined) ? [{data: siteConfig.defaultAuthor}] : authorData;
|
||||
|
@ -56,10 +64,10 @@ const cover = customFeaturedImage || matchedImage_src?.src || firstImageURL || `
|
|||
<article>
|
||||
<h1 class="title">{entry.data.title}</h1>
|
||||
{authorInfo.map((a: any) => <AuthorInfo data={a} />)}
|
||||
<span class="date">{new Date(entry.data.pubDate).toISOString().split('T')[0]}</span>
|
||||
<span class="date">(Updated on {new Date(lastUpdated).toISOString().split('T')[0]})</span>
|
||||
<span class="date">{pubDate}</span>
|
||||
{pubDate === lastUpdatedDate && <span class="date">({t('article.last_update')} {lastUpdatedDate})</span>}
|
||||
<span>|</span>
|
||||
<span class="wordcount">{wordcount.words} words</span>
|
||||
<span class="wordcount">{wordcount.words} {t('article.word_count')}</span>
|
||||
{ (cover && cover !== firstImageURL && cover !== `/blog/${slug}/featured.png`) && <Image class="cover" width=720 height=480 src={cover} alt={`cover of ${entry.data.title}`} /> }
|
||||
{headings.length !== 0 && <TableOfContents headings={headings} />}
|
||||
{entry.data.summary && <p class="summary">{entry.data.summary}</p> }
|
||||
|
@ -70,8 +78,8 @@ const cover = customFeaturedImage || matchedImage_src?.src || firstImageURL || `
|
|||
<div class="extra-post" style="margin-top: 2rem; border-top: 1px solid var(--border-color); padding-top: 1rem;">
|
||||
<ReplyViaEmail title={entry.data.title} email={authorInfo[0].email} />
|
||||
<br>
|
||||
<a href="/blog">← Back to posts</a>
|
||||
{!noscript && <h2>Comments</h2> <Comments />}
|
||||
<a href="/blog">← {t('article.back_to_posts')}</a>
|
||||
{!noscript && <h2>{t('article.comments')}</h2> <Comments />}
|
||||
{!noscript &&
|
||||
<script>
|
||||
import "katex/dist/contrib/copy-tex.js"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue