update to v5 + remove unmaintained i18n lib

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

3
.gitignore vendored
View File

@ -17,3 +17,6 @@ pnpm-debug.log*
# macOS-specific files
.DS_Store
# i18n
astro_tmp_pages_*

View File

@ -1,8 +1,5 @@
import { defineConfig } from "astro/config";
// https://github.com/alexandre-fernandez/astro-i18n
import i18n from "astro-i18n";
// https://astro.build/config
import mdx from "@astrojs/mdx";
import sitemap from "@astrojs/sitemap";
@ -10,24 +7,15 @@ import sitemap from "@astrojs/sitemap";
// https://astro.build/config
export default defineConfig({
site: "https://www.nardu.in",
build: {
format: "directory",
},
image: {
domains: ["assets.nardu.in"],
remotePatterns: [{ protocol: "https" }],
},
markdown: {
syntaxHighlight: "prism",
},
integrations: [
i18n(),
mdx(),
sitemap({
i18n: {
defaultLocale: "fr", // All urls that don't contain `en`
locales: {
fr: "fr-FR", // The `defaultLocale` value must present in `locales` keys
en: "en-US",
},
},
}),
sitemap(),
],
});

BIN
bun.lockb

Binary file not shown.

View File

@ -13,15 +13,14 @@
"i18n:sync": "astro-i18n sync"
},
"dependencies": {
"@astrojs/mdx": "^1.1.0",
"@astrojs/rss": "^3.0.0",
"@astrojs/sitemap": "^3.0.0",
"astro": "3.1.4",
"astro-i18n": "1.8.1",
"sharp": "^0.32.6"
"@astrojs/mdx": "4.0.3",
"@astrojs/rss": "4.0.10",
"@astrojs/sitemap": "3.2.1",
"astro": "5.1.1",
"sharp": "^0.33.4"
},
"devDependencies": {
"autoprefixer": "^10.4.13",
"postcss": "^8.4.20"
"autoprefixer": "^10.4.19",
"postcss": "^8.4.38"
}
}

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;

View File

@ -1,5 +1,7 @@
{
"extends": "astro/tsconfigs/base",
"include": [".astro/types.d.ts", "**/*"],
"exclude": ["dist"],
"compilerOptions": {
"strictNullChecks": true
}