v5 migration + remove i18n

This commit is contained in:
nico 2024-12-29 12:33:22 +01:00
parent b7ce5b7f20
commit b2b6887fdf
Signed by: Nicolas
SSH key fingerprint: SHA256:ELi8eDeNLl5PTn64G+o2Kx5+XVDfHF5um2tZigfwWkM
84 changed files with 1258 additions and 1354 deletions

View file

@ -1,24 +1,24 @@
---
import { createStaticPaths } from "astro-i18n";
import { createStaticPaths } from 'astro-i18n'
import { getCollection } from "astro:content";
import { getCollection } from 'astro:content'
import EditorialContent from "../../components/EditorialContent.astro";
import BaseLayout from "../../layouts/BaseLayout.astro";
import EditorialContent from '../../components/EditorialContent.astro'
import BaseLayout from '../../layouts/BaseLayout.astro'
export const getStaticPaths = createStaticPaths(
async ({ langCode }) => {
const articles = await getCollection("articles", ({ data }) => {
console.log(langCode);
return data.lang === langCode;
});
const articles = await getCollection('articles', ({ data }) => {
console.log(langCode)
return data.lang === langCode
})
return articles.map((article) => ({
params: { id: article.data.permalink },
props: { article },
}));
params: { id: article.data.slug },
props: { article }
}))
},
import.meta.url
);
)
// export async function getStaticPaths() {
// const articles = await getCollection("articles", ({ data }) => {
@ -28,12 +28,12 @@ export const getStaticPaths = createStaticPaths(
// console.log(articles);
// return articles.map((article) => ({
// params: { slug: article.data.permalink },
// params: { slug: article.data.slug },
// props: { article },
// }));
// }
const { article } = Astro.props;
const { article } = Astro.props
---
<BaseLayout pageTitle={article.data.title}>

View file

@ -1,36 +1,36 @@
---
import { createStaticPaths } from "astro-i18n";
import { createStaticPaths } from 'astro-i18n'
// import { astroI18n } from "astro-i18n";
import { getCollection } from "astro:content";
import EditorialContent from "../../components/EditorialContent.astro";
import { getCollection } from 'astro:content'
import EditorialContent from '../../components/EditorialContent.astro'
import BaseLayout from "../../layouts/BaseLayout.astro";
import BaseLayout from '../../layouts/BaseLayout.astro'
export const getStaticPaths = createStaticPaths(
async ({ langCode }) => {
const snippets = await getCollection("fragments", ({ data }) => {
return data.lang === langCode;
});
const snippets = await getCollection('fragments', ({ data }) => {
return data.lang === langCode
})
return snippets.map((snippet) => ({
params: { id: snippet.data.permalink },
props: { snippet },
}));
params: { id: snippet.data.slug },
props: { snippet }
}))
},
import.meta.url
);
)
// export async function getStaticPaths() {
// const snippets = await getCollection("fragments", ({ data }) => {
// return data.lang === astroI18n.langCode;
// });
// return snippets.map((snippet) => ({
// params: { slug: snippet.data.permalink },
// params: { slug: snippet.data.slug },
// props: { snippet },
// }));
// }
const { snippet } = Astro.props;
const { snippet } = Astro.props
---
<BaseLayout pageTitle={snippet.data.title}>

View file

