website hosted
This commit is contained in:
59
node_modules/@astrojs/node/LICENSE
generated
vendored
Normal file
59
node_modules/@astrojs/node/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
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.
|
||||
"""
|
||||
38
node_modules/@astrojs/node/README.md
generated
vendored
Normal file
38
node_modules/@astrojs/node/README.md
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
# @astrojs/node
|
||||
|
||||
This adapter allows Astro to deploy your SSR site to Node targets.
|
||||
|
||||
## Documentation
|
||||
|
||||
Read the [`@astrojs/node` docs][docs]
|
||||
|
||||
## Support
|
||||
|
||||
- Get help in the [Astro Discord][discord]. Post questions in our `#support` forum, or visit our dedicated `#dev` channel to discuss current development and more!
|
||||
|
||||
- Check our [Astro Integration Documentation][astro-integration] for more on integrations.
|
||||
|
||||
- Submit bug reports and feature requests as [GitHub issues][issues].
|
||||
|
||||
## Contributing
|
||||
|
||||
This package is maintained by Astro's Core team. You're welcome to submit an issue or PR! These links will help you get started:
|
||||
|
||||
- [Contributor Manual][contributing]
|
||||
- [Code of Conduct][coc]
|
||||
- [Community Guide][community]
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
Copyright (c) 2023–present [Astro][astro]
|
||||
|
||||
[astro]: https://astro.build/
|
||||
[docs]: https://docs.astro.build/en/guides/integrations-guide/node/
|
||||
[contributing]: https://github.com/withastro/astro/blob/main/CONTRIBUTING.md
|
||||
[coc]: https://github.com/withastro/.github/blob/main/CODE_OF_CONDUCT.md
|
||||
[community]: https://github.com/withastro/.github/blob/main/COMMUNITY_GUIDE.md
|
||||
[discord]: https://astro.build/chat/
|
||||
[issues]: https://github.com/withastro/astro/issues
|
||||
[astro-integration]: https://docs.astro.build/en/guides/integrations-guide/
|
||||
4
node_modules/@astrojs/node/dist/index.d.ts
generated
vendored
Normal file
4
node_modules/@astrojs/node/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { AstroAdapter, AstroIntegration } from 'astro';
|
||||
import type { Options, UserOptions } from './types.js';
|
||||
export declare function getAdapter(options: Options): AstroAdapter;
|
||||
export default function createIntegration(userOptions: UserOptions): AstroIntegration;
|
||||
123
node_modules/@astrojs/node/dist/index.js
generated
vendored
Normal file
123
node_modules/@astrojs/node/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { writeJson } from "@astrojs/internal-helpers/fs";
|
||||
import { AstroError } from "astro/errors";
|
||||
import { STATIC_HEADERS_FILE } from "./shared.js";
|
||||
function getAdapter(options) {
|
||||
return {
|
||||
name: "@astrojs/node",
|
||||
serverEntrypoint: "@astrojs/node/server.js",
|
||||
previewEntrypoint: "@astrojs/node/preview.js",
|
||||
exports: ["handler", "startServer", "options"],
|
||||
args: options,
|
||||
adapterFeatures: {
|
||||
buildOutput: "server",
|
||||
edgeMiddleware: false,
|
||||
experimentalStaticHeaders: options.experimentalStaticHeaders
|
||||
},
|
||||
supportedAstroFeatures: {
|
||||
hybridOutput: "stable",
|
||||
staticOutput: "stable",
|
||||
serverOutput: "stable",
|
||||
sharpImageService: "stable",
|
||||
i18nDomains: "experimental",
|
||||
envGetSecret: "stable"
|
||||
}
|
||||
};
|
||||
}
|
||||
const protocols = ["http:", "https:"];
|
||||
function createIntegration(userOptions) {
|
||||
if (!userOptions?.mode) {
|
||||
throw new AstroError(`Setting the 'mode' option is required.`);
|
||||
}
|
||||
const { experimentalErrorPageHost } = userOptions;
|
||||
if (experimentalErrorPageHost && (!URL.canParse(experimentalErrorPageHost) || !protocols.includes(new URL(experimentalErrorPageHost).protocol))) {
|
||||
throw new AstroError(
|
||||
`Invalid experimentalErrorPageHost: ${experimentalErrorPageHost}. It should be a valid URL.`
|
||||
);
|
||||
}
|
||||
let _options;
|
||||
let _config = void 0;
|
||||
let _routeToHeaders = void 0;
|
||||
return {
|
||||
name: "@astrojs/node",
|
||||
hooks: {
|
||||
"astro:config:setup": async ({ updateConfig, config, logger, command }) => {
|
||||
let session = config.session;
|
||||
_config = config;
|
||||
if (!session?.driver) {
|
||||
logger.info("Enabling sessions with filesystem storage");
|
||||
session = {
|
||||
...session,
|
||||
driver: "fs-lite",
|
||||
options: {
|
||||
base: fileURLToPath(new URL("sessions", config.cacheDir))
|
||||
}
|
||||
};
|
||||
}
|
||||
updateConfig({
|
||||
build: {
|
||||
redirects: false
|
||||
},
|
||||
image: {
|
||||
endpoint: {
|
||||
route: config.image.endpoint.route ?? "_image",
|
||||
entrypoint: config.image.endpoint.entrypoint ?? (command === "dev" ? "astro/assets/endpoint/dev" : "astro/assets/endpoint/node")
|
||||
}
|
||||
},
|
||||
session,
|
||||
vite: {
|
||||
ssr: {
|
||||
noExternal: ["@astrojs/node"]
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
"astro:build:generated": ({ experimentalRouteToHeaders }) => {
|
||||
_routeToHeaders = experimentalRouteToHeaders;
|
||||
},
|
||||
"astro:config:done": ({ setAdapter, config }) => {
|
||||
_options = {
|
||||
...userOptions,
|
||||
client: config.build.client?.toString(),
|
||||
server: config.build.server?.toString(),
|
||||
host: config.server.host,
|
||||
port: config.server.port,
|
||||
assets: config.build.assets,
|
||||
experimentalStaticHeaders: userOptions.experimentalStaticHeaders ?? false,
|
||||
experimentalErrorPageHost
|
||||
};
|
||||
setAdapter(getAdapter(_options));
|
||||
},
|
||||
"astro:build:done": async () => {
|
||||
if (!_config) {
|
||||
return;
|
||||
}
|
||||
if (_routeToHeaders && _routeToHeaders.size > 0) {
|
||||
const headersFileUrl = new URL(STATIC_HEADERS_FILE, _config.outDir);
|
||||
const headersValue = [];
|
||||
for (const [pathname, { headers }] of _routeToHeaders.entries()) {
|
||||
if (_config.experimental.csp) {
|
||||
const csp = headers.get("Content-Security-Policy");
|
||||
if (csp) {
|
||||
headersValue.push({
|
||||
pathname,
|
||||
headers: [
|
||||
{
|
||||
key: "Content-Security-Policy",
|
||||
value: csp
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
await writeJson(headersFileUrl, headersValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
export {
|
||||
createIntegration as default,
|
||||
getAdapter
|
||||
};
|
||||
4
node_modules/@astrojs/node/dist/log-listening-on.d.ts
generated
vendored
Normal file
4
node_modules/@astrojs/node/dist/log-listening-on.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type http from 'node:http';
|
||||
import https from 'node:https';
|
||||
import type { AstroIntegrationLogger } from 'astro';
|
||||
export declare function logListeningOn(logger: AstroIntegrationLogger, server: http.Server | https.Server, configuredHost: string | boolean | undefined): Promise<void>;
|
||||
57
node_modules/@astrojs/node/dist/log-listening-on.js
generated
vendored
Normal file
57
node_modules/@astrojs/node/dist/log-listening-on.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
import https from "node:https";
|
||||
import os from "node:os";
|
||||
const wildcardHosts = /* @__PURE__ */ new Set(["0.0.0.0", "::", "0000:0000:0000:0000:0000:0000:0000:0000"]);
|
||||
async function logListeningOn(logger, server, configuredHost) {
|
||||
await new Promise((resolve) => server.once("listening", resolve));
|
||||
const protocol = server instanceof https.Server ? "https" : "http";
|
||||
const host = getResolvedHostForHttpServer(configuredHost);
|
||||
const { port } = server.address();
|
||||
const address = getNetworkAddress(protocol, host, port);
|
||||
if (host === void 0 || wildcardHosts.has(host)) {
|
||||
logger.info(
|
||||
`Server listening on
|
||||
local: ${address.local[0]}
|
||||
network: ${address.network[0]}
|
||||
`
|
||||
);
|
||||
} else {
|
||||
logger.info(`Server listening on ${address.local[0]}`);
|
||||
}
|
||||
}
|
||||
function getResolvedHostForHttpServer(host) {
|
||||
if (host === false) {
|
||||
return "localhost";
|
||||
} else if (host === true) {
|
||||
return void 0;
|
||||
} else {
|
||||
return host;
|
||||
}
|
||||
}
|
||||
function getNetworkAddress(protocol = "http", hostname, port, base) {
|
||||
const NetworkAddress = {
|
||||
local: [],
|
||||
network: []
|
||||
};
|
||||
Object.values(os.networkInterfaces()).flatMap((nInterface) => nInterface ?? []).filter(
|
||||
(detail) => detail && detail.address && (detail.family === "IPv4" || // @ts-expect-error Node 18.0 - 18.3 returns number
|
||||
detail.family === 4)
|
||||
).forEach((detail) => {
|
||||
let host = detail.address.replace(
|
||||
"127.0.0.1",
|
||||
hostname === void 0 || wildcardHosts.has(hostname) ? "localhost" : hostname
|
||||
);
|
||||
if (host.includes(":")) {
|
||||
host = `[${host}]`;
|
||||
}
|
||||
const url = `${protocol}://${host}:${port}${base ? base : ""}`;
|
||||
if (detail.address.includes("127.0.0.1")) {
|
||||
NetworkAddress.local.push(url);
|
||||
} else {
|
||||
NetworkAddress.network.push(url);
|
||||
}
|
||||
});
|
||||
return NetworkAddress;
|
||||
}
|
||||
export {
|
||||
logListeningOn
|
||||
};
|
||||
11
node_modules/@astrojs/node/dist/middleware.d.ts
generated
vendored
Normal file
11
node_modules/@astrojs/node/dist/middleware.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import type { NodeApp } from 'astro/app/node';
|
||||
import type { Options, RequestHandler } from './types.js';
|
||||
/**
|
||||
* Creates a middleware that can be used with Express, Connect, etc.
|
||||
*
|
||||
* Similar to `createAppHandler` but can additionally be placed in the express
|
||||
* chain as an error middleware.
|
||||
*
|
||||
* https://expressjs.com/en/guide/using-middleware.html#middleware.error-handling
|
||||
*/
|
||||
export default function createMiddleware(app: NodeApp, options: Options): RequestHandler;
|
||||
29
node_modules/@astrojs/node/dist/middleware.js
generated
vendored
Normal file
29
node_modules/@astrojs/node/dist/middleware.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createAppHandler } from "./serve-app.js";
|
||||
function createMiddleware(app, options) {
|
||||
const handler = createAppHandler(app, options);
|
||||
const logger = app.getAdapterLogger();
|
||||
return async (...args) => {
|
||||
const [req, res, next, locals] = args;
|
||||
if (req instanceof Error) {
|
||||
const error = req;
|
||||
if (next) {
|
||||
return next(error);
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
try {
|
||||
await handler(req, res, next, locals);
|
||||
} catch (err) {
|
||||
logger.error(`Could not render ${req.url}`);
|
||||
console.error(err);
|
||||
if (!res.headersSent) {
|
||||
res.writeHead(500, `Server error`);
|
||||
res.end();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
export {
|
||||
createMiddleware as default
|
||||
};
|
||||
1
node_modules/@astrojs/node/dist/polyfill.d.ts
generated
vendored
Normal file
1
node_modules/@astrojs/node/dist/polyfill.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
2
node_modules/@astrojs/node/dist/polyfill.js
generated
vendored
Normal file
2
node_modules/@astrojs/node/dist/polyfill.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { applyPolyfills } from "astro/app/node";
|
||||
applyPolyfills();
|
||||
3
node_modules/@astrojs/node/dist/preview.d.ts
generated
vendored
Normal file
3
node_modules/@astrojs/node/dist/preview.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { CreatePreviewServer } from 'astro';
|
||||
declare const createPreviewServer: CreatePreviewServer;
|
||||
export { createPreviewServer as default };
|
||||
50
node_modules/@astrojs/node/dist/preview.js
generated
vendored
Normal file
50
node_modules/@astrojs/node/dist/preview.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { AstroError } from "astro/errors";
|
||||
import { logListeningOn } from "./log-listening-on.js";
|
||||
import { createServer } from "./standalone.js";
|
||||
const createPreviewServer = async (preview) => {
|
||||
let ssrHandler;
|
||||
try {
|
||||
process.env.ASTRO_NODE_AUTOSTART = "disabled";
|
||||
const ssrModule = await import(preview.serverEntrypoint.toString());
|
||||
if (typeof ssrModule.handler === "function") {
|
||||
ssrHandler = ssrModule.handler;
|
||||
} else {
|
||||
throw new AstroError(
|
||||
`The server entrypoint doesn't have a handler. Are you sure this is the right file?`
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
if (err.code === "ERR_MODULE_NOT_FOUND" && err.url === preview.serverEntrypoint.href) {
|
||||
throw new AstroError(
|
||||
`The server entrypoint ${fileURLToPath(
|
||||
preview.serverEntrypoint
|
||||
)} does not exist. Have you ran a build yet?`
|
||||
);
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
const host = process.env.HOST ?? preview.host ?? "0.0.0.0";
|
||||
const port = preview.port ?? 4321;
|
||||
const server = createServer(ssrHandler, host, port);
|
||||
if (preview.headers) {
|
||||
server.server.addListener("request", (_, res) => {
|
||||
if (res.statusCode === 200) {
|
||||
for (const [name, value] of Object.entries(preview.headers ?? {})) {
|
||||
if (value) res.setHeader(name, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
logListeningOn(preview.logger, server.server, host);
|
||||
await new Promise((resolve, reject) => {
|
||||
server.server.once("listening", resolve);
|
||||
server.server.once("error", reject);
|
||||
server.server.listen(port, host);
|
||||
});
|
||||
return server;
|
||||
};
|
||||
export {
|
||||
createPreviewServer as default
|
||||
};
|
||||
8
node_modules/@astrojs/node/dist/serve-app.d.ts
generated
vendored
Normal file
8
node_modules/@astrojs/node/dist/serve-app.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { NodeApp } from 'astro/app/node';
|
||||
import type { Options, RequestHandler } from './types.js';
|
||||
/**
|
||||
* Creates a Node.js http listener for on-demand rendered pages, compatible with http.createServer and Connect middleware.
|
||||
* If the next callback is provided, it will be called if the request does not have a matching route.
|
||||
* Intended to be used in both standalone and middleware mode.
|
||||
*/
|
||||
export declare function createAppHandler(app: NodeApp, options: Options): RequestHandler;
|
||||
53
node_modules/@astrojs/node/dist/serve-app.js
generated
vendored
Normal file
53
node_modules/@astrojs/node/dist/serve-app.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
import { AsyncLocalStorage } from "node:async_hooks";
|
||||
import { NodeApp } from "astro/app/node";
|
||||
function createAppHandler(app, options) {
|
||||
const als = new AsyncLocalStorage();
|
||||
const logger = app.getAdapterLogger();
|
||||
process.on("unhandledRejection", (reason) => {
|
||||
const requestUrl = als.getStore();
|
||||
logger.error(`Unhandled rejection while rendering ${requestUrl}`);
|
||||
console.error(reason);
|
||||
});
|
||||
const originUrl = options.experimentalErrorPageHost ? new URL(options.experimentalErrorPageHost) : void 0;
|
||||
const prerenderedErrorPageFetch = originUrl ? (url) => {
|
||||
const errorPageUrl = new URL(url);
|
||||
errorPageUrl.protocol = originUrl.protocol;
|
||||
errorPageUrl.host = originUrl.host;
|
||||
return fetch(errorPageUrl);
|
||||
} : void 0;
|
||||
return async (req, res, next, locals) => {
|
||||
let request;
|
||||
try {
|
||||
request = NodeApp.createRequest(req, {
|
||||
allowedDomains: app.getAllowedDomains?.() ?? []
|
||||
});
|
||||
} catch (err) {
|
||||
logger.error(`Could not render ${req.url}`);
|
||||
console.error(err);
|
||||
res.statusCode = 500;
|
||||
res.end("Internal Server Error");
|
||||
return;
|
||||
}
|
||||
const routeData = app.match(request, true);
|
||||
if (routeData) {
|
||||
const response = await als.run(
|
||||
request.url,
|
||||
() => app.render(request, {
|
||||
addCookieHeader: true,
|
||||
locals,
|
||||
routeData,
|
||||
prerenderedErrorPageFetch
|
||||
})
|
||||
);
|
||||
await NodeApp.writeResponse(response, res);
|
||||
} else if (next) {
|
||||
return next();
|
||||
} else {
|
||||
const response = await app.render(req, { addCookieHeader: true, prerenderedErrorPageFetch });
|
||||
await NodeApp.writeResponse(response, res);
|
||||
}
|
||||
};
|
||||
}
|
||||
export {
|
||||
createAppHandler
|
||||
};
|
||||
10
node_modules/@astrojs/node/dist/serve-static.d.ts
generated
vendored
Normal file
10
node_modules/@astrojs/node/dist/serve-static.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { IncomingMessage, ServerResponse } from 'node:http';
|
||||
import type { NodeApp } from 'astro/app/node';
|
||||
import type { Options } from './types.js';
|
||||
/**
|
||||
* Creates a Node.js http listener for static files and prerendered pages.
|
||||
* In standalone mode, the static handler is queried first for the static files.
|
||||
* If one matching the request path is not found, it relegates to the SSR handler.
|
||||
* Intended to be used only in the standalone mode.
|
||||
*/
|
||||
export declare function createStaticHandler(app: NodeApp, options: Options): (req: IncomingMessage, res: ServerResponse, ssr: () => unknown) => ServerResponse<IncomingMessage> | undefined;
|
||||
111
node_modules/@astrojs/node/dist/serve-static.js
generated
vendored
Normal file
111
node_modules/@astrojs/node/dist/serve-static.js
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import url from "node:url";
|
||||
import { hasFileExtension, isInternalPath } from "@astrojs/internal-helpers/path";
|
||||
import send from "send";
|
||||
function createStaticHandler(app, options) {
|
||||
const client = resolveClientDir(options);
|
||||
return (req, res, ssr) => {
|
||||
if (req.url) {
|
||||
const [urlPath, urlQuery] = req.url.split("?");
|
||||
const filePath = path.join(client, app.removeBase(urlPath));
|
||||
let isDirectory = false;
|
||||
try {
|
||||
isDirectory = fs.lstatSync(filePath).isDirectory();
|
||||
} catch {
|
||||
}
|
||||
const { trailingSlash = "ignore" } = options;
|
||||
const hasSlash = urlPath.endsWith("/");
|
||||
let pathname = urlPath;
|
||||
if (app.headersMap && app.headersMap.length > 0) {
|
||||
const routeData = app.match(req, true);
|
||||
if (routeData && routeData.prerender) {
|
||||
const matchedRoute = app.headersMap.find((header) => header.pathname.includes(pathname));
|
||||
if (matchedRoute) {
|
||||
for (const header of matchedRoute.headers) {
|
||||
res.setHeader(header.key, header.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (trailingSlash) {
|
||||
case "never": {
|
||||
if (isDirectory && urlPath !== "/" && hasSlash) {
|
||||
pathname = urlPath.slice(0, -1) + (urlQuery ? "?" + urlQuery : "");
|
||||
res.statusCode = 301;
|
||||
res.setHeader("Location", pathname);
|
||||
return res.end();
|
||||
}
|
||||
if (isDirectory && !hasSlash) {
|
||||
pathname = `${urlPath}/index.html`;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "ignore": {
|
||||
if (isDirectory && !hasSlash) {
|
||||
pathname = `${urlPath}/index.html`;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "always": {
|
||||
if (!hasSlash && !hasFileExtension(urlPath) && !isInternalPath(urlPath)) {
|
||||
pathname = urlPath + "/" + (urlQuery ? "?" + urlQuery : "");
|
||||
res.statusCode = 301;
|
||||
res.setHeader("Location", pathname);
|
||||
return res.end();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
pathname = prependForwardSlash(app.removeBase(pathname));
|
||||
const stream = send(req, pathname, {
|
||||
root: client,
|
||||
dotfiles: pathname.startsWith("/.well-known/") ? "allow" : "deny"
|
||||
});
|
||||
let forwardError = false;
|
||||
stream.on("error", (err) => {
|
||||
if (forwardError) {
|
||||
console.error(err.toString());
|
||||
res.writeHead(500);
|
||||
res.end("Internal server error");
|
||||
return;
|
||||
}
|
||||
ssr();
|
||||
});
|
||||
stream.on("headers", (_res) => {
|
||||
if (pathname.startsWith(`/${options.assets}/`)) {
|
||||
_res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
|
||||
}
|
||||
});
|
||||
stream.on("file", () => {
|
||||
forwardError = true;
|
||||
});
|
||||
stream.pipe(res);
|
||||
} else {
|
||||
ssr();
|
||||
}
|
||||
};
|
||||
}
|
||||
function resolveClientDir(options) {
|
||||
const clientURLRaw = new URL(options.client);
|
||||
const serverURLRaw = new URL(options.server);
|
||||
const rel = path.relative(url.fileURLToPath(serverURLRaw), url.fileURLToPath(clientURLRaw));
|
||||
const serverFolder = path.basename(options.server);
|
||||
let serverEntryFolderURL = path.dirname(import.meta.url);
|
||||
while (!serverEntryFolderURL.endsWith(serverFolder)) {
|
||||
serverEntryFolderURL = path.dirname(serverEntryFolderURL);
|
||||
}
|
||||
const serverEntryURL = serverEntryFolderURL + "/entry.mjs";
|
||||
const clientURL = new URL(appendForwardSlash(rel), serverEntryURL);
|
||||
const client = url.fileURLToPath(clientURL);
|
||||
return client;
|
||||
}
|
||||
function prependForwardSlash(pth) {
|
||||
return pth.startsWith("/") ? pth : "/" + pth;
|
||||
}
|
||||
function appendForwardSlash(pth) {
|
||||
return pth.endsWith("/") ? pth : pth + "/";
|
||||
}
|
||||
export {
|
||||
createStaticHandler
|
||||
};
|
||||
18
node_modules/@astrojs/node/dist/server.d.ts
generated
vendored
Normal file
18
node_modules/@astrojs/node/dist/server.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import './polyfill.js';
|
||||
import type { SSRManifest } from 'astro';
|
||||
import type { Options } from './types.js';
|
||||
export declare function createExports(manifest: SSRManifest, options: Options): {
|
||||
options: Options;
|
||||
handler: import("./types.js").RequestHandler;
|
||||
startServer: () => {
|
||||
server: {
|
||||
host: string;
|
||||
port: number;
|
||||
closed(): Promise<void>;
|
||||
stop(): Promise<void>;
|
||||
server: import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | import("https").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
|
||||
};
|
||||
done: Promise<void>;
|
||||
};
|
||||
};
|
||||
export declare function start(manifest: SSRManifest, options: Options): void;
|
||||
56
node_modules/@astrojs/node/dist/server.js
generated
vendored
Normal file
56
node_modules/@astrojs/node/dist/server.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
import "./polyfill.js";
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import { NodeApp } from "astro/app/node";
|
||||
import { setGetEnv } from "astro/env/setup";
|
||||
import createMiddleware from "./middleware.js";
|
||||
import { STATIC_HEADERS_FILE } from "./shared.js";
|
||||
import startServer, { createStandaloneHandler } from "./standalone.js";
|
||||
setGetEnv((key) => process.env[key]);
|
||||
function createExports(manifest, options) {
|
||||
const app = new NodeApp(manifest, !options.experimentalDisableStreaming);
|
||||
let headersMap = void 0;
|
||||
if (options.experimentalStaticHeaders) {
|
||||
headersMap = readHeadersJson(manifest.outDir);
|
||||
}
|
||||
if (headersMap) {
|
||||
app.setHeadersMap(headersMap);
|
||||
}
|
||||
options.trailingSlash = manifest.trailingSlash;
|
||||
return {
|
||||
options,
|
||||
handler: options.mode === "middleware" ? createMiddleware(app, options) : createStandaloneHandler(app, options),
|
||||
startServer: () => startServer(app, options)
|
||||
};
|
||||
}
|
||||
function start(manifest, options) {
|
||||
if (options.mode !== "standalone" || process.env.ASTRO_NODE_AUTOSTART === "disabled") {
|
||||
return;
|
||||
}
|
||||
let headersMap = void 0;
|
||||
if (options.experimentalStaticHeaders) {
|
||||
headersMap = readHeadersJson(manifest.outDir);
|
||||
}
|
||||
const app = new NodeApp(manifest, !options.experimentalDisableStreaming);
|
||||
if (headersMap) {
|
||||
app.setHeadersMap(headersMap);
|
||||
}
|
||||
startServer(app, options);
|
||||
}
|
||||
function readHeadersJson(outDir) {
|
||||
let headersMap = void 0;
|
||||
const headersUrl = new URL(STATIC_HEADERS_FILE, outDir);
|
||||
if (existsSync(headersUrl)) {
|
||||
const content = readFileSync(headersUrl, "utf-8");
|
||||
try {
|
||||
headersMap = JSON.parse(content);
|
||||
} catch (e) {
|
||||
console.error("[@astrojs/node] Error parsing _headers.json: " + e.message);
|
||||
console.error("[@astrojs/node] Please make sure your _headers.json is valid JSON.");
|
||||
}
|
||||
}
|
||||
return headersMap;
|
||||
}
|
||||
export {
|
||||
createExports,
|
||||
start
|
||||
};
|
||||
1
node_modules/@astrojs/node/dist/shared.d.ts
generated
vendored
Normal file
1
node_modules/@astrojs/node/dist/shared.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const STATIC_HEADERS_FILE = "_experimentalHeaders.json";
|
||||
4
node_modules/@astrojs/node/dist/shared.js
generated
vendored
Normal file
4
node_modules/@astrojs/node/dist/shared.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
const STATIC_HEADERS_FILE = "_experimentalHeaders.json";
|
||||
export {
|
||||
STATIC_HEADERS_FILE
|
||||
};
|
||||
23
node_modules/@astrojs/node/dist/standalone.d.ts
generated
vendored
Normal file
23
node_modules/@astrojs/node/dist/standalone.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import http from 'node:http';
|
||||
import https from 'node:https';
|
||||
import type { NodeApp } from 'astro/app/node';
|
||||
import type { Options } from './types.js';
|
||||
export declare const hostOptions: (host: Options["host"]) => string;
|
||||
export default function standalone(app: NodeApp, options: Options): {
|
||||
server: {
|
||||
host: string;
|
||||
port: number;
|
||||
closed(): Promise<void>;
|
||||
stop(): Promise<void>;
|
||||
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse> | https.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
||||
};
|
||||
done: Promise<void>;
|
||||
};
|
||||
export declare function createStandaloneHandler(app: NodeApp, options: Options): (req: http.IncomingMessage, res: http.ServerResponse) => void;
|
||||
export declare function createServer(listener: http.RequestListener, host: string, port: number): {
|
||||
host: string;
|
||||
port: number;
|
||||
closed(): Promise<void>;
|
||||
stop(): Promise<void>;
|
||||
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse> | https.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
||||
};
|
||||
82
node_modules/@astrojs/node/dist/standalone.js
generated
vendored
Normal file
82
node_modules/@astrojs/node/dist/standalone.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
import fs from "node:fs";
|
||||
import http from "node:http";
|
||||
import https from "node:https";
|
||||
import enableDestroy from "server-destroy";
|
||||
import { logListeningOn } from "./log-listening-on.js";
|
||||
import { createAppHandler } from "./serve-app.js";
|
||||
import { createStaticHandler } from "./serve-static.js";
|
||||
const hostOptions = (host) => {
|
||||
if (typeof host === "boolean") {
|
||||
return host ? "0.0.0.0" : "localhost";
|
||||
}
|
||||
return host;
|
||||
};
|
||||
function standalone(app, options) {
|
||||
const port = process.env.PORT ? Number(process.env.PORT) : options.port ?? 8080;
|
||||
const host = process.env.HOST ?? hostOptions(options.host);
|
||||
const handler = createStandaloneHandler(app, options);
|
||||
const server = createServer(handler, host, port);
|
||||
server.server.listen(port, host);
|
||||
if (process.env.ASTRO_NODE_LOGGING !== "disabled") {
|
||||
logListeningOn(app.getAdapterLogger(), server.server, host);
|
||||
}
|
||||
return {
|
||||
server,
|
||||
done: server.closed()
|
||||
};
|
||||
}
|
||||
function createStandaloneHandler(app, options) {
|
||||
const appHandler = createAppHandler(app, options);
|
||||
const staticHandler = createStaticHandler(app, options);
|
||||
return (req, res) => {
|
||||
try {
|
||||
decodeURI(req.url);
|
||||
} catch {
|
||||
res.writeHead(400);
|
||||
res.end("Bad request.");
|
||||
return;
|
||||
}
|
||||
staticHandler(req, res, () => appHandler(req, res));
|
||||
};
|
||||
}
|
||||
function createServer(listener, host, port) {
|
||||
let httpServer;
|
||||
if (process.env.SERVER_CERT_PATH && process.env.SERVER_KEY_PATH) {
|
||||
httpServer = https.createServer(
|
||||
{
|
||||
key: fs.readFileSync(process.env.SERVER_KEY_PATH),
|
||||
cert: fs.readFileSync(process.env.SERVER_CERT_PATH)
|
||||
},
|
||||
listener
|
||||
);
|
||||
} else {
|
||||
httpServer = http.createServer(listener);
|
||||
}
|
||||
enableDestroy(httpServer);
|
||||
const closed = new Promise((resolve, reject) => {
|
||||
httpServer.addListener("close", resolve);
|
||||
httpServer.addListener("error", reject);
|
||||
});
|
||||
const previewable = {
|
||||
host,
|
||||
port,
|
||||
closed() {
|
||||
return closed;
|
||||
},
|
||||
async stop() {
|
||||
await new Promise((resolve, reject) => {
|
||||
httpServer.destroy((err) => err ? reject(err) : resolve(void 0));
|
||||
});
|
||||
}
|
||||
};
|
||||
return {
|
||||
server: httpServer,
|
||||
...previewable
|
||||
};
|
||||
}
|
||||
export {
|
||||
createServer,
|
||||
createStandaloneHandler,
|
||||
standalone as default,
|
||||
hostOptions
|
||||
};
|
||||
47
node_modules/@astrojs/node/dist/types.d.ts
generated
vendored
Normal file
47
node_modules/@astrojs/node/dist/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
import type { IncomingMessage, ServerResponse } from 'node:http';
|
||||
import type { SSRManifest } from 'astro';
|
||||
export interface UserOptions {
|
||||
/**
|
||||
* Specifies the mode that the adapter builds to.
|
||||
*
|
||||
* - 'middleware' - Build to middleware, to be used within another Node.js server, such as Express.
|
||||
* - 'standalone' - Build to a standalone server. The server starts up just by running the built script.
|
||||
*/
|
||||
mode: 'middleware' | 'standalone';
|
||||
/**
|
||||
* Disables HTML streaming. This is useful for example if there are constraints from your host.
|
||||
*/
|
||||
experimentalDisableStreaming?: boolean;
|
||||
/**
|
||||
* If enabled, the adapter will save [static headers in the framework API file](https://docs.netlify.com/frameworks-api/#headers).
|
||||
*
|
||||
* Here the list of the headers that are added:
|
||||
* - The CSP header of the static pages is added when CSP support is enabled.
|
||||
*/
|
||||
experimentalStaticHeaders?: boolean;
|
||||
/**
|
||||
* The host that should be used if the server needs to fetch the prerendered error page.
|
||||
* If not provided, this will default to the host of the server. This should be set if the server
|
||||
* should fetch prerendered error pages from a different host than the public URL of the server.
|
||||
* This is useful for example if the server is behind a reverse proxy or a load balancer, or if
|
||||
* static files are hosted on a different domain. Do not include a path in the URL: it will be ignored.
|
||||
*/
|
||||
experimentalErrorPageHost?: string | URL;
|
||||
}
|
||||
export interface Options extends UserOptions {
|
||||
host: string | boolean;
|
||||
port: number;
|
||||
server: string;
|
||||
client: string;
|
||||
assets: string;
|
||||
trailingSlash?: SSRManifest['trailingSlash'];
|
||||
experimentalStaticHeaders: boolean;
|
||||
}
|
||||
export type RequestHandler = (...args: RequestHandlerParams) => void | Promise<void>;
|
||||
type RequestHandlerParams = [
|
||||
req: IncomingMessage,
|
||||
res: ServerResponse,
|
||||
next?: (err?: unknown) => void,
|
||||
locals?: object
|
||||
];
|
||||
export {};
|
||||
0
node_modules/@astrojs/node/dist/types.js
generated
vendored
Normal file
0
node_modules/@astrojs/node/dist/types.js
generated
vendored
Normal file
57
node_modules/@astrojs/node/package.json
generated
vendored
Normal file
57
node_modules/@astrojs/node/package.json
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"name": "@astrojs/node",
|
||||
"description": "Deploy your site to a Node.js server",
|
||||
"version": "9.5.0",
|
||||
"type": "module",
|
||||
"types": "./dist/index.d.ts",
|
||||
"author": "withastro",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/withastro/astro.git",
|
||||
"directory": "packages/integrations/node"
|
||||
},
|
||||
"keywords": [
|
||||
"withastro",
|
||||
"astro-adapter"
|
||||
],
|
||||
"bugs": "https://github.com/withastro/astro/issues",
|
||||
"homepage": "https://docs.astro.build/en/guides/integrations-guide/node/",
|
||||
"exports": {
|
||||
".": "./dist/index.js",
|
||||
"./server.js": "./dist/server.js",
|
||||
"./preview.js": "./dist/preview.js",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"send": "^1.2.0",
|
||||
"server-destroy": "^1.0.1",
|
||||
"@astrojs/internal-helpers": "0.7.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"astro": "^5.14.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.10.6",
|
||||
"@types/send": "^0.17.5",
|
||||
"@types/server-destroy": "^1.0.4",
|
||||
"cheerio": "1.1.2",
|
||||
"devalue": "^5.3.2",
|
||||
"express": "^4.21.2",
|
||||
"node-mocks-http": "^1.17.2",
|
||||
"astro": "5.14.5",
|
||||
"astro-scripts": "0.0.14"
|
||||
},
|
||||
"publishConfig": {
|
||||
"provenance": true
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "astro-scripts dev \"src/**/*.ts\"",
|
||||
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
|
||||
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
||||
"test": "astro-scripts test \"test/**/*.test.js\""
|
||||
}
|
||||
}
|
||||
59
node_modules/@astrojs/sitemap/LICENSE
generated
vendored
Normal file
59
node_modules/@astrojs/sitemap/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
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.
|
||||
"""
|
||||
38
node_modules/@astrojs/sitemap/README.md
generated
vendored
Normal file
38
node_modules/@astrojs/sitemap/README.md
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
# @astrojs/sitemap 🗺
|
||||
|
||||
This **[Astro integration][astro-integration]** generates a sitemap based on your pages when you build your Astro project.
|
||||
|
||||
## Documentation
|
||||
|
||||
Read the [`@astrojs/sitemap` docs][docs]
|
||||
|
||||
## Support
|
||||
|
||||
- Get help in the [Astro Discord][discord]. Post questions in our `#support` forum, or visit our dedicated `#dev` channel to discuss current development and more!
|
||||
|
||||
- Check our [Astro Integration Documentation][astro-integration] for more on integrations.
|
||||
|
||||
- Submit bug reports and feature requests as [GitHub issues][issues].
|
||||
|
||||
## Contributing
|
||||
|
||||
This package is maintained by Astro's Core team. You're welcome to submit an issue or PR! These links will help you get started:
|
||||
|
||||
- [Contributor Manual][contributing]
|
||||
- [Code of Conduct][coc]
|
||||
- [Community Guide][community]
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
Copyright (c) 2023–present [Astro][astro]
|
||||
|
||||
[astro]: https://astro.build/
|
||||
[docs]: https://docs.astro.build/en/guides/integrations-guide/sitemap/
|
||||
[contributing]: https://github.com/withastro/astro/blob/main/CONTRIBUTING.md
|
||||
[coc]: https://github.com/withastro/.github/blob/main/CODE_OF_CONDUCT.md
|
||||
[community]: https://github.com/withastro/.github/blob/main/COMMUNITY_GUIDE.md
|
||||
[discord]: https://astro.build/chat/
|
||||
[issues]: https://github.com/withastro/astro/issues
|
||||
[astro-integration]: https://docs.astro.build/en/guides/integrations-guide/
|
||||
10
node_modules/@astrojs/sitemap/dist/config-defaults.d.ts
generated
vendored
Normal file
10
node_modules/@astrojs/sitemap/dist/config-defaults.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
export declare const SITEMAP_CONFIG_DEFAULTS: {
|
||||
filenameBase: string;
|
||||
entryLimit: number;
|
||||
namespaces: {
|
||||
news: true;
|
||||
xhtml: true;
|
||||
image: true;
|
||||
video: true;
|
||||
};
|
||||
};
|
||||
13
node_modules/@astrojs/sitemap/dist/config-defaults.js
generated
vendored
Normal file
13
node_modules/@astrojs/sitemap/dist/config-defaults.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
const SITEMAP_CONFIG_DEFAULTS = {
|
||||
filenameBase: "sitemap",
|
||||
entryLimit: 45e3,
|
||||
namespaces: {
|
||||
news: true,
|
||||
xhtml: true,
|
||||
image: true,
|
||||
video: true
|
||||
}
|
||||
};
|
||||
export {
|
||||
SITEMAP_CONFIG_DEFAULTS
|
||||
};
|
||||
3
node_modules/@astrojs/sitemap/dist/generate-sitemap.d.ts
generated
vendored
Normal file
3
node_modules/@astrojs/sitemap/dist/generate-sitemap.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { SitemapItem, SitemapOptions } from './index.js';
|
||||
/** Construct sitemap.xml given a set of URLs */
|
||||
export declare function generateSitemap(pages: string[], finalSiteUrl: string, opts?: SitemapOptions): SitemapItem[];
|
||||
52
node_modules/@astrojs/sitemap/dist/generate-sitemap.js
generated
vendored
Normal file
52
node_modules/@astrojs/sitemap/dist/generate-sitemap.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
import { parseI18nUrl } from "./utils/parse-i18n-url.js";
|
||||
function generateSitemap(pages, finalSiteUrl, opts) {
|
||||
const { changefreq, priority, lastmod: lastmodSrc, i18n } = opts ?? {};
|
||||
const urls = [...pages];
|
||||
urls.sort((a, b) => a.localeCompare(b, "en", { numeric: true }));
|
||||
const lastmod = lastmodSrc?.toISOString();
|
||||
const { defaultLocale, locales } = i18n ?? {};
|
||||
let getI18nLinks;
|
||||
if (defaultLocale && locales) {
|
||||
getI18nLinks = createGetI18nLinks(urls, defaultLocale, locales, finalSiteUrl);
|
||||
}
|
||||
const urlData = urls.map((url, i) => ({
|
||||
url,
|
||||
links: getI18nLinks?.(i),
|
||||
lastmod,
|
||||
priority,
|
||||
changefreq
|
||||
}));
|
||||
return urlData;
|
||||
}
|
||||
function createGetI18nLinks(urls, defaultLocale, locales, finalSiteUrl) {
|
||||
const parsedI18nUrls = urls.map((url) => parseI18nUrl(url, defaultLocale, locales, finalSiteUrl));
|
||||
const i18nPathToLinksCache = /* @__PURE__ */ new Map();
|
||||
return (urlIndex) => {
|
||||
const i18nUrl = parsedI18nUrls[urlIndex];
|
||||
if (!i18nUrl) {
|
||||
return void 0;
|
||||
}
|
||||
const cached = i18nPathToLinksCache.get(i18nUrl.path);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
const links = [];
|
||||
for (let i = 0; i < parsedI18nUrls.length; i++) {
|
||||
const parsed = parsedI18nUrls[i];
|
||||
if (parsed?.path === i18nUrl.path) {
|
||||
links.push({
|
||||
url: urls[i],
|
||||
lang: locales[parsed.locale]
|
||||
});
|
||||
}
|
||||
}
|
||||
if (links.length <= 1) {
|
||||
return void 0;
|
||||
}
|
||||
i18nPathToLinksCache.set(i18nUrl.path, links);
|
||||
return links;
|
||||
};
|
||||
}
|
||||
export {
|
||||
generateSitemap
|
||||
};
|
||||
30
node_modules/@astrojs/sitemap/dist/index.d.ts
generated
vendored
Normal file
30
node_modules/@astrojs/sitemap/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { AstroIntegration } from 'astro';
|
||||
import type { EnumChangefreq, LinkItem as LinkItemBase, SitemapItemLoose } from 'sitemap';
|
||||
export { EnumChangefreq as ChangeFreqEnum } from 'sitemap';
|
||||
export type ChangeFreq = `${EnumChangefreq}`;
|
||||
export type SitemapItem = Pick<SitemapItemLoose, 'url' | 'lastmod' | 'changefreq' | 'priority' | 'links'>;
|
||||
export type LinkItem = LinkItemBase;
|
||||
export type SitemapOptions = {
|
||||
filenameBase?: string;
|
||||
filter?(page: string): boolean;
|
||||
customSitemaps?: string[];
|
||||
customPages?: string[];
|
||||
i18n?: {
|
||||
defaultLocale: string;
|
||||
locales: Record<string, string>;
|
||||
};
|
||||
entryLimit?: number;
|
||||
changefreq?: ChangeFreq;
|
||||
lastmod?: Date;
|
||||
priority?: number;
|
||||
serialize?(item: SitemapItem): SitemapItem | Promise<SitemapItem | undefined> | undefined;
|
||||
xslURL?: string;
|
||||
namespaces?: {
|
||||
news?: boolean;
|
||||
xhtml?: boolean;
|
||||
image?: boolean;
|
||||
video?: boolean;
|
||||
};
|
||||
} | undefined;
|
||||
declare const createPlugin: (options?: SitemapOptions) => AstroIntegration;
|
||||
export default createPlugin;
|
||||
138
node_modules/@astrojs/sitemap/dist/index.js
generated
vendored
Normal file
138
node_modules/@astrojs/sitemap/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { ZodError } from "zod";
|
||||
import { generateSitemap } from "./generate-sitemap.js";
|
||||
import { validateOptions } from "./validate-options.js";
|
||||
import { writeSitemap } from "./write-sitemap.js";
|
||||
import { EnumChangefreq } from "sitemap";
|
||||
function formatConfigErrorMessage(err) {
|
||||
const errorList = err.issues.map((issue) => ` ${issue.path.join(".")} ${issue.message + "."}`);
|
||||
return errorList.join("\n");
|
||||
}
|
||||
const PKG_NAME = "@astrojs/sitemap";
|
||||
const STATUS_CODE_PAGES = /* @__PURE__ */ new Set(["404", "500"]);
|
||||
const isStatusCodePage = (locales) => {
|
||||
const statusPathNames = new Set(
|
||||
locales.flatMap((locale) => [...STATUS_CODE_PAGES].map((page) => `${locale}/${page}`)).concat([...STATUS_CODE_PAGES])
|
||||
);
|
||||
return (pathname) => {
|
||||
if (pathname.endsWith("/")) {
|
||||
pathname = pathname.slice(0, -1);
|
||||
}
|
||||
if (pathname.startsWith("/")) {
|
||||
pathname = pathname.slice(1);
|
||||
}
|
||||
return statusPathNames.has(pathname);
|
||||
};
|
||||
};
|
||||
const createPlugin = (options) => {
|
||||
let config;
|
||||
return {
|
||||
name: PKG_NAME,
|
||||
hooks: {
|
||||
"astro:config:done": async ({ config: cfg }) => {
|
||||
config = cfg;
|
||||
},
|
||||
"astro:build:done": async ({ dir, routes, pages, logger }) => {
|
||||
try {
|
||||
if (!config.site) {
|
||||
logger.warn(
|
||||
"The Sitemap integration requires the `site` astro.config option. Skipping."
|
||||
);
|
||||
return;
|
||||
}
|
||||
const opts = validateOptions(config.site, options);
|
||||
const { filenameBase, filter, customPages, customSitemaps, serialize, entryLimit } = opts;
|
||||
const outFile = `${filenameBase}-index.xml`;
|
||||
const finalSiteUrl = new URL(config.base, config.site);
|
||||
const shouldIgnoreStatus = isStatusCodePage(Object.keys(opts.i18n?.locales ?? {}));
|
||||
let pageUrls = pages.filter((p) => !shouldIgnoreStatus(p.pathname)).map((p) => {
|
||||
if (p.pathname !== "" && !finalSiteUrl.pathname.endsWith("/"))
|
||||
finalSiteUrl.pathname += "/";
|
||||
if (p.pathname.startsWith("/")) p.pathname = p.pathname.slice(1);
|
||||
const fullPath = finalSiteUrl.pathname + p.pathname;
|
||||
return new URL(fullPath, finalSiteUrl).href;
|
||||
});
|
||||
const routeUrls = routes.reduce((urls, r) => {
|
||||
if (r.type !== "page") return urls;
|
||||
if (r.pathname) {
|
||||
if (shouldIgnoreStatus(r.pathname ?? r.route)) return urls;
|
||||
let fullPath = finalSiteUrl.pathname;
|
||||
if (fullPath.endsWith("/")) fullPath += r.generate(r.pathname).substring(1);
|
||||
else fullPath += r.generate(r.pathname);
|
||||
const newUrl = new URL(fullPath, finalSiteUrl).href;
|
||||
if (config.trailingSlash === "never") {
|
||||
urls.push(newUrl);
|
||||
} else if (config.build.format === "directory" && !newUrl.endsWith("/")) {
|
||||
urls.push(newUrl + "/");
|
||||
} else {
|
||||
urls.push(newUrl);
|
||||
}
|
||||
}
|
||||
return urls;
|
||||
}, []);
|
||||
pageUrls = Array.from(/* @__PURE__ */ new Set([...pageUrls, ...routeUrls, ...customPages ?? []]));
|
||||
if (filter) {
|
||||
pageUrls = pageUrls.filter(filter);
|
||||
}
|
||||
if (pageUrls.length === 0) {
|
||||
logger.warn(`No pages found!
|
||||
\`${outFile}\` not created.`);
|
||||
return;
|
||||
}
|
||||
let urlData = generateSitemap(pageUrls, finalSiteUrl.href, opts);
|
||||
if (serialize) {
|
||||
try {
|
||||
const serializedUrls = [];
|
||||
for (const item of urlData) {
|
||||
const serialized = await Promise.resolve(serialize(item));
|
||||
if (serialized) {
|
||||
serializedUrls.push(serialized);
|
||||
}
|
||||
}
|
||||
if (serializedUrls.length === 0) {
|
||||
logger.warn("No pages found!");
|
||||
return;
|
||||
}
|
||||
urlData = serializedUrls;
|
||||
} catch (err) {
|
||||
logger.error(`Error serializing pages
|
||||
${err.toString()}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
const destDir = fileURLToPath(dir);
|
||||
const lastmod = opts.lastmod?.toISOString();
|
||||
const xslURL = opts.xslURL ? new URL(opts.xslURL, finalSiteUrl).href : void 0;
|
||||
await writeSitemap(
|
||||
{
|
||||
filenameBase,
|
||||
hostname: finalSiteUrl.href,
|
||||
destinationDir: destDir,
|
||||
publicBasePath: config.base,
|
||||
sourceData: urlData,
|
||||
limit: entryLimit,
|
||||
customSitemaps,
|
||||
xslURL,
|
||||
lastmod,
|
||||
namespaces: opts.namespaces
|
||||
},
|
||||
config
|
||||
);
|
||||
logger.info(`\`${outFile}\` created at \`${path.relative(process.cwd(), destDir)}\``);
|
||||
} catch (err) {
|
||||
if (err instanceof ZodError) {
|
||||
logger.warn(formatConfigErrorMessage(err));
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
var index_default = createPlugin;
|
||||
export {
|
||||
EnumChangefreq as ChangeFreqEnum,
|
||||
index_default as default
|
||||
};
|
||||
91
node_modules/@astrojs/sitemap/dist/schema.d.ts
generated
vendored
Normal file
91
node_modules/@astrojs/sitemap/dist/schema.d.ts
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
import { EnumChangefreq as ChangeFreq } from 'sitemap';
|
||||
import { z } from 'zod';
|
||||
export declare const SitemapOptionsSchema: z.ZodDefault<z.ZodObject<{
|
||||
filenameBase: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
||||
filter: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodBoolean>>;
|
||||
customSitemaps: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
||||
customPages: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
||||
canonicalURL: z.ZodOptional<z.ZodString>;
|
||||
xslURL: z.ZodOptional<z.ZodString>;
|
||||
i18n: z.ZodOptional<z.ZodEffects<z.ZodObject<{
|
||||
defaultLocale: z.ZodString;
|
||||
locales: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
defaultLocale: string;
|
||||
locales: Record<string, string>;
|
||||
}, {
|
||||
defaultLocale: string;
|
||||
locales: Record<string, string>;
|
||||
}>, {
|
||||
defaultLocale: string;
|
||||
locales: Record<string, string>;
|
||||
}, {
|
||||
defaultLocale: string;
|
||||
locales: Record<string, string>;
|
||||
}>>;
|
||||
entryLimit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
||||
serialize: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodAny], z.ZodUnknown>, z.ZodAny>>;
|
||||
changefreq: z.ZodOptional<z.ZodNativeEnum<typeof ChangeFreq>>;
|
||||
lastmod: z.ZodOptional<z.ZodDate>;
|
||||
priority: z.ZodOptional<z.ZodNumber>;
|
||||
namespaces: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
||||
news: z.ZodOptional<z.ZodBoolean>;
|
||||
xhtml: z.ZodOptional<z.ZodBoolean>;
|
||||
image: z.ZodOptional<z.ZodBoolean>;
|
||||
video: z.ZodOptional<z.ZodBoolean>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
news?: boolean | undefined;
|
||||
xhtml?: boolean | undefined;
|
||||
image?: boolean | undefined;
|
||||
video?: boolean | undefined;
|
||||
}, {
|
||||
news?: boolean | undefined;
|
||||
xhtml?: boolean | undefined;
|
||||
image?: boolean | undefined;
|
||||
video?: boolean | undefined;
|
||||
}>>>;
|
||||
}, "strict", z.ZodTypeAny, {
|
||||
filenameBase: string;
|
||||
entryLimit: number;
|
||||
namespaces: {
|
||||
news?: boolean | undefined;
|
||||
xhtml?: boolean | undefined;
|
||||
image?: boolean | undefined;
|
||||
video?: boolean | undefined;
|
||||
};
|
||||
changefreq?: ChangeFreq | undefined;
|
||||
priority?: number | undefined;
|
||||
lastmod?: Date | undefined;
|
||||
i18n?: {
|
||||
defaultLocale: string;
|
||||
locales: Record<string, string>;
|
||||
} | undefined;
|
||||
filter?: ((args_0: string, ...args: unknown[]) => boolean) | undefined;
|
||||
customSitemaps?: string[] | undefined;
|
||||
customPages?: string[] | undefined;
|
||||
canonicalURL?: string | undefined;
|
||||
xslURL?: string | undefined;
|
||||
serialize?: ((args_0: any, ...args: unknown[]) => any) | undefined;
|
||||
}, {
|
||||
changefreq?: ChangeFreq | undefined;
|
||||
priority?: number | undefined;
|
||||
lastmod?: Date | undefined;
|
||||
i18n?: {
|
||||
defaultLocale: string;
|
||||
locales: Record<string, string>;
|
||||
} | undefined;
|
||||
filter?: ((args_0: string, ...args: unknown[]) => boolean) | undefined;
|
||||
filenameBase?: string | undefined;
|
||||
entryLimit?: number | undefined;
|
||||
customSitemaps?: string[] | undefined;
|
||||
customPages?: string[] | undefined;
|
||||
canonicalURL?: string | undefined;
|
||||
xslURL?: string | undefined;
|
||||
serialize?: ((args_0: any, ...args: unknown[]) => any) | undefined;
|
||||
namespaces?: {
|
||||
news?: boolean | undefined;
|
||||
xhtml?: boolean | undefined;
|
||||
image?: boolean | undefined;
|
||||
video?: boolean | undefined;
|
||||
} | undefined;
|
||||
}>>;
|
||||
37
node_modules/@astrojs/sitemap/dist/schema.js
generated
vendored
Normal file
37
node_modules/@astrojs/sitemap/dist/schema.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import { EnumChangefreq as ChangeFreq } from "sitemap";
|
||||
import { z } from "zod";
|
||||
import { SITEMAP_CONFIG_DEFAULTS } from "./config-defaults.js";
|
||||
const localeKeySchema = z.string().min(1);
|
||||
const SitemapOptionsSchema = z.object({
|
||||
filenameBase: z.string().optional().default(SITEMAP_CONFIG_DEFAULTS.filenameBase),
|
||||
filter: z.function().args(z.string()).returns(z.boolean()).optional(),
|
||||
customSitemaps: z.string().url().array().optional(),
|
||||
customPages: z.string().url().array().optional(),
|
||||
canonicalURL: z.string().url().optional(),
|
||||
xslURL: z.string().optional(),
|
||||
i18n: z.object({
|
||||
defaultLocale: localeKeySchema,
|
||||
locales: z.record(
|
||||
localeKeySchema,
|
||||
z.string().min(2).regex(/^[a-zA-Z\-]+$/gm, {
|
||||
message: "Only English alphabet symbols and hyphen allowed"
|
||||
})
|
||||
)
|
||||
}).refine((val) => !val || val.locales[val.defaultLocale], {
|
||||
message: "`defaultLocale` must exist in `locales` keys"
|
||||
}).optional(),
|
||||
entryLimit: z.number().nonnegative().optional().default(SITEMAP_CONFIG_DEFAULTS.entryLimit),
|
||||
serialize: z.function().args(z.any()).returns(z.any()).optional(),
|
||||
changefreq: z.nativeEnum(ChangeFreq).optional(),
|
||||
lastmod: z.date().optional(),
|
||||
priority: z.number().min(0).max(1).optional(),
|
||||
namespaces: z.object({
|
||||
news: z.boolean().optional(),
|
||||
xhtml: z.boolean().optional(),
|
||||
image: z.boolean().optional(),
|
||||
video: z.boolean().optional()
|
||||
}).optional().default(SITEMAP_CONFIG_DEFAULTS.namespaces)
|
||||
}).strict().default(SITEMAP_CONFIG_DEFAULTS);
|
||||
export {
|
||||
SitemapOptionsSchema
|
||||
};
|
||||
6
node_modules/@astrojs/sitemap/dist/utils/parse-i18n-url.d.ts
generated
vendored
Normal file
6
node_modules/@astrojs/sitemap/dist/utils/parse-i18n-url.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
interface ParsedI18nUrl {
|
||||
locale: string;
|
||||
path: string;
|
||||
}
|
||||
export declare function parseI18nUrl(url: string, defaultLocale: string, locales: Record<string, string>, base: string): ParsedI18nUrl | undefined;
|
||||
export {};
|
||||
24
node_modules/@astrojs/sitemap/dist/utils/parse-i18n-url.js
generated
vendored
Normal file
24
node_modules/@astrojs/sitemap/dist/utils/parse-i18n-url.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
function parseI18nUrl(url, defaultLocale, locales, base) {
|
||||
if (!url.startsWith(base)) {
|
||||
return void 0;
|
||||
}
|
||||
let s = url.slice(base.length);
|
||||
if (!s || s === "/") {
|
||||
return { locale: defaultLocale, path: "/" };
|
||||
}
|
||||
if (s[0] !== "/") {
|
||||
s = "/" + s;
|
||||
}
|
||||
const locale = s.split("/")[1];
|
||||
if (locale in locales) {
|
||||
let path = s.slice(1 + locale.length);
|
||||
if (!path) {
|
||||
path = "/";
|
||||
}
|
||||
return { locale, path };
|
||||
}
|
||||
return { locale: defaultLocale, path: s };
|
||||
}
|
||||
export {
|
||||
parseI18nUrl
|
||||
};
|
||||
1
node_modules/@astrojs/sitemap/dist/validate-options.d.ts
generated
vendored
Normal file
1
node_modules/@astrojs/sitemap/dist/validate-options.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
20
node_modules/@astrojs/sitemap/dist/validate-options.js
generated
vendored
Normal file
20
node_modules/@astrojs/sitemap/dist/validate-options.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import { z } from "zod";
|
||||
import { SitemapOptionsSchema } from "./schema.js";
|
||||
const validateOptions = (site, opts) => {
|
||||
const result = SitemapOptionsSchema.parse(opts);
|
||||
z.object({
|
||||
site: z.string().optional(),
|
||||
// Astro takes care of `site`: how to validate, transform and refine
|
||||
canonicalURL: z.string().optional()
|
||||
// `canonicalURL` is already validated in prev step
|
||||
}).refine((options) => options.site || options.canonicalURL, {
|
||||
message: "Required `site` astro.config option or `canonicalURL` integration option"
|
||||
}).parse({
|
||||
site,
|
||||
canonicalURL: result.canonicalURL
|
||||
});
|
||||
return result;
|
||||
};
|
||||
export {
|
||||
validateOptions
|
||||
};
|
||||
22
node_modules/@astrojs/sitemap/dist/write-sitemap.d.ts
generated
vendored
Normal file
22
node_modules/@astrojs/sitemap/dist/write-sitemap.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import type { AstroConfig } from 'astro';
|
||||
import type { SitemapItem } from './index.js';
|
||||
type WriteSitemapConfig = {
|
||||
filenameBase: string;
|
||||
hostname: string;
|
||||
sitemapHostname?: string;
|
||||
customSitemaps?: string[];
|
||||
sourceData: SitemapItem[];
|
||||
destinationDir: string;
|
||||
publicBasePath?: string;
|
||||
limit?: number;
|
||||
xslURL?: string;
|
||||
lastmod?: string;
|
||||
namespaces?: {
|
||||
news?: boolean;
|
||||
xhtml?: boolean;
|
||||
image?: boolean;
|
||||
video?: boolean;
|
||||
};
|
||||
};
|
||||
export declare function writeSitemap({ filenameBase, hostname, sitemapHostname, sourceData, destinationDir, limit, customSitemaps, publicBasePath, xslURL: xslUrl, lastmod, namespaces, }: WriteSitemapConfig, astroConfig: AstroConfig): Promise<void>;
|
||||
export {};
|
||||
71
node_modules/@astrojs/sitemap/dist/write-sitemap.js
generated
vendored
Normal file
71
node_modules/@astrojs/sitemap/dist/write-sitemap.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
import { createWriteStream } from "node:fs";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
import { normalize, resolve } from "node:path";
|
||||
import { pipeline, Readable } from "node:stream";
|
||||
import { promisify } from "node:util";
|
||||
import { SitemapAndIndexStream, SitemapIndexStream, SitemapStream } from "sitemap";
|
||||
import replace from "stream-replace-string";
|
||||
async function writeSitemap({
|
||||
filenameBase,
|
||||
hostname,
|
||||
sitemapHostname = hostname,
|
||||
sourceData,
|
||||
destinationDir,
|
||||
limit = 5e4,
|
||||
customSitemaps = [],
|
||||
publicBasePath = "./",
|
||||
xslURL: xslUrl,
|
||||
lastmod,
|
||||
namespaces = { news: true, xhtml: true, image: true, video: true }
|
||||
}, astroConfig) {
|
||||
await mkdir(destinationDir, { recursive: true });
|
||||
const sitemapAndIndexStream = new SitemapAndIndexStream({
|
||||
limit,
|
||||
xslUrl,
|
||||
getSitemapStream: (i) => {
|
||||
const sitemapStream = new SitemapStream({
|
||||
hostname,
|
||||
xslUrl,
|
||||
// Custom namespace handling
|
||||
xmlns: {
|
||||
news: namespaces?.news !== false,
|
||||
xhtml: namespaces?.xhtml !== false,
|
||||
image: namespaces?.image !== false,
|
||||
video: namespaces?.video !== false
|
||||
}
|
||||
});
|
||||
const path = `./${filenameBase}-${i}.xml`;
|
||||
const writePath = resolve(destinationDir, path);
|
||||
if (!publicBasePath.endsWith("/")) {
|
||||
publicBasePath += "/";
|
||||
}
|
||||
const publicPath = normalize(publicBasePath + path);
|
||||
let stream;
|
||||
if (astroConfig.trailingSlash === "never" || astroConfig.build.format === "file") {
|
||||
const host = hostname.endsWith("/") ? hostname.slice(0, -1) : hostname;
|
||||
const searchStr = `<loc>${host}/</loc>`;
|
||||
const replaceStr = `<loc>${host}</loc>`;
|
||||
stream = sitemapStream.pipe(replace(searchStr, replaceStr)).pipe(createWriteStream(writePath));
|
||||
} else {
|
||||
stream = sitemapStream.pipe(createWriteStream(writePath));
|
||||
}
|
||||
const url = new URL(publicPath, sitemapHostname).toString();
|
||||
return [{ url, lastmod }, sitemapStream, stream];
|
||||
}
|
||||
});
|
||||
const src = Readable.from(sourceData);
|
||||
const indexPath = resolve(destinationDir, `./${filenameBase}-index.xml`);
|
||||
for (const url of customSitemaps) {
|
||||
SitemapIndexStream.prototype._transform.call(
|
||||
sitemapAndIndexStream,
|
||||
{ url, lastmod },
|
||||
"utf8",
|
||||
() => {
|
||||
}
|
||||
);
|
||||
}
|
||||
return promisify(pipeline)(src, sitemapAndIndexStream, createWriteStream(indexPath));
|
||||
}
|
||||
export {
|
||||
writeSitemap
|
||||
};
|
||||
48
node_modules/@astrojs/sitemap/package.json
generated
vendored
Normal file
48
node_modules/@astrojs/sitemap/package.json
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "@astrojs/sitemap",
|
||||
"description": "Generate a sitemap for your Astro site",
|
||||
"version": "3.6.0",
|
||||
"type": "module",
|
||||
"types": "./dist/index.d.ts",
|
||||
"author": "withastro",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/withastro/astro.git",
|
||||
"directory": "packages/integrations/sitemap"
|
||||
},
|
||||
"keywords": [
|
||||
"astro-integration",
|
||||
"astro-component",
|
||||
"seo",
|
||||
"sitemap"
|
||||
],
|
||||
"bugs": "https://github.com/withastro/astro/issues",
|
||||
"homepage": "https://docs.astro.build/en/guides/integrations-guide/sitemap/",
|
||||
"exports": {
|
||||
".": "./dist/index.js",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"sitemap": "^8.0.0",
|
||||
"stream-replace-string": "^2.0.0",
|
||||
"zod": "^3.25.76"
|
||||
},
|
||||
"devDependencies": {
|
||||
"xml2js": "0.6.2",
|
||||
"astro-scripts": "0.0.14",
|
||||
"astro": "5.13.8"
|
||||
},
|
||||
"publishConfig": {
|
||||
"provenance": true
|
||||
},
|
||||
"scripts": {
|
||||
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
|
||||
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
||||
"dev": "astro-scripts dev \"src/**/*.ts\"",
|
||||
"test": "astro-scripts test \"test/**/*.test.js\""
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user