Skip to content

Commit

Permalink
Chore: remove rss helper from getStaticPaths (#3462)
Browse files Browse the repository at this point in the history
* chore: remove rss() with helpful error message

* docs: add context on "getStaticPaths" removal

* chore: changeset

* deps: remove fast-xml-parser from core!

* chore: update lockfile
  • Loading branch information
bholmesdev authored May 31, 2022
1 parent b795a08 commit d145b86
Show file tree
Hide file tree
Showing 9 changed files with 323 additions and 564 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-readers-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Remove the rss() helper from getStaticPaths. Using rss() now prints an error pointing to the new @astrojs/rss documentation.
1 change: 0 additions & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
"estree-walker": "^3.0.1",
"execa": "^6.1.0",
"fast-glob": "^3.2.11",
"fast-xml-parser": "^4.0.7",
"gray-matter": "^4.0.3",
"html-entities": "^2.3.3",
"html-escaper": "^3.0.3",
Expand Down
51 changes: 5 additions & 46 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,11 @@ export type GetHydrateCallback = () => Promise<
* Docs: https://docs.astro.build/reference/api-reference/#getstaticpaths
*/ export interface GetStaticPathsOptions {
paginate: PaginateFunction;
rss: (...args: any[]) => any;
/**
* The RSS helper has been removed from getStaticPaths! Try the new @astrojs/rss package instead.
* @see https://docs.astro.build/en/guides/rss/
*/
rss(): never;
}

export type GetStaticPathsItem = { params: Params; props?: Props };
Expand Down Expand Up @@ -986,51 +990,6 @@ export type SerializedRouteData = Omit<RouteData, 'generate' | 'pattern'> & {

export type RuntimeMode = 'development' | 'production';

/**
* RSS
* Docs: https://docs.astro.build/reference/api-reference/#rss
*/
export interface RSS {
/** (required) Title of the RSS Feed */
title: string;
/** (required) Description of the RSS Feed */
description: string;
/** Specify arbitrary metadata on opening <xml> tag */
xmlns?: Record<string, string>;
/**
* If false (default), does not include XSL stylesheet.
* If true, automatically includes 'pretty-feed-v3'.
* If a string value, specifies a local custom XSL stylesheet, for example '/custom-feed.xsl'.
*/
stylesheet?: string | boolean;
/** Specify custom data in opening of file */
customData?: string;
/**
* Specify where the RSS xml file should be written.
* Relative to final build directory. Example: '/foo/bar.xml'
* Defaults to '/rss.xml'.
*/
dest?: string;
/** Return data about each item */
items: {
/** (required) Title of item */
title: string;
/** (required) Link to item */
link: string;
/** Publication date of item */
pubDate?: Date;
/** Item description */
description?: string;
/** Append some other XML-valid data to this item */
customData?: string;
}[];
}

export type RSSFunction = (args: RSS) => RSSResult;

export type FeedResult = { url: string; content?: string };
export type RSSResult = { xml: FeedResult; xsl?: FeedResult };

export type SSRError = Error & vite.ErrorPayload['err'];

export interface SSRElement {
Expand Down
27 changes: 0 additions & 27 deletions packages/astro/src/core/build/page-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { fileURLToPath } from 'url';
import * as colors from 'kleur/colors';
import { debug } from '../logger/core.js';
import { preload as ssrPreload } from '../render/dev/index.js';
import { generateRssFunction } from '../render/rss.js';
import { callGetStaticPaths, RouteCache, RouteCacheEntry } from '../render/route-cache.js';
import { removeTrailingForwardSlash } from '../path.js';
import { isBuildingToSSR } from '../util.js';
Expand Down Expand Up @@ -114,32 +113,6 @@ export async function collectPagesData(
debug('build', `├── ${colors.bold(colors.red('✗'))} ${route.component}`);
throw err;
});
const rssFn = generateRssFunction(astroConfig.site, route);
for (const rssCallArg of result.rss) {
const rssResult = rssFn(rssCallArg);
if (rssResult.xml) {
const { url, content } = rssResult.xml;
if (content) {
const rssFile = new URL(url.replace(/^\/?/, './'), astroConfig.outDir);
if (assets[fileURLToPath(rssFile)]) {
throw new Error(
`[getStaticPaths] RSS feed ${url} already exists.\nUse \`rss(data, {url: '...'})\` to choose a unique, custom URL. (${route.component})`
);
}
assets[fileURLToPath(rssFile)] = content;
}
}
if (rssResult.xsl?.content) {
const { url, content } = rssResult.xsl;
const stylesheetFile = new URL(url.replace(/^\/?/, './'), astroConfig.outDir);
if (assets[fileURLToPath(stylesheetFile)]) {
throw new Error(
`[getStaticPaths] RSS feed stylesheet ${url} already exists.\nUse \`rss(data, {stylesheet: '...'})\` to choose a unique, custom URL. (${route.component})`
);
}
assets[fileURLToPath(stylesheetFile)] = content;
}
}
const finalPaths = result.staticPaths
.map((staticPath) => staticPath.params && route.generate(staticPath.params))
.filter((staticPath) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/render/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface SSROptions {
logging: LogOptions;
/** "development" or "production" */
mode: RuntimeMode;
/** production website, needed for some RSS functions */
/** production website */
origin: string;
/** the web request (needed for dynamic routes) */
pathname: string;
Expand Down
102 changes: 0 additions & 102 deletions packages/astro/src/core/render/pretty-feed.ts

This file was deleted.

14 changes: 3 additions & 11 deletions packages/astro/src/core/render/route-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
GetStaticPathsResultKeyed,
Params,
RouteData,
RSS,
} from '../../@types/astro';
import { LogOptions, warn, debug } from '../logger/core.js';

Expand All @@ -16,8 +15,6 @@ import {
validateGetStaticPathsResult,
} from '../routing/validation.js';

type RSSFn = (...args: any[]) => any;

interface CallGetStaticPathsOptions {
mod: ComponentInstance;
route: RouteData;
Expand All @@ -34,18 +31,15 @@ export async function callGetStaticPaths({
ssr,
}: CallGetStaticPathsOptions): Promise<RouteCacheEntry> {
validateGetStaticPathsModule(mod, { ssr });
const resultInProgress = {
rss: [] as RSS[],
};

let staticPaths: GetStaticPathsResult = [];
if (mod.getStaticPaths) {
staticPaths = (
await mod.getStaticPaths({
paginate: generatePaginateFunction(route),
rss: (data) => {
resultInProgress.rss.push(data);
},
rss() {
throw new Error('The RSS helper has been removed from getStaticPaths! Try the new @astrojs/rss package instead. See https://docs.astro.build/en/guides/rss/')
}
})
).flat();
}
Expand All @@ -61,14 +55,12 @@ export async function callGetStaticPaths({
validateGetStaticPathsResult(keyedStaticPaths, logging);
}
return {
rss: resultInProgress.rss,
staticPaths: keyedStaticPaths,
};
}

export interface RouteCacheEntry {
staticPaths: GetStaticPathsResultKeyed;
rss: RSS[];
}

/**
Expand Down
134 changes: 0 additions & 134 deletions packages/astro/src/core/render/rss.ts

This file was deleted.

Loading

0 comments on commit d145b86

Please sign in to comment.