added rss feeds
This commit is contained in:
parent
b602b45c05
commit
3d00b4d3cb
36 changed files with 127 additions and 3 deletions
34
src/pages/en/rss.xml.js
Normal file
34
src/pages/en/rss.xml.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
import rss from "@astrojs/rss";
|
||||
import { getCollection } from "astro:content";
|
||||
|
||||
export async function get(context) {
|
||||
const articles = await getCollection("articles", ({ data }) => {
|
||||
return data.lang === "en" && !data.draft;
|
||||
});
|
||||
const fragments = await getCollection("fragments", ({ data }) => {
|
||||
return data.lang === "en" && !data.draft;
|
||||
});
|
||||
const posts = articles.concat(fragments);
|
||||
return rss({
|
||||
// `<title>` field in output xml
|
||||
title: "Nicolas Arduin",
|
||||
// `<description>` field in output xml
|
||||
description: "Articles from nardu.in",
|
||||
// Pull in your project "site" from the endpoint context
|
||||
// https://docs.astro.build/en/reference/api-reference/#contextsite
|
||||
site: context.site,
|
||||
// Array of `<item>`s in output xml
|
||||
// See "Generating items" section for examples using content collections and glob imports
|
||||
items: posts.map((post) => ({
|
||||
title: post.data.title,
|
||||
pubDate: post.data.createdAt,
|
||||
description: post.data.subtitle,
|
||||
lang: post.data.lang,
|
||||
// Compute RSS link from post `slug`
|
||||
// This example assumes all posts are rendered as `/blog/[slug]` routes
|
||||
link: `/en/${post.data.type}/${post.slug}/`,
|
||||
})),
|
||||
// (optional) inject custom xml
|
||||
customData: `<language>en-us</language>`,
|
||||
});
|
||||
}
|
34
src/pages/rss.xml.js
Normal file
34
src/pages/rss.xml.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
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);
|
||||
return rss({
|
||||
// `<title>` field in output xml
|
||||
title: "Nicolas Arduin",
|
||||
// `<description>` field in output xml
|
||||
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,
|
||||
// Array of `<item>`s in output xml
|
||||
// See "Generating items" section for examples using content collections and glob imports
|
||||
items: posts.map((post) => ({
|
||||
title: post.data.title,
|
||||
pubDate: post.data.createdAt,
|
||||
description: post.data.subtitle,
|
||||
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.slug}/`,
|
||||
})),
|
||||
// (optional) inject custom xml
|
||||
customData: `<language>fr-fr</language>`,
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue