update to v5 + remove unmaintained i18n lib
This commit is contained in:
parent
59687fbade
commit
99ef7634e3
3
.gitignore
vendored
3
.gitignore
vendored
@ -17,3 +17,6 @@ pnpm-debug.log*
|
|||||||
|
|
||||||
# macOS-specific files
|
# macOS-specific files
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
# i18n
|
||||||
|
astro_tmp_pages_*
|
@ -1,8 +1,5 @@
|
|||||||
import { defineConfig } from "astro/config";
|
import { defineConfig } from "astro/config";
|
||||||
|
|
||||||
// https://github.com/alexandre-fernandez/astro-i18n
|
|
||||||
import i18n from "astro-i18n";
|
|
||||||
|
|
||||||
// https://astro.build/config
|
// https://astro.build/config
|
||||||
import mdx from "@astrojs/mdx";
|
import mdx from "@astrojs/mdx";
|
||||||
import sitemap from "@astrojs/sitemap";
|
import sitemap from "@astrojs/sitemap";
|
||||||
@ -10,24 +7,15 @@ import sitemap from "@astrojs/sitemap";
|
|||||||
// https://astro.build/config
|
// https://astro.build/config
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
site: "https://www.nardu.in",
|
site: "https://www.nardu.in",
|
||||||
|
build: {
|
||||||
|
format: "directory",
|
||||||
|
},
|
||||||
image: {
|
image: {
|
||||||
domains: ["assets.nardu.in"],
|
domains: ["assets.nardu.in"],
|
||||||
remotePatterns: [{ protocol: "https" }],
|
remotePatterns: [{ protocol: "https" }],
|
||||||
},
|
},
|
||||||
markdown: {
|
|
||||||
syntaxHighlight: "prism",
|
|
||||||
},
|
|
||||||
integrations: [
|
integrations: [
|
||||||
i18n(),
|
|
||||||
mdx(),
|
mdx(),
|
||||||
sitemap({
|
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",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
15
package.json
15
package.json
@ -13,15 +13,14 @@
|
|||||||
"i18n:sync": "astro-i18n sync"
|
"i18n:sync": "astro-i18n sync"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@astrojs/mdx": "^1.1.0",
|
"@astrojs/mdx": "4.0.3",
|
||||||
"@astrojs/rss": "^3.0.0",
|
"@astrojs/rss": "4.0.10",
|
||||||
"@astrojs/sitemap": "^3.0.0",
|
"@astrojs/sitemap": "3.2.1",
|
||||||
"astro": "3.1.4",
|
"astro": "5.1.1",
|
||||||
"astro-i18n": "1.8.1",
|
"sharp": "^0.33.4"
|
||||||
"sharp": "^0.32.6"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autoprefixer": "^10.4.13",
|
"autoprefixer": "^10.4.19",
|
||||||
"postcss": "^8.4.20"
|
"postcss": "^8.4.38"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
---
|
---
|
||||||
// import { renderContent } from "astro-i18n";
|
import { render } from "astro:content";
|
||||||
|
|
||||||
import MetaDate from "./MetaDate.astro";
|
import MetaDate from "./MetaDate.astro";
|
||||||
import TOC from "./TOC.astro";
|
import TOC from "./TOC.astro";
|
||||||
|
|
||||||
const { content } = Astro.props;
|
const { content } = Astro.props;
|
||||||
const { Content, headings } = await content.render();
|
const { Content, headings } = await render(content);
|
||||||
// const { html, headings } = await renderContent(Astro, content);
|
|
||||||
|
|
||||||
const toc = headings.map((heading) => {
|
const toc = headings.map((heading) => {
|
||||||
return heading;
|
return heading;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { z, defineCollection } from "astro:content";
|
import { z, defineCollection } from "astro:content";
|
||||||
|
import { glob } from 'astro/loaders';
|
||||||
|
|
||||||
const articles = defineCollection({
|
const articles = defineCollection({
|
||||||
|
loader: glob({ pattern: '**/[^_]*.md', base: "./src/content/articles" }),
|
||||||
schema: z.object({
|
schema: z.object({
|
||||||
title: z.string(),
|
title: z.string(),
|
||||||
subtitle: z.string(),
|
subtitle: z.string(),
|
||||||
@ -20,6 +22,7 @@ const articles = defineCollection({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const fragments = defineCollection({
|
const fragments = defineCollection({
|
||||||
|
loader: glob({ pattern: '**/[^_]*.md', base: "./src/content/fragments" }),
|
||||||
schema: z.object({
|
schema: z.object({
|
||||||
title: z.string(),
|
title: z.string(),
|
||||||
subtitle: z.string(),
|
subtitle: z.string(),
|
||||||
@ -39,6 +42,7 @@ const fragments = defineCollection({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const references = defineCollection({
|
const references = defineCollection({
|
||||||
|
loader: glob({ pattern: '**/[^_]*.md', base: "./src/content/references" }),
|
||||||
schema: z.object({
|
schema: z.object({
|
||||||
title: z.string(),
|
title: z.string(),
|
||||||
subtitle: z.string(),
|
subtitle: z.string(),
|
@ -13,7 +13,7 @@ export const getStaticPaths = createStaticPaths(
|
|||||||
return data.lang === langCode;
|
return data.lang === langCode;
|
||||||
});
|
});
|
||||||
return articles.map((article) => ({
|
return articles.map((article) => ({
|
||||||
params: { slug: article.data.permalink },
|
params: { id: article.data.permalink },
|
||||||
props: { article },
|
props: { article },
|
||||||
}));
|
}));
|
||||||
},
|
},
|
@ -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} />
|
|
@ -1,6 +0,0 @@
|
|||||||
---
|
|
||||||
import Page from "../../articles/index.astro"
|
|
||||||
const { props } = Astro
|
|
||||||
---
|
|
||||||
|
|
||||||
<Page {...props} />
|
|
@ -1,6 +0,0 @@
|
|||||||
---
|
|
||||||
import Page from "../index.astro"
|
|
||||||
const { props } = Astro
|
|
||||||
---
|
|
||||||
|
|
||||||
<Page {...props} />
|
|
@ -1,6 +0,0 @@
|
|||||||
---
|
|
||||||
import Page from "../plan-du-site.astro"
|
|
||||||
const { props } = Astro
|
|
||||||
---
|
|
||||||
|
|
||||||
<Page {...props} />
|
|
@ -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} />
|
|
@ -1,6 +0,0 @@
|
|||||||
---
|
|
||||||
import Page from "../../fragments/index.astro"
|
|
||||||
const { props } = Astro
|
|
||||||
---
|
|
||||||
|
|
||||||
<Page {...props} />
|
|
@ -1,6 +0,0 @@
|
|||||||
---
|
|
||||||
import Page from "../../veille/index.astro"
|
|
||||||
const { props } = Astro
|
|
||||||
---
|
|
||||||
|
|
||||||
<Page {...props} />
|
|
@ -1,6 +0,0 @@
|
|||||||
---
|
|
||||||
import Page from "../../references/index.astro"
|
|
||||||
const { props } = Astro
|
|
||||||
---
|
|
||||||
|
|
||||||
<Page {...props} />
|
|
@ -13,7 +13,7 @@ export const getStaticPaths = createStaticPaths(
|
|||||||
return data.lang === langCode;
|
return data.lang === langCode;
|
||||||
});
|
});
|
||||||
return snippets.map((snippet) => ({
|
return snippets.map((snippet) => ({
|
||||||
params: { slug: snippet.data.permalink },
|
params: { id: snippet.data.permalink },
|
||||||
props: { snippet },
|
props: { snippet },
|
||||||
}));
|
}));
|
||||||
},
|
},
|
@ -1,7 +1,8 @@
|
|||||||
---
|
---
|
||||||
// init i18n
|
// init i18n
|
||||||
import { l, t, astroI18n } from "astro-i18n";
|
import { getLocale } from "astro-i18n-aut";
|
||||||
astroI18n.init(Astro);
|
|
||||||
|
const locale = getLocale(Astro.url);
|
||||||
|
|
||||||
// import stuff
|
// import stuff
|
||||||
import BaseLayout from "../layouts/BaseLayout.astro";
|
import BaseLayout from "../layouts/BaseLayout.astro";
|
||||||
@ -11,17 +12,19 @@ import ListCards from "../components/ListCards.astro";
|
|||||||
const pageTitle = t("accueil");
|
const pageTitle = t("accueil");
|
||||||
|
|
||||||
// get all HP sections
|
// 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
|
// only keep the right locale version
|
||||||
const localizedSections = allSections.filter((section) => {
|
const localizedSections = allSections.filter((section) => {
|
||||||
return section.frontmatter.lang === astroI18n.langCode;
|
return section.frontmatter.lang === locale;
|
||||||
});
|
});
|
||||||
|
|
||||||
// New astro content collections
|
// New astro content collections
|
||||||
import { getCollection } from "astro:content";
|
import { getCollection } from "astro:content";
|
||||||
// Only return posts with correct lang in the frontmatter
|
// Only return posts with correct lang in the frontmatter
|
||||||
const localizedArticles = await getCollection("articles", ({ data }) => {
|
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
|
// sort articles by descending publication date
|
||||||
const sortedArticles = localizedArticles.sort(
|
const sortedArticles = localizedArticles.sort(
|
||||||
@ -29,14 +32,14 @@ const sortedArticles = localizedArticles.sort(
|
|||||||
);
|
);
|
||||||
// Only return snippets with correct lang in the frontmatter
|
// Only return snippets with correct lang in the frontmatter
|
||||||
const localizedSnippets = await getCollection("fragments", ({ data }) => {
|
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
|
// sort articles by descending publication date
|
||||||
const sortedSnippets = localizedSnippets.sort(
|
const sortedSnippets = localizedSnippets.sort(
|
||||||
(a, b) => b.data.createdAt - a.data.createdAt
|
(a, b) => b.data.createdAt - a.data.createdAt
|
||||||
);
|
);
|
||||||
const localizedReferences = await getCollection("references", ({ data }) => {
|
const localizedReferences = await getCollection("references", ({ data }) => {
|
||||||
return data.lang === astroI18n.langCode && !data.draft;
|
return data.lang === locale && !data.draft;
|
||||||
});
|
});
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -8,7 +8,9 @@ import BaseLayout from "../../layouts/BaseLayout.astro";
|
|||||||
import MetaDate from "../../components/MetaDate.astro";
|
import MetaDate from "../../components/MetaDate.astro";
|
||||||
|
|
||||||
// get all content
|
// 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
|
// only keep the right locale version
|
||||||
const localizedSections = allSections.filter((section) => {
|
const localizedSections = allSections.filter((section) => {
|
||||||
return section.frontmatter.lang === astroI18n.langCode;
|
return section.frontmatter.lang === astroI18n.langCode;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
{
|
{
|
||||||
"extends": "astro/tsconfigs/base",
|
"extends": "astro/tsconfigs/base",
|
||||||
|
"include": [".astro/types.d.ts", "**/*"],
|
||||||
|
"exclude": ["dist"],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"strictNullChecks": true
|
"strictNullChecks": true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user