nuxtseo-shared 0.3.0 → 0.5.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/dist/module.json +1 -1
- package/dist/runtime/server/kit.d.ts +3 -0
- package/dist/utils.d.mts +9 -0
- package/dist/utils.d.ts +9 -0
- package/dist/{runtime/pure.js → utils.mjs} +8 -2
- package/package.json +10 -5
- package/dist/runtime/pure.d.ts +0 -0
- package/src/runtime/pure.ts +0 -57
- package/src/runtime/server/kit.ts +0 -26
package/dist/module.json
CHANGED
package/dist/utils.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface CreateFilterOptions {
|
|
2
|
+
include?: (string | RegExp)[];
|
|
3
|
+
exclude?: (string | RegExp)[];
|
|
4
|
+
}
|
|
5
|
+
declare function createFilter(options?: CreateFilterOptions): (path: string) => boolean;
|
|
6
|
+
declare function withoutQuery(path: string): string;
|
|
7
|
+
|
|
8
|
+
export { createFilter, withoutQuery };
|
|
9
|
+
export type { CreateFilterOptions };
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface CreateFilterOptions {
|
|
2
|
+
include?: (string | RegExp)[];
|
|
3
|
+
exclude?: (string | RegExp)[];
|
|
4
|
+
}
|
|
5
|
+
declare function createFilter(options?: CreateFilterOptions): (path: string) => boolean;
|
|
6
|
+
declare function withoutQuery(path: string): string;
|
|
7
|
+
|
|
8
|
+
export { createFilter, withoutQuery };
|
|
9
|
+
export type { CreateFilterOptions };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { toRouteMatcher, createRouter } from 'radix3';
|
|
2
|
+
|
|
3
|
+
function createFilter(options = {}) {
|
|
3
4
|
const include = options.include || [];
|
|
4
5
|
const exclude = options.exclude || [];
|
|
5
6
|
if (include.length === 0 && exclude.length === 0)
|
|
@@ -34,3 +35,8 @@ export function createFilter(options = {}) {
|
|
|
34
35
|
return include.length === 0;
|
|
35
36
|
};
|
|
36
37
|
}
|
|
38
|
+
function withoutQuery(path) {
|
|
39
|
+
return path.split("?")[0];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { createFilter, withoutQuery };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxtseo-shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"description": "Shared utilities for Nuxt SEO modules.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -38,15 +38,20 @@
|
|
|
38
38
|
"types": "./dist/telemetry.d.mts",
|
|
39
39
|
"import": "./dist/telemetry.mjs"
|
|
40
40
|
},
|
|
41
|
-
"./
|
|
42
|
-
|
|
41
|
+
"./utils": {
|
|
42
|
+
"types": "./dist/utils.d.mts",
|
|
43
|
+
"import": "./dist/utils.mjs"
|
|
44
|
+
},
|
|
45
|
+
"./server": {
|
|
46
|
+
"types": "./dist/server.d.mts",
|
|
47
|
+
"import": "./dist/server.mjs"
|
|
48
|
+
},
|
|
43
49
|
"./package.json": "./package.json"
|
|
44
50
|
},
|
|
45
51
|
"main": "./dist/module.mjs",
|
|
46
52
|
"types": "./dist/types.d.mts",
|
|
47
53
|
"files": [
|
|
48
|
-
"dist"
|
|
49
|
-
"src/runtime"
|
|
54
|
+
"dist"
|
|
50
55
|
],
|
|
51
56
|
"peerDependencies": {
|
|
52
57
|
"@nuxt/schema": "^3.16.0 || ^4.0.0",
|
package/dist/runtime/pure.d.ts
DELETED
|
File without changes
|
package/src/runtime/pure.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { createRouter, toRouteMatcher } from 'radix3'
|
|
2
|
-
|
|
3
|
-
export interface CreateFilterOptions {
|
|
4
|
-
include?: (string | RegExp)[]
|
|
5
|
-
exclude?: (string | RegExp)[]
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function createFilter(options: CreateFilterOptions = {}): (path: string) => boolean {
|
|
9
|
-
const include = options.include || []
|
|
10
|
-
const exclude = options.exclude || []
|
|
11
|
-
if (include.length === 0 && exclude.length === 0)
|
|
12
|
-
return () => true
|
|
13
|
-
|
|
14
|
-
// Pre-compute regex and string rules once
|
|
15
|
-
const excludeRegex = exclude.filter(r => r instanceof RegExp) as RegExp[]
|
|
16
|
-
const includeRegex = include.filter(r => r instanceof RegExp) as RegExp[]
|
|
17
|
-
const excludeStrings = exclude.filter(r => typeof r === 'string') as string[]
|
|
18
|
-
const includeStrings = include.filter(r => typeof r === 'string') as string[]
|
|
19
|
-
|
|
20
|
-
// Pre-create routers once (expensive operation)
|
|
21
|
-
const excludeMatcher = excludeStrings.length > 0
|
|
22
|
-
? toRouteMatcher(createRouter({
|
|
23
|
-
routes: Object.fromEntries(excludeStrings.map(r => [r, true])),
|
|
24
|
-
strictTrailingSlash: false,
|
|
25
|
-
}))
|
|
26
|
-
: null
|
|
27
|
-
const includeMatcher = includeStrings.length > 0
|
|
28
|
-
? toRouteMatcher(createRouter({
|
|
29
|
-
routes: Object.fromEntries(includeStrings.map(r => [r, true])),
|
|
30
|
-
strictTrailingSlash: false,
|
|
31
|
-
}))
|
|
32
|
-
: null
|
|
33
|
-
|
|
34
|
-
// Pre-create Sets for O(1) exact match lookups
|
|
35
|
-
const excludeExact = new Set(excludeStrings)
|
|
36
|
-
const includeExact = new Set(includeStrings)
|
|
37
|
-
|
|
38
|
-
return function (path: string): boolean {
|
|
39
|
-
// Check exclude rules first
|
|
40
|
-
if (excludeRegex.some(r => r.test(path)))
|
|
41
|
-
return false
|
|
42
|
-
if (excludeExact.has(path))
|
|
43
|
-
return false
|
|
44
|
-
if (excludeMatcher && excludeMatcher.matchAll(path).length > 0)
|
|
45
|
-
return false
|
|
46
|
-
|
|
47
|
-
// Check include rules
|
|
48
|
-
if (includeRegex.some(r => r.test(path)))
|
|
49
|
-
return true
|
|
50
|
-
if (includeExact.has(path))
|
|
51
|
-
return true
|
|
52
|
-
if (includeMatcher && includeMatcher.matchAll(path).length > 0)
|
|
53
|
-
return true
|
|
54
|
-
|
|
55
|
-
return include.length === 0
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { NitroRouteRules } from 'nitropack'
|
|
2
|
-
import { defu } from 'defu'
|
|
3
|
-
import { useRuntimeConfig } from 'nitropack/runtime'
|
|
4
|
-
import { createRouter as createRadixRouter, toRouteMatcher } from 'radix3'
|
|
5
|
-
import { withoutBase, withoutTrailingSlash } from 'ufo'
|
|
6
|
-
|
|
7
|
-
export function withoutQuery(path: string): string {
|
|
8
|
-
return path.split('?')[0]
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function createNitroRouteRuleMatcher(): (path: string) => NitroRouteRules {
|
|
12
|
-
const { nitro, app } = useRuntimeConfig()
|
|
13
|
-
const _routeRulesMatcher = toRouteMatcher(
|
|
14
|
-
createRadixRouter({
|
|
15
|
-
routes: Object.fromEntries(
|
|
16
|
-
Object.entries(nitro?.routeRules || {})
|
|
17
|
-
.map(([path, rules]) => [withoutTrailingSlash(path), rules]),
|
|
18
|
-
),
|
|
19
|
-
}),
|
|
20
|
-
)
|
|
21
|
-
return (path: string) => {
|
|
22
|
-
return defu({}, ..._routeRulesMatcher.matchAll(
|
|
23
|
-
withoutBase(withoutTrailingSlash(withoutQuery(path)), app.baseURL),
|
|
24
|
-
).reverse()) as NitroRouteRules
|
|
25
|
-
}
|
|
26
|
-
}
|