Closed louiss0 closed 1 year ago
👍 Ideally we'd be able to use getCollection()
API directly as this is the type of scenario it's really useful for.
Ugly workaround:
const slugRegex = /^src\/content\/blog\/(.*?)\.mdx?$/i
...
link: new URL(`/posts/${post.url.replace(slugRegex, '$1/')}`, import.meta.env.SITE).toString(),
You can use the getCollection()
API directly.
import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';
import { SITE_TITLE, SITE_DESCRIPTION } from '../config';
const posts = await getCollection('blog');
export const get = () =>
rss({
title: SITE_TITLE,
description: SITE_DESCRIPTION,
site: import.meta.env.SITE,
items: posts.map((post) => ({
title: post.data.title,
description: post.data.description,
pubDate: post.data.pubDate,
link: post.slug,
})),
});
You can use the
getCollection()
API directly.import rss from '@astrojs/rss'; import { getCollection } from 'astro:content'; import { SITE_TITLE, SITE_DESCRIPTION } from '../config'; const posts = await getCollection('blog'); export const get = () => rss({ title: SITE_TITLE, description: SITE_DESCRIPTION, site: import.meta.env.SITE, items: posts.map((post) => ({ title: post.data.title, description: post.data.description, pubDate: post.data.pubDate, link: post.slug, })), });
I can't seem to get a good build from doing that.
I did verify that it works: louiss0/test-windows#1 (open in StackBlitz).
I did verify that it works: louiss0/test-windows#1 (open in StackBlitz).
I tried out the example but I did not get a good build out of it. This is what I get when I try to build the site.
Using get collection does not allow you to get the build you want. I don't know what is happening but the files i need refuse to come out. Do I need to build while the server is running or something?
It looks like you are running astro preview
, which does not build anything; it only serves the build that was previously generated with astro build
. Review the CLI reference.
It looks like you are running
astro preview
, which does not build anything; it only serves the build that was previously generated withastro build
. Review the CLI reference.
I did that after the build the files that are generated from the build on the left. It's not about the command It's about the files. As you can see no html files are generated at all.
I just noticed that I don't get the url from the post when I use import.meta.glob()
this is what I get from it
👍 Ideally we'd be able to use
getCollection()
API directly as this is the type of scenario it's really useful for.Ugly workaround:
const slugRegex = /^src\/content\/blog\/(.*?)\.mdx?$/i ... link: new URL(`/posts/${post.url.replace(slugRegex, '$1/')}`, import.meta.env.SITE).toString(),
How am I supposed to write the url. I see no url out put any more
As you can see no html files are generated at all.
You seem to have run into a separate async
-related bug that caused astro build
to exit early without an error message. I’ve filed that as #5628. Try again with this (also updated at louiss0/test-windows#1).
import rss from "@astrojs/rss";
import { getCollection } from "astro:content";
import { SITE_TITLE, SITE_DESCRIPTION } from "../config";
export const get = async () => {
const posts = await getCollection("blog");
return rss({
title: SITE_TITLE,
description: SITE_DESCRIPTION,
site: import.meta.env.SITE,
items: posts.map((post) => ({
title: post.data.title,
description: post.data.description,
pubDate: post.data.pubDate,
link: post.slug,
})),
});
};
As you can see no html files are generated at all.
You seem to have run into a separate
async
-related bug that causedastro build
to exit early without an error message. Try again with this (also updated at louiss0/test-windows#1).import rss from "@astrojs/rss"; import { getCollection } from "astro:content"; import { SITE_TITLE, SITE_DESCRIPTION } from "../config"; export const get = async () => { const posts = await getCollection("blog"); return rss({ title: SITE_TITLE, description: SITE_DESCRIPTION, site: import.meta.env.SITE, items: posts.map((post) => ({ title: post.data.title, description: post.data.description, pubDate: post.data.pubDate, link: post.slug, })), }); };
You got it the astro team needs to be told that this is how to use getCollection()
from now on. We have a new problem now.
I'll have to write lots of boilerplate code to be able to get multiple collections from multiple files. I want the content folder just to be the base.
This is how you use astro/rss with content collections. This is fantastic
As you can see no html files are generated at all.
You seem to have run into a separate
async
-related bug that causedastro build
to exit early without an error message. I’ve filed that as #5628. Try again with this (also updated at louiss0/test-windows#1).import rss from "@astrojs/rss"; import { getCollection } from "astro:content"; import { SITE_TITLE, SITE_DESCRIPTION } from "../config"; export const get = async () => { const posts = await getCollection("blog"); return rss({ title: SITE_TITLE, description: SITE_DESCRIPTION, site: import.meta.env.SITE, items: posts.map((post) => ({ title: post.data.title, description: post.data.description, pubDate: post.data.pubDate, link: post.slug, })), }); };
Thanks! 🚀 I got the early exit issue using astro build
multiple in my attempts, so though this was limited to *.astro
files.
What version of
astro
are you using?1.7.0
Are you using an SSR adapter? If so, which one?
NONE
What package manager are you using?
pnpm
What operating system are you using?
Windows
Describe the Bug
I can't use RSS with Astro when I try to use the content folder to render the rss stuff it will not work.
This is the error that I get when running the code.
This is what my config looks like
Link to Minimal Reproducible Example
https://github.com/louiss0/test-windows
Participation