🎉 initiate project *astro_rewrite*

This commit is contained in:
sindrekjelsrud 2023-07-19 21:31:30 +02:00
parent ffd4d5e86c
commit 2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions

61
node_modules/@astrojs/rss/LICENSE generated vendored Normal file
View file

@ -0,0 +1,61 @@
MIT License
Copyright (c) 2021 Fred K. Schott
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/sveltejs/kit repository:
Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
"""
This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/vitejs/vite repository:
MIT License
Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

376
node_modules/@astrojs/rss/README.md generated vendored Normal file
View file

@ -0,0 +1,376 @@
# @astrojs/rss 📖
This package brings fast RSS feed generation to blogs and other content sites built with [Astro](https://astro.build/). For more information about RSS feeds in general, see [aboutfeeds.com](https://aboutfeeds.com/).
## Installation
Install the `@astrojs/rss` package into any Astro project using your preferred package manager:
```bash
# npm
npm i @astrojs/rss
# yarn
yarn add @astrojs/rss
# pnpm
pnpm i @astrojs/rss
```
## Example usage
The `@astrojs/rss` package provides helpers for generating RSS feeds within [Astro endpoints][astro-endpoints]. This unlocks both static builds _and_ on-demand generation when using an [SSR adapter](https://docs.astro.build/en/guides/server-side-rendering/#enabling-ssr-in-your-project).
For instance, say you need to generate an RSS feed for all posts under `src/content/blog/` using content collections.
Start by [adding a `site` to your project's `astro.config` for link generation](https://docs.astro.build/en/reference/configuration-reference/#site). Then, create an `rss.xml.js` file under your project's `src/pages/` directory, and [use `getCollection()`](https://docs.astro.build/en/guides/content-collections/#getcollection) to generate a feed from all documents in the `blog` collection:
```js
// src/pages/rss.xml.js
import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';
export async function get(context) {
const posts = await getCollection('blog');
return rss({
title: 'Buzzs Blog',
description: 'A humble Astronauts guide to the stars',
// Pull in your project "site" from the endpoint context
// https://docs.astro.build/en/reference/api-reference/#contextsite
site: context.site,
items: posts.map(post => ({
// Assumes all RSS feed item properties are in post frontmatter
...post.data,
// Generate a `url` from each post `slug`
// This assumes all blog posts are rendered as `/blog/[slug]` routes
// https://docs.astro.build/en/guides/content-collections/#generating-pages-from-content-collections
link: `/blog/${post.slug}/`,
}))
});
}
```
Read **[Astro's RSS docs][astro-rss]** for more on using content collections, and instructions for globbing entries in `/src/pages/`.
## `rss()` configuration options
The `rss` default export offers a number of configuration options. Here's a quick reference:
```js
export function get(context) {
return rss({
// `<title>` field in output xml
title: 'Buzzs Blog',
// `<description>` field in output xml
description: 'A humble Astronauts guide to the stars',
// provide a base URL for RSS <item> links
site: context.site,
// list of `<item>`s in output xml
items: [...],
// include draft posts in the feed (default: false)
drafts: true,
// (optional) absolute path to XSL stylesheet in your project
stylesheet: '/rss-styles.xsl',
// (optional) inject custom xml
customData: '<language>en-us</language>',
// (optional) add arbitrary metadata to opening <rss> tag
xmlns: { h: 'http://www.w3.org/TR/html4/' },
// (optional) add trailing slashes to URLs (default: true)
trailingSlash: false
});
}
```
### title
Type: `string (required)`
The `<title>` attribute of your RSS feed's output xml.
### description
Type: `string (required)`
The `<description>` attribute of your RSS feed's output xml.
### site
Type: `string (required)`
The base URL to use when generating RSS item links. We recommend using the [endpoint context object](https://docs.astro.build/en/reference/api-reference/#contextsite), which includes the `site` configured in your project's `astro.config.*`:
```ts
import rss from '@astrojs/rss';
export const get = (context) => rss({
site: context.site,
...
});
```
### items
Type: `RSSFeedItem[] (required)`
A list of formatted RSS feed items. See [Astro's RSS items documentation](https://docs.astro.build/en/guides/rss/#generating-items) for usage examples to choose the best option for you.
When providing a formatted RSS item list, see the [`RSSFeedItem` type reference](#rssfeeditem).
### drafts
Type: `boolean (optional)`
Set `drafts: true` to include [draft posts](https://docs.astro.build/en/guides/markdown-content/#draft-pages) in the feed output. By default, this option is `false` and draft posts are not included.
### stylesheet
Type: `string (optional)`
An absolute path to an XSL stylesheet in your project. If you dont have an RSS stylesheet in mind, we recommend the [Pretty Feed v3 default stylesheet](https://github.com/genmon/aboutfeeds/blob/main/tools/pretty-feed-v3.xsl), which you can download from GitHub and save into your project's `public/` directory.
### customData
Type: `string (optional)`
A string of valid XML to be injected between your feed's `<description>` and `<item>` tags. This is commonly used to set a language for your feed:
```js
import rss from '@astrojs/rss';
export const get = () => rss({
...
customData: '<language>en-us</language>',
});
```
### xmlns
Type: `Record<string, string> (optional)`
An object mapping a set of `xmlns` suffixes to strings of metadata on the opening `<rss>` tag.
For example, this object:
```js
rss({
...
xmlns: { h: 'http://www.w3.org/TR/html4/' },
})
```
Will inject the following XML:
```xml
<rss xmlns:h="http://www.w3.org/TR/html4/"...
```
### content
The `content` key contains the full content of the post as HTML. This allows you to make your entire post content available to RSS feed readers.
**Note:** Whenever you're using HTML content in XML, we suggest using a package like [`sanitize-html`](https://www.npmjs.com/package/sanitize-html) in order to make sure that your content is properly sanitized, escaped, and encoded.
[See our RSS documentation](https://docs.astro.build/en/guides/rss/#including-full-post-content) for examples using content collections and glob imports.
### `trailingSlash`
Type: `boolean (optional)`
Default: `true`
By default, the library will add trailing slashes to the emitted URLs. To prevent this behavior, add `trailingSlash: false` to the `rss` function.
```js
import rss from '@astrojs/rss';
export const get = () => rss({
trailingSlash: false
});
```
## `RSSFeedItem`
An `RSSFeedItem` is a single item in the list of items in your feed. It represents a story, with `link`, `title`, and `pubDate` fields. There are further optional fields defined below. You can also check the definitions for the fields in the [RSS spec](https://validator.w3.org/feed/docs/rss2.html#ltpubdategtSubelementOfLtitemgt).
An example feed item might look like:
```js
const item = {
title: "Alpha Centauri: so close you can touch it",
link: "/blog/alpha-centuari",
pubDate: new Date("2023-06-04"),
description: "Alpha Centauri is a triple star system, containing Proxima Centauri, the closest star to our sun at only 4.24 light-years away.",
categories: ["stars", "space"]
}
```
### `title`
Type: `string (required)`
The title of the item in the feed.
### `link`
Type: `string (required)`
The URL of the item on the web.
### `pubDate`
Type: `Date (required)`
Indicates when the item was published.
### `description`
Type: `string (optional)`
A synopsis of your item when you are publishing the full content of the item in the `content` field. The `description` may alternatively be the full content of the item in the feed if you are not using the `content` field (entity-coded HTML is permitted).
### `content`
Type: `string (optional)`
The full text content of the item suitable for presentation as HTML. If used, you should also provide a short article summary in the `description` field.
See the [recommendations from the RSS spec for how to use and differentiate between `description` and `content`](https://www.rssboard.org/rss-profile#namespace-elements-content-encoded).
### `categories`
Type: `string[] (optional)`
A list of any tags or categories to categorize your content. They will be output as multiple `<category>` elements.
### `author`
Type: `string (optional)`
The email address of the item author. This is useful for indicating the author of a post on multi-author blogs.
### `commentsUrl`
Type: `string (optional)`
The URL of a web page that contains comments on the item.
### `source`
Type: `object (optional)`
An object that defines the `title` and `url` of the original feed for items that have been republished from another source. Both are required properties of `source` for proper attribution.
```js
const item = {
title: "Alpha Centauri: so close you can touch it",
link: "/blog/alpha-centuari",
pubDate: new Date("2023-06-04"),
description: "Alpha Centauri is a triple star system, containing Proxima Centauri, the closest star to our sun at only 4.24 light-years away.",
source: {
title: "The Galactic Times",
url: "https://galactictimes.space/feed.xml"
}
}
```
#### `source.title`
Type: `string (required)`
The name of the original feed in which the item was published. (Note that this is the feed's title, not the individual article title.)
#### `source.url`
Type: `string (required)`
The URL of the original feed in which the item was published.
### `enclosure`
Type: `object (optional)`
An object to specify properties for an included media source (e.g. a podcast) with three required values: `url`, `length`, and `type`.
```js
const item = {
title: "Alpha Centauri: so close you can touch it",
link: "/blog/alpha-centuari",
pubDate: new Date("2023-06-04"),
description: "Alpha Centauri is a triple star system, containing Proxima Centauri, the closest star to our sun at only 4.24 light-years away.",
enclosure: {
url: "/media/alpha-centauri.aac",
length: 124568,
type: "audio/aac"
}
}
```
#### `enclosure.url`
Type: `string (required)`
The URL where the media can be found. If the media is hosted outside of your own domain you must provide a full URL.
#### `enclosure.length`
Type: `number (required)`
The size of the file found at the `url` in bytes.
#### `enclosure.type`
Type: `string (required)`
The [MIME type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types) for the media item found at the `url`.
## `rssSchema`
When using content collections, you can configure your collection schema to enforce expected [`RSSFeedItem`](#items) properties. Import and apply `rssSchema` to ensure that each collection entry produces a valid RSS feed item:
```ts "schema: rssSchema,"
import { defineCollection } from 'astro:content';
import { rssSchema } from '@astrojs/rss';
const blog = defineCollection({
schema: rssSchema,
});
export const collections = { blog };
```
If you have an existing schema, you can merge extra properties using `extends()`:
```ts ".extends({ extraProperty: z.string() }),"
import { defineCollection } from 'astro:content';
import { rssSchema } from '@astrojs/rss';
const blog = defineCollection({
schema: rssSchema.extends({ extraProperty: z.string() }),
});
```
## `pagesGlobToRssItems()`
To create an RSS feed from documents in `src/pages/`, use the `pagesGlobToRssItems()` helper. This accepts an `import.meta.glob` result ([see Vite documentation](https://vitejs.dev/guide/features.html#glob-import)) and outputs an array of valid [`RSSFeedItem`s](#items).
This function assumes, but does not verify, you are globbing for items inside `src/pages/`, and all necessary feed properties are present in each document's frontmatter. If you encounter errors, verify each page frontmatter manually.
```ts "pagesGlobToRssItems"
// src/pages/rss.xml.js
import rss, { pagesGlobToRssItems } from '@astrojs/rss';
export async function get(context) {
return rss({
title: 'Buzzs Blog',
description: 'A humble Astronauts guide to the stars',
site: context.site,
items: await pagesGlobToRssItems(
import.meta.glob('./blog/*.{md,mdx}'),
),
});
}
```
---
For more on building with Astro, [visit the Astro docs][astro-rss].
[astro-rss]: https://docs.astro.build/en/guides/rss/#using-astrojsrss-recommended
[astro-endpoints]: https://docs.astro.build/en/core-concepts/astro-pages/#non-html-pages

321
node_modules/@astrojs/rss/dist/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,321 @@
import { z } from 'astro/zod';
import { rssSchema } from './schema.js';
export { rssSchema };
export type RSSOptions = {
/** Title of the RSS Feed */
title: z.infer<typeof rssOptionsValidator>['title'];
/** Description of the RSS Feed */
description: z.infer<typeof rssOptionsValidator>['description'];
/**
* Specify the base URL to use for RSS feed links.
* We recommend using the [endpoint context object](https://docs.astro.build/en/reference/api-reference/#contextsite),
* which includes the `site` configured in your project's `astro.config.*`
*/
site: z.infer<typeof rssOptionsValidator>['site'];
/** List of RSS feed items to render. */
items: RSSFeedItem[] | GlobResult;
/** Specify arbitrary metadata on opening <xml> tag */
xmlns?: z.infer<typeof rssOptionsValidator>['xmlns'];
/**
* Specifies a local custom XSL stylesheet. Ex. '/public/custom-feed.xsl'
*/
stylesheet?: z.infer<typeof rssOptionsValidator>['stylesheet'];
/** Specify custom data in opening of file */
customData?: z.infer<typeof rssOptionsValidator>['customData'];
/** Whether to include drafts or not */
drafts?: z.infer<typeof rssOptionsValidator>['drafts'];
trailingSlash?: z.infer<typeof rssOptionsValidator>['trailingSlash'];
};
export type RSSFeedItem = {
/** Link to item */
link: string;
/** Full content of the item. Should be valid HTML */
content?: string | undefined;
/** Title of item */
title: z.infer<typeof rssSchema>['title'];
/** Publication date of item */
pubDate: z.infer<typeof rssSchema>['pubDate'];
/** Item description */
description?: z.infer<typeof rssSchema>['description'];
/** Append some other XML-valid data to this item */
customData?: z.infer<typeof rssSchema>['customData'];
/** Whether draft or not */
draft?: z.infer<typeof rssSchema>['draft'];
/** Categories or tags related to the item */
categories?: z.infer<typeof rssSchema>['categories'];
/** The item author's email address */
author?: z.infer<typeof rssSchema>['author'];
/** A URL of a page for comments related to the item */
commentsUrl?: z.infer<typeof rssSchema>['commentsUrl'];
/** The RSS channel that the item came from */
source?: z.infer<typeof rssSchema>['source'];
/** A media object that belongs to the item */
enclosure?: z.infer<typeof rssSchema>['enclosure'];
};
type ValidatedRSSFeedItem = z.infer<typeof rssFeedItemValidator>;
type GlobResult = z.infer<typeof globResultValidator>;
declare const rssFeedItemValidator: z.ZodObject<{
title: z.ZodString;
pubDate: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodDate]>, Date, string | number | Date>, Date, string | number | Date>;
description: z.ZodOptional<z.ZodString>;
customData: z.ZodOptional<z.ZodString>;
draft: z.ZodOptional<z.ZodBoolean>;
categories: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
author: z.ZodOptional<z.ZodString>;
commentsUrl: z.ZodOptional<z.ZodString>;
source: z.ZodOptional<z.ZodObject<{
url: z.ZodString;
title: z.ZodString;
}, "strip", z.ZodTypeAny, {
title: string;
url: string;
}, {
title: string;
url: string;
}>>;
enclosure: z.ZodOptional<z.ZodObject<{
url: z.ZodString;
length: z.ZodNumber;
type: z.ZodString;
}, "strip", z.ZodTypeAny, {
length: number;
type: string;
url: string;
}, {
length: number;
type: string;
url: string;
}>>;
link: z.ZodString;
content: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
description?: string | undefined;
customData?: string | undefined;
draft?: boolean | undefined;
categories?: string[] | undefined;
author?: string | undefined;
commentsUrl?: string | undefined;
source?: {
title: string;
url: string;
} | undefined;
enclosure?: {
length: number;
type: string;
url: string;
} | undefined;
content?: string | undefined;
title: string;
pubDate: Date;
link: string;
}, {
description?: string | undefined;
customData?: string | undefined;
draft?: boolean | undefined;
categories?: string[] | undefined;
author?: string | undefined;
commentsUrl?: string | undefined;
source?: {
title: string;
url: string;
} | undefined;
enclosure?: {
length: number;
type: string;
url: string;
} | undefined;
content?: string | undefined;
title: string;
pubDate: string | number | Date;
link: string;
}>;
declare const globResultValidator: z.ZodRecord<z.ZodString, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodPromise<z.ZodAny>>>;
declare const rssOptionsValidator: z.ZodObject<{
title: z.ZodString;
description: z.ZodString;
site: z.ZodEffects<z.ZodString, string, unknown>;
items: z.ZodEffects<z.ZodUnion<[z.ZodArray<z.ZodObject<{
title: z.ZodString;
pubDate: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodDate]>, Date, string | number | Date>, Date, string | number | Date>;
description: z.ZodOptional<z.ZodString>;
customData: z.ZodOptional<z.ZodString>;
draft: z.ZodOptional<z.ZodBoolean>;
categories: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
author: z.ZodOptional<z.ZodString>;
commentsUrl: z.ZodOptional<z.ZodString>;
source: z.ZodOptional<z.ZodObject<{
url: z.ZodString;
title: z.ZodString;
}, "strip", z.ZodTypeAny, {
title: string;
url: string;
}, {
title: string;
url: string;
}>>;
enclosure: z.ZodOptional<z.ZodObject<{
url: z.ZodString;
length: z.ZodNumber;
type: z.ZodString;
}, "strip", z.ZodTypeAny, {
length: number;
type: string;
url: string;
}, {
length: number;
type: string;
url: string;
}>>;
link: z.ZodString;
content: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
description?: string | undefined;
customData?: string | undefined;
draft?: boolean | undefined;
categories?: string[] | undefined;
author?: string | undefined;
commentsUrl?: string | undefined;
source?: {
title: string;
url: string;
} | undefined;
enclosure?: {
length: number;
type: string;
url: string;
} | undefined;
content?: string | undefined;
title: string;
pubDate: Date;
link: string;
}, {
description?: string | undefined;
customData?: string | undefined;
draft?: boolean | undefined;
categories?: string[] | undefined;
author?: string | undefined;
commentsUrl?: string | undefined;
source?: {
title: string;
url: string;
} | undefined;
enclosure?: {
length: number;
type: string;
url: string;
} | undefined;
content?: string | undefined;
title: string;
pubDate: string | number | Date;
link: string;
}>, "many">, z.ZodRecord<z.ZodString, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodPromise<z.ZodAny>>>]>, {
description?: string | undefined;
customData?: string | undefined;
draft?: boolean | undefined;
categories?: string[] | undefined;
author?: string | undefined;
commentsUrl?: string | undefined;
source?: {
title: string;
url: string;
} | undefined;
enclosure?: {
length: number;
type: string;
url: string;
} | undefined;
content?: string | undefined;
title: string;
pubDate: Date;
link: string;
}[], {
description?: string | undefined;
customData?: string | undefined;
draft?: boolean | undefined;
categories?: string[] | undefined;
author?: string | undefined;
commentsUrl?: string | undefined;
source?: {
title: string;
url: string;
} | undefined;
enclosure?: {
length: number;
type: string;
url: string;
} | undefined;
content?: string | undefined;
title: string;
pubDate: string | number | Date;
link: string;
}[] | Record<string, (...args: unknown[]) => Promise<any>>>;
xmlns: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
drafts: z.ZodDefault<z.ZodBoolean>;
stylesheet: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>;
customData: z.ZodOptional<z.ZodString>;
trailingSlash: z.ZodDefault<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
customData?: string | undefined;
xmlns?: Record<string, string> | undefined;
stylesheet?: string | boolean | undefined;
title: string;
description: string;
trailingSlash: boolean;
site: string;
items: {
description?: string | undefined;
customData?: string | undefined;
draft?: boolean | undefined;
categories?: string[] | undefined;
author?: string | undefined;
commentsUrl?: string | undefined;
source?: {
title: string;
url: string;
} | undefined;
enclosure?: {
length: number;
type: string;
url: string;
} | undefined;
content?: string | undefined;
title: string;
pubDate: Date;
link: string;
}[];
drafts: boolean;
}, {
customData?: string | undefined;
trailingSlash?: boolean | undefined;
site?: unknown;
xmlns?: Record<string, string> | undefined;
drafts?: boolean | undefined;
stylesheet?: string | boolean | undefined;
title: string;
description: string;
items: {
description?: string | undefined;
customData?: string | undefined;
draft?: boolean | undefined;
categories?: string[] | undefined;
author?: string | undefined;
commentsUrl?: string | undefined;
source?: {
title: string;
url: string;
} | undefined;
enclosure?: {
length: number;
type: string;
url: string;
} | undefined;
content?: string | undefined;
title: string;
pubDate: string | number | Date;
link: string;
}[] | Record<string, (...args: unknown[]) => Promise<any>>;
}>;
export default function getRSS(rssOptions: RSSOptions): Promise<{
body: string;
}>;
export declare function pagesGlobToRssItems(items: GlobResult): Promise<ValidatedRSSFeedItem[]>;

169
node_modules/@astrojs/rss/dist/index.js generated vendored Normal file
View file

@ -0,0 +1,169 @@
import { z } from "astro/zod";
import { XMLBuilder, XMLParser } from "fast-xml-parser";
import { yellow } from "kleur/colors";
import { rssSchema } from "./schema.js";
import { createCanonicalURL, errorMap, isValidURL } from "./util.js";
const rssFeedItemValidator = rssSchema.extend({ link: z.string(), content: z.string().optional() });
const globResultValidator = z.record(z.function().returns(z.promise(z.any())));
const rssOptionsValidator = z.object({
title: z.string(),
description: z.string(),
site: z.preprocess((url) => url instanceof URL ? url.href : url, z.string().url()),
items: z.array(rssFeedItemValidator).or(globResultValidator).transform((items) => {
if (!Array.isArray(items)) {
console.warn(
yellow(
"[RSS] Passing a glob result directly has been deprecated. Please migrate to the `pagesGlobToRssItems()` helper: https://docs.astro.build/en/guides/rss/"
)
);
return pagesGlobToRssItems(items);
}
return items;
}),
xmlns: z.record(z.string()).optional(),
drafts: z.boolean().default(false),
stylesheet: z.union([z.string(), z.boolean()]).optional(),
customData: z.string().optional(),
trailingSlash: z.boolean().default(true)
});
async function getRSS(rssOptions) {
const validatedRssOptions = await validateRssOptions(rssOptions);
return {
body: await generateRSS(validatedRssOptions)
};
}
async function validateRssOptions(rssOptions) {
const parsedResult = await rssOptionsValidator.safeParseAsync(rssOptions, { errorMap });
if (parsedResult.success) {
return parsedResult.data;
}
const formattedError = new Error(
[
`[RSS] Invalid or missing options:`,
...parsedResult.error.errors.map(
(zodError) => `${zodError.message} (${zodError.path.join(".")})`
)
].join("\n")
);
throw formattedError;
}
function pagesGlobToRssItems(items) {
return Promise.all(
Object.entries(items).map(async ([filePath, getInfo]) => {
const { url, frontmatter } = await getInfo();
if (url === void 0 || url === null) {
throw new Error(
`[RSS] You can only glob entries within 'src/pages/' when passing import.meta.glob() directly. Consider mapping the result to an array of RSSFeedItems. See the RSS docs for usage examples: https://docs.astro.build/en/guides/rss/#2-list-of-rss-feed-objects`
);
}
const parsedResult = rssFeedItemValidator.safeParse(
{ ...frontmatter, link: url },
{ errorMap }
);
if (parsedResult.success) {
return parsedResult.data;
}
const formattedError = new Error(
[
`[RSS] ${filePath} has invalid or missing frontmatter.
Fix the following properties:`,
...parsedResult.error.errors.map((zodError) => zodError.message)
].join("\n")
);
formattedError.file = filePath;
throw formattedError;
})
);
}
async function generateRSS(rssOptions) {
var _a;
const { site } = rssOptions;
const items = rssOptions.drafts ? rssOptions.items : rssOptions.items.filter((item) => !item.draft);
const xmlOptions = {
ignoreAttributes: false,
// Avoid correcting self-closing tags to standard tags
// when using `customData`
// https://github.com/withastro/astro/issues/5794
suppressEmptyNode: true,
suppressBooleanAttributes: false
};
const parser = new XMLParser(xmlOptions);
const root = { "?xml": { "@_version": "1.0", "@_encoding": "UTF-8" } };
if (typeof rssOptions.stylesheet === "string") {
const isXSL = /\.xsl$/i.test(rssOptions.stylesheet);
root["?xml-stylesheet"] = {
"@_href": rssOptions.stylesheet,
...isXSL && { "@_type": "text/xsl" }
};
}
root.rss = { "@_version": "2.0" };
if (items.find((result) => result.content)) {
const XMLContentNamespace = "http://purl.org/rss/1.0/modules/content/";
root.rss["@_xmlns:content"] = XMLContentNamespace;
if (((_a = rssOptions.xmlns) == null ? void 0 : _a.content) && rssOptions.xmlns.content === XMLContentNamespace) {
delete rssOptions.xmlns.content;
}
}
if (rssOptions.xmlns) {
for (const [k, v] of Object.entries(rssOptions.xmlns)) {
root.rss[`@_xmlns:${k}`] = v;
}
}
root.rss.channel = {
title: rssOptions.title,
description: rssOptions.description,
link: createCanonicalURL(site, rssOptions.trailingSlash, void 0).href
};
if (typeof rssOptions.customData === "string")
Object.assign(
root.rss.channel,
parser.parse(`<channel>${rssOptions.customData}</channel>`).channel
);
root.rss.channel.item = items.map((result) => {
const itemLink = isValidURL(result.link) ? result.link : createCanonicalURL(result.link, rssOptions.trailingSlash, site).href;
const item = {
title: result.title,
link: itemLink,
guid: { "#text": itemLink, "@_isPermaLink": "true" }
};
if (result.description) {
item.description = result.description;
}
if (result.pubDate) {
item.pubDate = result.pubDate.toUTCString();
}
if (typeof result.content === "string") {
item["content:encoded"] = result.content;
}
if (typeof result.customData === "string") {
Object.assign(item, parser.parse(`<item>${result.customData}</item>`).item);
}
if (Array.isArray(result.categories)) {
item.category = result.categories;
}
if (typeof result.author === "string") {
item.author = result.author;
}
if (typeof result.commentsUrl === "string") {
item.comments = isValidURL(result.commentsUrl) ? result.commentsUrl : createCanonicalURL(result.commentsUrl, rssOptions.trailingSlash, site).href;
}
if (result.source) {
item.source = parser.parse(
`<source url="${result.source.url}">${result.source.title}</source>`
).source;
}
if (result.enclosure) {
const enclosureURL = isValidURL(result.enclosure.url) ? result.enclosure.url : createCanonicalURL(result.enclosure.url, rssOptions.trailingSlash, site).href;
item.enclosure = parser.parse(
`<enclosure url="${enclosureURL}" length="${result.enclosure.length}" type="${result.enclosure.type}"/>`
).enclosure;
}
return item;
});
return new XMLBuilder(xmlOptions).build(root);
}
export {
getRSS as default,
pagesGlobToRssItems,
rssSchema
};

70
node_modules/@astrojs/rss/dist/schema.d.ts generated vendored Normal file
View file

@ -0,0 +1,70 @@
import { z } from 'astro/zod';
export declare const rssSchema: z.ZodObject<{
title: z.ZodString;
pubDate: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodDate]>, Date, string | number | Date>, Date, string | number | Date>;
description: z.ZodOptional<z.ZodString>;
customData: z.ZodOptional<z.ZodString>;
draft: z.ZodOptional<z.ZodBoolean>;
categories: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
author: z.ZodOptional<z.ZodString>;
commentsUrl: z.ZodOptional<z.ZodString>;
source: z.ZodOptional<z.ZodObject<{
url: z.ZodString;
title: z.ZodString;
}, "strip", z.ZodTypeAny, {
title: string;
url: string;
}, {
title: string;
url: string;
}>>;
enclosure: z.ZodOptional<z.ZodObject<{
url: z.ZodString;
length: z.ZodNumber;
type: z.ZodString;
}, "strip", z.ZodTypeAny, {
length: number;
type: string;
url: string;
}, {
length: number;
type: string;
url: string;
}>>;
}, "strip", z.ZodTypeAny, {
description?: string | undefined;
customData?: string | undefined;
draft?: boolean | undefined;
categories?: string[] | undefined;
author?: string | undefined;
commentsUrl?: string | undefined;
source?: {
title: string;
url: string;
} | undefined;
enclosure?: {
length: number;
type: string;
url: string;
} | undefined;
title: string;
pubDate: Date;
}, {
description?: string | undefined;
customData?: string | undefined;
draft?: boolean | undefined;
categories?: string[] | undefined;
author?: string | undefined;
commentsUrl?: string | undefined;
source?: {
title: string;
url: string;
} | undefined;
enclosure?: {
length: number;
type: string;
url: string;
} | undefined;
title: string;
pubDate: string | number | Date;
}>;

20
node_modules/@astrojs/rss/dist/schema.js generated vendored Normal file
View file

@ -0,0 +1,20 @@
import { z } from "astro/zod";
const rssSchema = z.object({
title: z.string(),
pubDate: z.union([z.string(), z.number(), z.date()]).transform((value) => new Date(value)).refine((value) => !isNaN(value.getTime())),
description: z.string().optional(),
customData: z.string().optional(),
draft: z.boolean().optional(),
categories: z.array(z.string()).optional(),
author: z.string().optional(),
commentsUrl: z.string().optional(),
source: z.object({ url: z.string().url(), title: z.string() }).optional(),
enclosure: z.object({
url: z.string(),
length: z.number().positive().int().finite(),
type: z.string()
}).optional()
});
export {
rssSchema
};

7
node_modules/@astrojs/rss/dist/util.d.ts generated vendored Normal file
View file

@ -0,0 +1,7 @@
import type { z } from 'astro/zod';
import type { RSSOptions } from './index';
/** Normalize URL to its canonical form */
export declare function createCanonicalURL(url: string, trailingSlash?: RSSOptions['trailingSlash'], base?: string): URL;
/** Check if a URL is already valid */
export declare function isValidURL(url: string): boolean;
export declare const errorMap: z.ZodErrorMap;

40
node_modules/@astrojs/rss/dist/util.js generated vendored Normal file
View file

@ -0,0 +1,40 @@
function createCanonicalURL(url, trailingSlash, base) {
let pathname = url.replace(/\/index.html$/, "");
if (trailingSlash === false) {
pathname = pathname.replace(/(\/+)?$/, "");
} else if (!getUrlExtension(url)) {
pathname = pathname.replace(/(\/+)?$/, "/");
}
pathname = pathname.replace(/\/+/g, "/");
return new URL(pathname, base);
}
function isValidURL(url) {
try {
new URL(url);
return true;
} catch (e) {
}
return false;
}
function getUrlExtension(url) {
const lastDot = url.lastIndexOf(".");
const lastSlash = url.lastIndexOf("/");
return lastDot > lastSlash ? url.slice(lastDot + 1) : "";
}
const flattenErrorPath = (errorPath) => errorPath.join(".");
const errorMap = (error, ctx) => {
if (error.code === "invalid_type") {
const badKeyPath = JSON.stringify(flattenErrorPath(error.path));
if (error.received === "undefined") {
return { message: `${badKeyPath} is required.` };
} else {
return { message: `${badKeyPath} should be ${error.expected}, not ${error.received}.` };
}
}
return { message: ctx.defaultError };
};
export {
createCanonicalURL,
errorMap,
isValidURL
};

1
node_modules/@astrojs/rss/node_modules/.bin/fxparser generated vendored Symbolic link
View file

@ -0,0 +1 @@
../../../../fast-xml-parser/src/cli/cli.js

44
node_modules/@astrojs/rss/package.json generated vendored Normal file
View file

@ -0,0 +1,44 @@
{
"name": "@astrojs/rss",
"description": "Add RSS feeds to your Astro projects",
"version": "2.4.3",
"type": "module",
"types": "./dist/index.d.ts",
"author": "withastro",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/withastro/astro.git",
"directory": "packages/astro-rss"
},
"bugs": "https://github.com/withastro/astro/issues",
"homepage": "https://astro.build",
"exports": {
".": "./dist/index.js",
"./package.json": "./package.json"
},
"files": [
"dist"
],
"devDependencies": {
"@types/chai": "^4.3.1",
"@types/chai-as-promised": "^7.1.5",
"@types/mocha": "^9.1.1",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"chai-xml": "^0.4.0",
"mocha": "^9.2.2",
"astro": "2.5.2",
"astro-scripts": "0.0.14"
},
"dependencies": {
"fast-xml-parser": "^4.0.8",
"kleur": "^4.1.5"
},
"scripts": {
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
"build:ci": "astro-scripts build \"src/**/*.ts\"",
"dev": "astro-scripts dev \"src/**/*.ts\"",
"test": "mocha --exit --timeout 20000"
}
}