@uxf/router 11.11.3 → 11.22.0
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/package.json +1 -1
- package/router.d.ts +1 -1
- package/router.js +2 -2
- package/{sitemapGenerator.js → sitemap-generator.js} +4 -13
- package/sitemap-generator.test.d.ts +1 -0
- package/sitemap-generator.test.js +31 -0
- package/utils/object-to-xml.d.ts +1 -0
- package/utils/object-to-xml.js +10 -0
- /package/{sitemapGenerator.d.ts → sitemap-generator.d.ts} +0 -0
package/package.json
CHANGED
package/router.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LinkProps } from "next/link";
|
|
2
|
-
import { SitemapGeneratorOptions, SitemapGeneratorType } from "./
|
|
2
|
+
import { SitemapGeneratorOptions, SitemapGeneratorType } from "./sitemap-generator";
|
|
3
3
|
import { QueryParams } from "./types";
|
|
4
4
|
export type FunctionParametersGenerator<RouteList> = {
|
|
5
5
|
[K in keyof RouteList]: RouteList[K] extends null ? [K] : [K, RouteList[K]];
|
package/router.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createRouter = void 0;
|
|
4
4
|
const router_1 = require("next/router");
|
|
5
5
|
const qs_1 = require("qs");
|
|
6
|
-
const
|
|
6
|
+
const sitemap_generator_1 = require("./sitemap-generator");
|
|
7
7
|
function createRouter(routes) {
|
|
8
8
|
return {
|
|
9
9
|
route: (route, params = undefined) => ({
|
|
@@ -70,7 +70,7 @@ function createRouter(routes) {
|
|
|
70
70
|
}
|
|
71
71
|
return activeRoute;
|
|
72
72
|
},
|
|
73
|
-
createSitemapGenerator:
|
|
73
|
+
createSitemapGenerator: sitemap_generator_1.createSitemapGenerator,
|
|
74
74
|
routes,
|
|
75
75
|
useQueryParams: () => (0, router_1.useRouter)().query,
|
|
76
76
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createSitemapGenerator = void 0;
|
|
4
|
+
const object_to_xml_1 = require("./utils/object-to-xml");
|
|
4
5
|
function filterNullish(val) {
|
|
5
6
|
return val.filter((item) => item !== null && item !== undefined);
|
|
6
7
|
}
|
|
@@ -12,19 +13,9 @@ class SitemapGenerator {
|
|
|
12
13
|
this.toXml = () => {
|
|
13
14
|
return this.getSitemapItems().then((sitemapItems) => {
|
|
14
15
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var _a, _b;
|
|
19
|
-
return `<url>
|
|
20
|
-
<loc>${(_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.baseUrl) !== null && _b !== void 0 ? _b : ""}${item.loc}</loc>
|
|
21
|
-
${item.priority ? `<priority>${item.priority}</priority>` : ""}
|
|
22
|
-
${item.lastmod ? `<lastmod>${item.lastmod}</lastmod>` : ""}
|
|
23
|
-
${item.changefreq ? `<changefreq>${item.changefreq}</changefreq>` : ""}
|
|
24
|
-
</url>`;
|
|
25
|
-
})
|
|
26
|
-
.join("")}
|
|
27
|
-
</urlset>`;
|
|
16
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
|
|
17
|
+
${sitemapItems.map((item) => ` <url>\n${(0, object_to_xml_1.objectToXml)(item)}\n </url>`).join("\n")}
|
|
18
|
+
</urlset>`;
|
|
28
19
|
});
|
|
29
20
|
};
|
|
30
21
|
this.toJson = () => this.getSitemapItems().then(JSON.stringify);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const router_1 = require("./router");
|
|
4
|
+
const { createSitemapGenerator, routeToUrl } = (0, router_1.createRouter)({
|
|
5
|
+
index: "/",
|
|
6
|
+
catchAllSegments: "/catch-all/[...pathParams]",
|
|
7
|
+
optionalCatchAllSegments: "/catch-all-optional/[[...pathParams]]",
|
|
8
|
+
});
|
|
9
|
+
test("routeToUrl", async () => {
|
|
10
|
+
const xml = await createSitemapGenerator({})
|
|
11
|
+
.add("index", async () => ({ loc: routeToUrl("index", {}) }))
|
|
12
|
+
.add("catchAllSegments", async () => ({ loc: routeToUrl("catchAllSegments", { pathParams: ["param-1"] }) }))
|
|
13
|
+
.add("optionalCatchAllSegments", async () => ({
|
|
14
|
+
loc: routeToUrl("optionalCatchAllSegments", { pathParams: ["param-1", "param-2"] }),
|
|
15
|
+
priority: 10,
|
|
16
|
+
}))
|
|
17
|
+
.toXml();
|
|
18
|
+
expect(xml).toBe(`<?xml version="1.0" encoding="UTF-8"?>
|
|
19
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
|
|
20
|
+
<url>
|
|
21
|
+
<loc>/</loc>
|
|
22
|
+
</url>
|
|
23
|
+
<url>
|
|
24
|
+
<loc>/catch-all/param-1</loc>
|
|
25
|
+
</url>
|
|
26
|
+
<url>
|
|
27
|
+
<loc>/catch-all-optional/param-1/param-2</loc>
|
|
28
|
+
<priority>10</priority>
|
|
29
|
+
</url>
|
|
30
|
+
</urlset>`);
|
|
31
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function objectToXml(object: Record<string, string | number | null | undefined>): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.objectToXml = void 0;
|
|
4
|
+
function objectToXml(object) {
|
|
5
|
+
return Object.entries(object)
|
|
6
|
+
.filter(([, value]) => value !== null && value !== undefined)
|
|
7
|
+
.map(([key, value]) => ` <${key}>${value}</${key}>`)
|
|
8
|
+
.join("\n");
|
|
9
|
+
}
|
|
10
|
+
exports.objectToXml = objectToXml;
|
|
File without changes
|