mirror of
https://github.com/sergeyyarkov/yarkov.tech.git
synced 2026-10-11 10:29:21 +03:00
46 lines
1.3 KiB
Plaintext
46 lines
1.3 KiB
Plaintext
---
|
|
import { CollectionEntry, getCollection } from "astro:content";
|
|
import ArticleLayout from "@root/layouts/article.astro";
|
|
import { createRelativeArticleUrl, removeLanguageCodeFromPath } from "@root/utils";
|
|
import { getLanguageFromURL, useTranslation } from "@i18n/utils";
|
|
|
|
/**
|
|
* Generate articles pages from `blog` collection.
|
|
* The final url will be `http://website.com/blog/2023-01-01/my-article` with default language
|
|
* and `http://website.com/{language-code}/blog/2023-01-01/my-article` with other languages.
|
|
*/
|
|
export async function getStaticPaths() {
|
|
const collection = await getCollection("blog", (e) => !e.data.draft);
|
|
return collection.map((article) => {
|
|
const {
|
|
id,
|
|
data: { title, pubDate },
|
|
} = article;
|
|
const url = createRelativeArticleUrl({ id, title, pubDate });
|
|
return {
|
|
params: { blog: url.slice(1) },
|
|
props: {
|
|
article,
|
|
availableOnLangs: collection.filter((e) =>
|
|
e.id.includes(removeLanguageCodeFromPath(article.id))
|
|
),
|
|
},
|
|
};
|
|
});
|
|
}
|
|
|
|
type Props = { article: CollectionEntry<"blog">; availableOnLangs: CollectionEntry<"blog">[] };
|
|
|
|
const { Content, headings } = await Astro.props.article.render();
|
|
const { article, availableOnLangs } = Astro.props;
|
|
---
|
|
|
|
<ArticleLayout
|
|
lang={article.id.split("/")[0]}
|
|
article={article}
|
|
headings={headings}
|
|
availableOnLangs={availableOnLangs}
|
|
>
|
|
<Content />
|
|
</ArticleLayout>
|