@zubyjs/sitemap 1.0.48 → 1.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -22
- package/index.d.ts +22 -3
- package/index.js +33 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,28 +29,7 @@ Then add the `@zubyjs/sitemap` plugin to your `zuby.config.mjs` file under the `
|
|
|
29
29
|
});
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
to link the generated `sitemap.xml` file on your website:
|
|
34
|
-
|
|
35
|
-
```diff lang="jsx" title="pages/layout.jsx"
|
|
36
|
-
export default function Layout({
|
|
37
|
-
children,
|
|
38
|
-
context,
|
|
39
|
-
}) {
|
|
40
|
-
return (
|
|
41
|
-
<html>
|
|
42
|
-
<head>
|
|
43
|
-
<meta charSet="UTF-8" />
|
|
44
|
-
+ <link rel="sitemap" type="application/xml" href="/sitemap.xml" />
|
|
45
|
-
<title>{context.title}</title>
|
|
46
|
-
</head>
|
|
47
|
-
<body>{children}</body>
|
|
48
|
-
</html>
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
|
|
32
|
+
The plugin will automatically add link the generated sitemap to the head of your HTML pages.
|
|
54
33
|
And that's it! Now you can run `zuby build` and the sitemap.xml file will be generated.
|
|
55
34
|
|
|
56
35
|
NOTE: Always make sure that all zuby packages are in sync in your `package.json` file:
|
package/index.d.ts
CHANGED
|
@@ -8,10 +8,10 @@ export interface SitemapPluginOptions {
|
|
|
8
8
|
filter?: (path: string) => boolean;
|
|
9
9
|
/**
|
|
10
10
|
* Additional custom paths that should be included in the sitemap.
|
|
11
|
-
* @example
|
|
11
|
+
* @example customPaths: ['/custom-page', '/custom-page-2']
|
|
12
12
|
* @default []
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
customPaths?: string[];
|
|
15
15
|
/**
|
|
16
16
|
* The maximum number of entries per sitemap file.
|
|
17
17
|
* @example entryLimit: 10000
|
|
@@ -24,6 +24,25 @@ export interface SitemapPluginOptions {
|
|
|
24
24
|
* @default 'sitemap'
|
|
25
25
|
*/
|
|
26
26
|
filename?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Set to false to not include pre-rendered paths in the sitemap.
|
|
29
|
+
* @default true
|
|
30
|
+
*/
|
|
31
|
+
includePrerendered?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Set to false to not include pages with static path type in the sitemap.
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
includePages?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Set to true to include handlers with static path type in the sitemap.
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
41
|
+
includeHandlers?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Set to false to not automatically add the sitemap link to the head of the HTML.
|
|
44
|
+
*/
|
|
45
|
+
addLinkToHead?: boolean;
|
|
27
46
|
}
|
|
28
47
|
/**
|
|
29
48
|
* Zuby.js plugin that generates sitemap.xml
|
|
@@ -31,6 +50,6 @@ export interface SitemapPluginOptions {
|
|
|
31
50
|
* @param options
|
|
32
51
|
* @returns ZubyPlugin
|
|
33
52
|
*/
|
|
34
|
-
declare const _default: ({ filter,
|
|
53
|
+
declare const _default: ({ filter, customPaths, entryLimit, filename, includePrerendered, includePages, includeHandlers, addLinkToHead, }?: SitemapPluginOptions) => ZubyPlugin;
|
|
35
54
|
export default _default;
|
|
36
55
|
export declare function splitToParts(array: string[], parts: number): string[][];
|
package/index.js
CHANGED
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
2
|
import { writeFile } from 'fs/promises';
|
|
3
|
+
import { PATH_TYPES, TEMPLATES } from 'zuby/templates/types.js';
|
|
3
4
|
/**
|
|
4
5
|
* Zuby.js plugin that generates sitemap.xml
|
|
5
6
|
* from pre-rendered paths.
|
|
6
7
|
* @param options
|
|
7
8
|
* @returns ZubyPlugin
|
|
8
9
|
*/
|
|
9
|
-
export default ({ filter = () => true,
|
|
10
|
+
export default ({ filter = () => true, customPaths = [], entryLimit = 45000, filename = 'sitemap', includePrerendered = true, includePages = true, includeHandlers = false, addLinkToHead = true, } = {}) => ({
|
|
10
11
|
name: 'zuby-sitemap-plugin',
|
|
11
|
-
description: 'generating sitemap
|
|
12
|
+
description: 'generating sitemap...',
|
|
12
13
|
buildStep: true,
|
|
13
14
|
hooks: {
|
|
14
|
-
'zuby:
|
|
15
|
+
'zuby:config:setup': ({ addToHead }) => {
|
|
16
|
+
if (!addLinkToHead)
|
|
17
|
+
return;
|
|
18
|
+
addToHead(`<link rel="sitemap" type="application/xml" title="Sitemap" href="/${filename}.xml" />`);
|
|
19
|
+
},
|
|
20
|
+
'zuby:build:done': async ({ config, logger, templates }) => {
|
|
15
21
|
const { site, outDir, i18n, prerenderPaths } = config;
|
|
22
|
+
logger.info('Generating sitemap from paths...');
|
|
16
23
|
if (!site) {
|
|
17
24
|
logger?.warn(`WARNING: The "site" property is not defined in zuby.config.mjs. Skipping sitemap generation.`);
|
|
18
25
|
return;
|
|
19
26
|
}
|
|
20
|
-
logger.info('Generating sitemap from pre-rendered paths...');
|
|
21
27
|
const removeLocale = (path) => {
|
|
22
28
|
for (const locale of i18n?.locales || []) {
|
|
23
29
|
if (path.startsWith(`/${locale}/`))
|
|
@@ -30,10 +36,30 @@ export default ({ filter = () => true, customPages = [], entryLimit = 45000, fil
|
|
|
30
36
|
const normalizePath = (path) => {
|
|
31
37
|
return path.replace(/(.+)\/$/, '').replace(/\/\/+/g, '/');
|
|
32
38
|
};
|
|
33
|
-
const paths =
|
|
34
|
-
|
|
39
|
+
const paths = new Set(customPaths);
|
|
40
|
+
if (includePrerendered) {
|
|
41
|
+
prerenderPaths.forEach(path => paths.add(normalizePath(path)));
|
|
42
|
+
}
|
|
43
|
+
if (includePages) {
|
|
44
|
+
const pageStaticPaths = templates
|
|
45
|
+
?.filter(({ templateType, pathType }) => {
|
|
46
|
+
return templateType === TEMPLATES.page && pathType == PATH_TYPES.static;
|
|
47
|
+
})
|
|
48
|
+
.map(({ path }) => path);
|
|
49
|
+
pageStaticPaths.forEach(path => paths.add(normalizePath(path)));
|
|
50
|
+
}
|
|
51
|
+
if (includeHandlers) {
|
|
52
|
+
const handlerStaticPaths = templates
|
|
53
|
+
?.filter(({ templateType, pathType }) => {
|
|
54
|
+
return templateType === TEMPLATES.handler && pathType == PATH_TYPES.static;
|
|
55
|
+
})
|
|
56
|
+
.map(({ path }) => path);
|
|
57
|
+
handlerStaticPaths.forEach(path => paths.add(normalizePath(path)));
|
|
58
|
+
}
|
|
59
|
+
const filteredPaths = Array.from(paths).filter(filter);
|
|
60
|
+
const entries = filteredPaths.map(path => {
|
|
35
61
|
const localizedPaths = i18n
|
|
36
|
-
?
|
|
62
|
+
? filteredPaths.filter(filteredPath => {
|
|
37
63
|
return removeLocale(path) === removeLocale(filteredPath);
|
|
38
64
|
})
|
|
39
65
|
: [];
|