createPlugin() — astro Function Reference
Architecture documentation for the createPlugin() function in index.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 1bbd6d7d_7355_b89b_685e_873720d72418["createPlugin()"] 79573a16_7c46_af8f_5c1d_ea09d9ca9085["index.ts"] 1bbd6d7d_7355_b89b_685e_873720d72418 -->|defined in| 79573a16_7c46_af8f_5c1d_ea09d9ca9085 9804c61c_5b2d_f65a_7831_05c44a8cef26["isStatusCodePage()"] 1bbd6d7d_7355_b89b_685e_873720d72418 -->|calls| 9804c61c_5b2d_f65a_7831_05c44a8cef26 54689613_153c_977d_3fed_491151b71381["formatConfigErrorMessage()"] 1bbd6d7d_7355_b89b_685e_873720d72418 -->|calls| 54689613_153c_977d_3fed_491151b71381 style 1bbd6d7d_7355_b89b_685e_873720d72418 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/integrations/sitemap/src/index.ts lines 82–274
const createPlugin = (options?: SitemapOptions): AstroIntegration => {
let _routes: Array<IntegrationResolvedRoute>;
let config: AstroConfig;
return {
name: PKG_NAME,
hooks: {
'astro:routes:resolved': ({ routes }) => {
_routes = routes;
},
'astro:config:done': async ({ config: cfg }) => {
config = cfg;
},
'astro:build:done': async ({ dir, 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,
chunks,
} = 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<string[]>((urls, r) => {
// Only expose pages, not endpoints or redirects
if (r.type !== 'page') return urls;
/**
* Dynamic URLs have entries with `undefined` pathnames
*/
if (r.pathname) {
if (shouldIgnoreStatus(r.pathname ?? r.pattern)) return urls;
// `finalSiteUrl` may end with a trailing slash
// or not because of base paths.
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(new Set([...pageUrls, ...routeUrls, ...(customPages ?? [])]));
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does createPlugin() do?
createPlugin() is a function in the astro codebase, defined in packages/integrations/sitemap/src/index.ts.
Where is createPlugin() defined?
createPlugin() is defined in packages/integrations/sitemap/src/index.ts at line 82.
What does createPlugin() call?
createPlugin() calls 2 function(s): formatConfigErrorMessage, isStatusCodePage.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free