@ -1,57 +1,61 @@
---
const locale = Astro.currentLocale;
import { getCollection, render } from 'astro:content'
// import stuff
import BaseLayout from "../layouts/BaseLayout.astro";
import QuickAccessCard from "../components/QuickAccessCard.astro";
import ListCards from "../components/ListCards.astro";
import BaseLayout from '../layouts/BaseLayout.astro'
import QuickAccessCard from '../components/QuickAccessCard.astro'
import ListCards from '../components/ListCards.astro'
const pageTitle = t("accueil");
const pageTitle = 'Accueil'
// get all HP sections
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 === locale;
});
const HPsections = await getCollection('HPsections').then(async (entries) => {
entries.sort((a, b) => a.data.order - b.data.order)
return Promise.all(
entries.map(async (entry) => {
// render and return entry + content
const { Content } = await render(entry)
return {
...entry,
Content
}
})
)
})
// 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 === locale && !data.draft;
});
// sort articles by descending publication date
const sortedArticles = localizedArticles.sort(
(a, b) => b.data.createdAt - a.data.createdAt
);
// Only return snippets with correct lang in the frontmatter
const localizedSnippets = await getCollection("fragments", ({ data }) => {
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 === locale && !data.draft;
});
const allArticles = await getCollection('articles', ({ data }) => {
return !data.draft && data.lang === 'fr'
}).then((entries) =>
// sort results
entries.sort(
(a, b) => b.data.createdAt.getTime() - a.data.createdAt.getTime()
)
)
const allSnippets = await getCollection('fragments', ({ data }) => {
return !data.draft && data.lang === 'fr'
}).then((entries) =>
entries.sort(
(a, b) => b.data.createdAt.getTime() - a.data.createdAt.getTime()
)
)
const allReferences = await getCollection('references')
---
<BaseLayout pageTitle={pageTitle}>
<section class="region intro">
<h1 set:html={t("index.title")} />
<section class="quick-access">
<h2 class="intro__subtitle">{t("index.subtitle")}</h2>
<ul class="quick-access__list" role="list">
<section class='region intro'>
<h1>
Création de <span class='highlight'>sites&nbsp;web</span>
<a href='/articles/faq' class='clean-link'>sobres et accessibles</a>
</h1>
<section class='quick-access'>
<h2 class='intro__subtitle'>Apprenez-en plus sur…</h2>
<ul class='quick-access__list' role='list'>
{
localizedSections.map(
HPsections.map(
(section) =>
section.frontmatter.id && (
section.data.uid && (
<li>
<QuickAccessCard item={section.frontmatter} />
<QuickAccessCard item={section.data} />
</li>
)
)
@ -61,49 +65,43 @@ const localizedReferences = await getCollection("references", ({ data }) => {
</section>
{
localizedSections.map((section) => (
<section id={section.frontmatter.id} class="region section">
<div class="section__container">
<div class="flow section__content">
<section.Content />
{section.frontmatter.reference && (
<div class="section__reference">
HPsections.map(({ data, Content }) => (
<section id={data.uid} class='region section'>
<div class='section__container'>
<div class='flow section__content'>
<Content />
{data.reference && (
<div class='section__reference'>
<ListCards
list={localizedReferences.filter((ref) => {
return ref.data.permalink === section.frontmatter.reference;
list={allReferences.filter((ref) => {
return ref.data.slug === data.reference
})}
routeName={t("references.slug")}
routeName='references'
/>
</div>
)}
</div>
<div class="section__image">
<img
src={section.frontmatter.image}
width="400"
height="350"
alt=""
aria-hidden="true"
/>
<div class='section__image'>
<img src={data.image} width='400' height='350' alt='' />
</div>
</div>
</section>
))
}
<section class="region flow latest">
<div class="flow latest__articles">
<h2>{t("index.latestArticles")}</h2>
<ListCards list={sortedArticles} routeName={t("article.titre")} />
<p class="latest__link">
<a href={l("/articles")}>{t("index.allArticles")}</a>
<section class='region flow latest'>
<div class='flow latest__articles'>
<h2>Derniers articles</h2>
<ListCards list={allArticles} routeName='articles' />
<p class='latest__link'>
<a href='/articles'>Tous les articles</a>
</p>
</div>
<div class="flow latest__snippets">
<h2>{t("index.latestSnippets")}</h2>
<ListCards list={sortedSnippets} routeName={t("fragments.titre")} />
<p class="latest__link">
<a href={l("/fragments")}>{t("index.allSnippets")}</a>
<div class='flow latest__snippets'>
<h2>Derniers fragments</h2>
<ListCards list={allSnippets} routeName='fragments' />
<p class='latest__link'>
<a href='/fragments'>Tous les fragments</a>
</p>
</div>
</section>
@ -115,7 +113,7 @@ const localizedReferences = await getCollection("references", ({ data }) => {
position: relative;
}
.intro::before {
content: "";
content: '';
position: absolute;
top: -30%;
left: -10%;
@ -142,7 +140,7 @@ const localizedReferences = await getCollection("references", ({ data }) => {
}
.intro__subtitle {
margin: var(--space-s-m) 0;
font-family: "wotfard";
font-family: 'wotfard';
font-weight: 500;
text-align: center;
color: var(--color-dark-blue);

View file

@ -1,44 +1,40 @@
---
// init i18n
import { l, t, astroI18n } from "astro-i18n";
astroI18n.init(Astro);
import BaseLayout from "../layouts/BaseLayout.astro";
import BaseLayout from '../layouts/BaseLayout.astro'
// New astro content collections
import { getCollection } from "astro:content";
import { getCollection } from 'astro:content'
// get all articles
const localizedArticles = await getCollection("articles", ({ data }) => {
return data.lang === astroI18n.langCode && !data.draft;
});
const allArticles = await getCollection('articles', ({ data }) => {
return !data.draft
})
// get all snippets
const localizedFragments = await getCollection("fragments", ({ data }) => {
return data.lang === astroI18n.langCode && !data.draft;
});
const allFragments = await getCollection('fragments', ({ data }) => {
return !data.draft
})
const pageTitle = t("sitemap");
const pageTitle = 'Plan du site'
---
<BaseLayout pageTitle={pageTitle}>
<section class="region">
<h1>{t("sitemap")}</h1>
<ul class="flow sitemap" role="list">
<section class='region'>
<h1>{pageTitle}</h1>
<ul class='flow sitemap' role='list'>
<li>
<h2>
<a href={l("/")}>{t("accueil")}</a>
<a href='/'>Accueil</a>
</h2>
</li>
<li>
<h2>
<a href={l("/articles")}>{t("article.titre")}</a>
<a href='/articles'>Articles</a>
</h2>
<ul>
{
localizedArticles.map((article) => (
allArticles.map((article) => (
<li>
<a href={l("/articles/[slug]", { slug: article.slug })}>
{article.data.title}
<a href={`/articles/${article.data.slug}`}>
{article.data.title} <sup>({article.data.lang})</sup>
</a>
</li>
))
@ -47,14 +43,17 @@ const pageTitle = t("sitemap");
</li>
<li>
<h2>
<a href={l("/fragments")}>{t("fragments.titre")}</a>
<a href='/fragments'>Fragments</a>
</h2>
<ul>
{
localizedFragments.map((fragment) => (
allFragments.map((fragment) => (
<li>
<a href={l("/fragments/[slug]", { slug: fragment.slug })}>
{fragment.data.title}
<a
href={`/fragments/${fragment.id}`}
lang={fragment.data.lang !== 'fr' ? fragment.data.lang : null}
>
{fragment.data.title} <sup>({fragment.data.lang})</sup>
</a>
</li>
))
@ -63,12 +62,12 @@ const pageTitle = t("sitemap");
</li>
<li>
<h2>
<a href={l("/references")}>{t("references.titre")}</a>
<a href='/references'>Références</a>
</h2>
</li>
<li>
<h2>
<a href={l("/veille")}>{t("veille.titre")}</a>
<a href='/veille'>Veille</a>
</h2>
</li>
</ul>
@ -76,11 +75,13 @@ const pageTitle = t("sitemap");
</BaseLayout>
<style>
h2 {
text-transform: capitalize;
}
.sitemap * + * {
margin-block-start: 20px;
margin-block-start: var(--space-s);
}
.sitemap > * + * {
margin-block-start: var(--space-l);
}
sup {
font-weight: normal;
}
</style>

View file

@ -1,19 +1,19 @@
import rss from "@astrojs/rss";
import { getCollection } from "astro:content";
import rss from '@astrojs/rss'
import { getCollection } from 'astro:content'
export async function get(context) {
const articles = await getCollection("articles", ({ data }) => {
return data.lang === "fr" && !data.draft;
});
const fragments = await getCollection("fragments", ({ data }) => {
return data.lang === "fr" && !data.draft;
});
const posts = articles.concat(fragments);
const articles = await getCollection('articles', ({ data }) => {
return data.lang === 'fr' && !data.draft
})
const fragments = await getCollection('fragments', ({ data }) => {
return data.lang === 'fr' && !data.draft
})
const posts = articles.concat(fragments)
return rss({
// `<title>` field in output xml
title: "Nicolas Arduin",
title: 'Nicolas Arduin',
// `<description>` field in output xml
description: "Articles publiés sur nardu.in",
description: 'Articles publiés sur nardu.in',
// Pull in your project "site" from the endpoint context
// https://docs.astro.build/en/reference/api-reference/#contextsite
site: context.site,
@ -26,9 +26,9 @@ export async function get(context) {
lang: post.data.lang,
// Compute RSS link from post `slug`
// This example assumes all posts are rendered as `/blog/[slug]` routes
link: `/${post.data.type}/${post.data.permalink}/`,
link: `/${post.data.type}/${post.data.slug}/`
})),
// (optional) inject custom xml
customData: `<language>fr-fr</language>`,
});
customData: `<language>fr-fr</language>`
})
}