update to v5 + remove unmaintained i18n lib

This commit is contained in:
nico 2024-12-27 08:55:12 +01:00
parent 59687fbade
commit 99ef7634e3
19 changed files with 38 additions and 103 deletions

View file

@ -1,11 +1,11 @@
---
// import { renderContent } from "astro-i18n";
import { render } from "astro:content";
import MetaDate from "./MetaDate.astro";
import TOC from "./TOC.astro";
const { content } = Astro.props;
const { Content, headings } = await content.render();
// const { html, headings } = await renderContent(Astro, content);
const { Content, headings } = await render(content);
const toc = headings.map((heading) => {
return heading;

View file

@ -1,6 +1,8 @@
import { z, defineCollection } from "astro:content";
import { glob } from 'astro/loaders';
const articles = defineCollection({
loader: glob({ pattern: '**/[^_]*.md', base: "./src/content/articles" }),
schema: z.object({
title: z.string(),
subtitle: z.string(),
@ -20,6 +22,7 @@ const articles = defineCollection({
});
const fragments = defineCollection({
loader: glob({ pattern: '**/[^_]*.md', base: "./src/content/fragments" }),
schema: z.object({
title: z.string(),
subtitle: z.string(),
@ -39,6 +42,7 @@ const fragments = defineCollection({
});
const references = defineCollection({
loader: glob({ pattern: '**/[^_]*.md', base: "./src/content/references" }),
schema: z.object({
title: z.string(),
subtitle: z.string(),

View file

@ -13,7 +13,7 @@ export const getStaticPaths = createStaticPaths(
return data.lang === langCode;
});
return articles.map((article) => ({
params: { slug: article.data.permalink },
params: { id: article.data.permalink },
props: { article },
}));
},

View file

@ -1,15 +0,0 @@
---
import Page from "../../articles/[slug].astro"
import { getStaticPaths as proxyGetStaticPaths } from "../../articles/[slug].astro"
import { extractRouteLangCode } from "astro-i18n"
/* @ts-ignore */
export const getStaticPaths = (props) => proxyGetStaticPaths({
...props,
langCode: extractRouteLangCode(import.meta.url),
})
const { props } = Astro
---
<Page {...props} />

View file

@ -1,6 +0,0 @@
---
import Page from "../../articles/index.astro"
const { props } = Astro
---
<Page {...props} />

View file

@ -1,6 +0,0 @@
---
import Page from "../index.astro"
const { props } = Astro
---
<Page {...props} />

View file

@ -1,6 +0,0 @@
---
import Page from "../plan-du-site.astro"
const { props } = Astro
---
<Page {...props} />

View file

@ -1,15 +0,0 @@
---
import Page from "../../fragments/[slug].astro"
import { getStaticPaths as proxyGetStaticPaths } from "../../fragments/[slug].astro"
import { extractRouteLangCode } from "astro-i18n"
/* @ts-ignore */
export const getStaticPaths = (props) => proxyGetStaticPaths({
...props,
langCode: extractRouteLangCode(import.meta.url),
})
const { props } = Astro
---
<Page {...props} />

View file

@ -1,6 +0,0 @@
---
import Page from "../../fragments/index.astro"
const { props } = Astro
---
<Page {...props} />

View file

@ -1,6 +0,0 @@
---
import Page from "../../veille/index.astro"
const { props } = Astro
---
<Page {...props} />

View file

@ -1,6 +0,0 @@
---
import Page from "../../references/index.astro"
const { props } = Astro
---
<Page {...props} />

View file

@ -13,7 +13,7 @@ export const getStaticPaths = createStaticPaths(
return data.lang === langCode;
});
return snippets.map((snippet) => ({
params: { slug: snippet.data.permalink },
params: { id: snippet.data.permalink },
props: { snippet },
}));
},

View file

@ -1,7 +1,8 @@
---
// init i18n
import { l, t, astroI18n } from "astro-i18n";
astroI18n.init(Astro);
import { getLocale } from "astro-i18n-aut";
const locale = getLocale(Astro.url);
// import stuff
import BaseLayout from "../layouts/BaseLayout.astro";
@ -11,17 +12,19 @@ import ListCards from "../components/ListCards.astro";
const pageTitle = t("accueil");
// get all HP sections
const allSections = await Astro.glob("../data/HP/**/*.md");
const allSections = Object.values(
import.meta.glob("../data/HP/**/*.md", { eager: true })
);
// only keep the right locale version
const localizedSections = allSections.filter((section) => {
return section.frontmatter.lang === astroI18n.langCode;
return section.frontmatter.lang === locale;
});
// New astro content collections
import { getCollection } from "astro:content";
// Only return posts with correct lang in the frontmatter
const localizedArticles = await getCollection("articles", ({ data }) => {
return data.lang === astroI18n.langCode && !data.draft;
return data.lang === locale && !data.draft;
});
// sort articles by descending publication date
const sortedArticles = localizedArticles.sort(
@ -29,14 +32,14 @@ const sortedArticles = localizedArticles.sort(
);
// Only return snippets with correct lang in the frontmatter
const localizedSnippets = await getCollection("fragments", ({ data }) => {
return data.lang === astroI18n.langCode && !data.draft;
return data.lang === locale && !data.draft;
});
// sort articles by descending publication date
const sortedSnippets = localizedSnippets.sort(
(a, b) => b.data.createdAt - a.data.createdAt
);
const localizedReferences = await getCollection("references", ({ data }) => {
return data.lang === astroI18n.langCode && !data.draft;
return data.lang === locale && !data.draft;
});
---

View file

@ -8,7 +8,9 @@ import BaseLayout from "../../layouts/BaseLayout.astro";
import MetaDate from "../../components/MetaDate.astro";
// get all content
const allSections = await Astro.glob("../../data/veille/**/*.md");
const allSections = Object.values(
import.meta.glob("../../data/veille/**/*.md", { eager: true })
);
// only keep the right locale version
const localizedSections = allSections.filter((section) => {
return section.frontmatter.lang === astroI18n.langCode;