@gracile/sitemap
Advanced tools
Comparing version 0.1.1 to 0.1.2-next.0
@@ -11,3 +11,3 @@ export declare function viteSitemapPlugin(options: { | ||
robotsTxt?: [string, string][] | false; | ||
}): any; | ||
}): any[]; | ||
//# sourceMappingURL=vite.d.ts.map |
@@ -8,44 +8,45 @@ import { Readable } from 'node:stream'; | ||
let isSsrBuild = false; | ||
return { | ||
name: VITE_PLUGIN_NAME, | ||
enforce: 'post', | ||
config(_, env) { | ||
isSsrBuild = env.isSsrBuild || false; | ||
}, | ||
async generateBundle(_, bundle) { | ||
if (isSsrBuild) { | ||
logger.warn(`\n${VITE_PLUGIN_NAME} is only compatible with static output! Skipping…\n`); | ||
return; | ||
} | ||
const links = Object.entries(bundle) | ||
.filter(([, asset]) => asset.fileName.endsWith('.html')) | ||
.map(([, asset]) => `/${asset.fileName}`.replace(/\/index\.html$/, '/')); | ||
if (links.length < 2) { | ||
logger.warn(`\n${VITE_PLUGIN_NAME} hasn't found any built HTML pages! Skipping…\n`); | ||
return; | ||
} | ||
const hostname = options.siteUrl.endsWith('/') | ||
? options.siteUrl | ||
: `${options.siteUrl}/`; | ||
const stream = new SitemapStream({ | ||
hostname, | ||
}); | ||
const map = await streamToPromise(Readable.from(links).pipe(stream)).then((data) => { | ||
return data.toString(); | ||
}); | ||
this.emitFile({ | ||
fileName: 'sitemap.xml', | ||
type: 'asset', | ||
source: map, | ||
}); | ||
if (options.robotsTxt !== false) { | ||
return [ | ||
{ | ||
name: VITE_PLUGIN_NAME, | ||
enforce: 'post', | ||
config(_, env) { | ||
isSsrBuild = env.isSsrBuild || false; | ||
}, | ||
async generateBundle(_, bundle) { | ||
if (isSsrBuild) { | ||
logger.warn(`\n${VITE_PLUGIN_NAME} is only compatible with static output! Skipping…\n`); | ||
return; | ||
} | ||
const links = Object.entries(bundle) | ||
.filter(([, asset]) => asset.fileName.endsWith('.html')) | ||
.map(([, asset]) => `/${asset.fileName}`.replace(/\/index\.html$/, '/')); | ||
if (links.length < 2) { | ||
logger.warn(`\n${VITE_PLUGIN_NAME} hasn't found any built HTML pages! Skipping…\n`); | ||
return; | ||
} | ||
const hostname = options.siteUrl.endsWith('/') | ||
? options.siteUrl | ||
: `${options.siteUrl}/`; | ||
const stream = new SitemapStream({ | ||
hostname, | ||
}); | ||
const map = await streamToPromise(Readable.from(links).pipe(stream)).then((data) => { | ||
return data.toString(); | ||
}); | ||
this.emitFile({ | ||
fileName: 'robots.txt', | ||
fileName: 'sitemap.xml', | ||
type: 'asset', | ||
source: ` | ||
source: map, | ||
}); | ||
if (options.robotsTxt !== false) { | ||
this.emitFile({ | ||
fileName: 'robots.txt', | ||
type: 'asset', | ||
source: ` | ||
${typeof options.robotsTxt === 'object' | ||
? options.robotsTxt | ||
.map(([option, value]) => `${option}: ${value}`) | ||
.join('\n') | ||
: ` | ||
? options.robotsTxt | ||
.map(([option, value]) => `${option}: ${value}`) | ||
.join('\n') | ||
: ` | ||
User-agent: * | ||
@@ -57,8 +58,9 @@ Allow: / | ||
`.trim(), | ||
}); | ||
} | ||
logger.info(c.cyan(c.bold('Sitemap generated. Found links:'))); | ||
logger.info(c.gray(`- ${links.join('\n- ')}`)); | ||
}); | ||
} | ||
logger.info(c.cyan(c.bold('Sitemap generated. Found links:'))); | ||
logger.info(c.gray(`- ${links.join('\n- ')}`)); | ||
}, | ||
}, | ||
}; | ||
]; | ||
} |
{ | ||
"name": "@gracile/sitemap", | ||
"version": "0.1.1", | ||
"version": "0.1.2-next.0", | ||
"description": "A thin, full-stack, web framework", | ||
@@ -48,3 +48,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "970e457d0382b48beb531a1803393373cae38dcb" | ||
"gitHead": "ed69f4d4d482a43fdb12bc0a02f12093337d91c7" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43274
74