🎉 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

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
};