@hamur/seo 0.0.2 → 0.0.3
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/src/index.js +12 -3
- package/dist/types/src/sitemap/paths.d.ts +1 -1
- package/package.json +8 -8
- package/src/build/llms.ts +2 -1
- package/src/server/sitemap.ts +25 -5
- package/src/sitemap/paths.ts +11 -3
package/dist/src/index.js
CHANGED
|
@@ -457,7 +457,7 @@ function setupLinkChecker(value, hamur) {
|
|
|
457
457
|
import { existsSync as existsSync2 } from "node:fs";
|
|
458
458
|
import { join as join3 } from "node:path";
|
|
459
459
|
import { addTemplate, createRouteRules as createRouteRules2 } from "hamur/kit";
|
|
460
|
-
import { absoluteUrl } from "hamur/server/internal";
|
|
460
|
+
import { absoluteUrl, accessRuleOf } from "hamur/server/internal";
|
|
461
461
|
|
|
462
462
|
// packages/seo/src/runtime/markdown.ts
|
|
463
463
|
var VOID = new Set([
|
|
@@ -907,6 +907,8 @@ export const rootId = "";
|
|
|
907
907
|
return;
|
|
908
908
|
if (excluded?.match(page.path).matches.length)
|
|
909
909
|
return;
|
|
910
|
+
if (accessRuleOf(hamur.routeRules)(page.path, markdownPath(page.path)))
|
|
911
|
+
return;
|
|
910
912
|
const origin = hamur.options.site.url ?? process.env.HAMUR_SITE_URL ?? "http://localhost";
|
|
911
913
|
const text = htmlToMarkdown(page.body, { base: absoluteUrl(origin, baseURL, page.path), rootId });
|
|
912
914
|
if (text !== "")
|
|
@@ -1209,7 +1211,9 @@ function pageAlternates(pages, i18n, listed, clean) {
|
|
|
1209
1211
|
|
|
1210
1212
|
// packages/seo/src/sitemap/paths.ts
|
|
1211
1213
|
import { createRouteRules as createRouteRules3 } from "hamur/kit";
|
|
1214
|
+
import { accessRuleOf as accessRuleOf2 } from "hamur/server/internal";
|
|
1212
1215
|
var ORIGIN2 = "http://localhost";
|
|
1216
|
+
var FILES2 = new Set(["/_version.json", "/sw.js", "/robots.txt", "/sitemap.xml"]);
|
|
1213
1217
|
var isDynamic = (path) => /[:*]/.test(path);
|
|
1214
1218
|
function clean(path) {
|
|
1215
1219
|
if (!path.startsWith("/") || path.startsWith("//"))
|
|
@@ -1223,14 +1227,19 @@ function clean(path) {
|
|
|
1223
1227
|
function sitemapPaths({ pages, listed, rules, exclude }) {
|
|
1224
1228
|
const matcher = createRouteRules3({ ...rules });
|
|
1225
1229
|
const excluded = createRouteRules3(Object.fromEntries(exclude.map((pattern) => [pattern, {}])));
|
|
1230
|
+
const guard = accessRuleOf2({ ...rules });
|
|
1226
1231
|
const found = new Set;
|
|
1227
|
-
for (const path of [
|
|
1232
|
+
for (const path of [
|
|
1233
|
+
...pages.filter((page) => !isDynamic(page)),
|
|
1234
|
+
...listed,
|
|
1235
|
+
...matcher.prerenderPaths().filter((path) => !FILES2.has(path))
|
|
1236
|
+
]) {
|
|
1228
1237
|
const clear = clean(path);
|
|
1229
1238
|
if (clear !== undefined)
|
|
1230
1239
|
found.add(clear);
|
|
1231
1240
|
}
|
|
1232
1241
|
return [...found].filter((path) => {
|
|
1233
|
-
if (excluded.match(path).matches.length)
|
|
1242
|
+
if (excluded.match(path).matches.length || guard(path, "/sitemap.xml"))
|
|
1234
1243
|
return false;
|
|
1235
1244
|
const { rule } = matcher.match(path);
|
|
1236
1245
|
return rule.noindex !== true && rule.redirect === undefined;
|
|
@@ -9,5 +9,5 @@ export interface PathsInput {
|
|
|
9
9
|
}
|
|
10
10
|
/** An app path in the form a request has: query and hash dropped, percent-encoded, one trailing `/` run removed; `undefined` for anything else. */
|
|
11
11
|
export declare function clean(path: string): string | undefined;
|
|
12
|
-
/** The page routes without params, then the paths the build knows the prerender seeds, each once, minus `noindex`, `redirect` and `
|
|
12
|
+
/** The page routes without params, then the paths the build knows the prerender seeds, each once, minus `noindex`, `redirect`, `exclude` and those an access rule covers that `/sitemap.xml` is not under. */
|
|
13
13
|
export declare function sitemapPaths({ pages, listed, rules, exclude }: PathsInput): string[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hamur/seo",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -87,13 +87,13 @@
|
|
|
87
87
|
],
|
|
88
88
|
"dependencies": {},
|
|
89
89
|
"peerDependencies": {
|
|
90
|
-
"hamur": "~0.0.
|
|
91
|
-
"@hamur/adapter-react": "^0.0.
|
|
92
|
-
"@hamur/adapter-vue": "^0.0.
|
|
93
|
-
"@hamur/adapter-preact": "^0.0.
|
|
94
|
-
"@hamur/adapter-svelte": "^0.0.
|
|
95
|
-
"@hamur/adapter-solid": "^0.0.
|
|
96
|
-
"@hamur/adapter-html": "^0.0.
|
|
90
|
+
"hamur": "~0.0.3",
|
|
91
|
+
"@hamur/adapter-react": "^0.0.3",
|
|
92
|
+
"@hamur/adapter-vue": "^0.0.3",
|
|
93
|
+
"@hamur/adapter-preact": "^0.0.3",
|
|
94
|
+
"@hamur/adapter-svelte": "^0.0.3",
|
|
95
|
+
"@hamur/adapter-solid": "^0.0.3",
|
|
96
|
+
"@hamur/adapter-html": "^0.0.3",
|
|
97
97
|
"react": "^19.3.1",
|
|
98
98
|
"preact": "^11.0.2",
|
|
99
99
|
"vue": "^3.5.44",
|
package/src/build/llms.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync } from "node:fs"
|
|
2
2
|
import { join } from "node:path"
|
|
3
3
|
import { addTemplate, createRouteRules, type HamurContext } from "hamur/kit"
|
|
4
|
-
import { absoluteUrl } from "hamur/server/internal"
|
|
4
|
+
import { absoluteUrl, accessRuleOf } from "hamur/server/internal"
|
|
5
5
|
import { htmlToMarkdown } from "../runtime/markdown.ts"
|
|
6
6
|
import { checkOwner, resolveLlms, type ResolvedLlms } from "../llms/options.ts"
|
|
7
7
|
import { markdownPath } from "../llms/paths.ts"
|
|
@@ -62,6 +62,7 @@ export function setupLlms(llms: ResolvedLlms | undefined, hamur: HamurContext):
|
|
|
62
62
|
)
|
|
63
63
|
return
|
|
64
64
|
if (excluded?.match(page.path).matches.length) return
|
|
65
|
+
if (accessRuleOf(hamur.routeRules)(page.path, markdownPath(page.path))) return
|
|
65
66
|
const origin = hamur.options.site.url ?? process.env.HAMUR_SITE_URL ?? "http://localhost"
|
|
66
67
|
const text = htmlToMarkdown(page.body, { base: absoluteUrl(origin, baseURL, page.path), rootId })
|
|
67
68
|
if (text !== "") converted.set(markdownPath(page.path), text)
|
package/src/server/sitemap.ts
CHANGED
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
useSiteConfig,
|
|
11
11
|
type HamurEvent,
|
|
12
12
|
} from "hamur/server"
|
|
13
|
+
import { appAccessRuleOf } from "hamur/server/internal"
|
|
14
|
+
import { pathBelow } from "../llms/paths.ts"
|
|
13
15
|
import { mergeUrls, oversize, partCount, partRange, rootXml } from "../sitemap/answer.ts"
|
|
14
16
|
import { readCount, readRows, readSource } from "../sitemap/entries.ts"
|
|
15
17
|
import { absoluteUrl, urlsetXml, type SitemapUrl } from "../sitemap/xml.ts"
|
|
@@ -19,6 +21,18 @@ const LOOP = "@hamur/seo: a sitemap source fetched the sitemap"
|
|
|
19
21
|
const LOOP_HEADER = "x-hamur-sitemap-source"
|
|
20
22
|
const XML = { "content-type": "application/xml; charset=utf-8" }
|
|
21
23
|
|
|
24
|
+
/** The URLs whose page is as public as the sitemap. */
|
|
25
|
+
function listable(urls: SitemapUrl[], origin: string): SitemapUrl[] {
|
|
26
|
+
const ruleOf = appAccessRuleOf()
|
|
27
|
+
if (!ruleOf) return urls
|
|
28
|
+
const site = new URL(origin).origin
|
|
29
|
+
return urls.filter(({ loc }) => {
|
|
30
|
+
const url = new URL(loc)
|
|
31
|
+
const path = url.origin === site ? pathBelow(url.pathname, baseURL) : undefined
|
|
32
|
+
return path === undefined || ruleOf(path, "/sitemap.xml") === undefined
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
22
36
|
class SourceFailure extends Error {
|
|
23
37
|
constructor(
|
|
24
38
|
readonly source: string,
|
|
@@ -89,7 +103,10 @@ const cachedListing = defineCachedFunction(
|
|
|
89
103
|
return result.value
|
|
90
104
|
})
|
|
91
105
|
return {
|
|
92
|
-
urls:
|
|
106
|
+
urls: listable(
|
|
107
|
+
mergeUrls([pages, ...answers.flatMap((answer) => ("urls" in answer ? [answer.urls] : []))]),
|
|
108
|
+
origin,
|
|
109
|
+
),
|
|
93
110
|
paged: answers.flatMap((answer) => ("count" in answer ? [answer.count] : [])),
|
|
94
111
|
}
|
|
95
112
|
},
|
|
@@ -115,11 +132,14 @@ async function readRange(
|
|
|
115
132
|
const data = await askSource(source, lo - start, hi - lo)
|
|
116
133
|
try {
|
|
117
134
|
urls.push(
|
|
118
|
-
...
|
|
135
|
+
...listable(
|
|
136
|
+
readSource(source, readRows(source, data, hi - lo), {
|
|
137
|
+
origin,
|
|
138
|
+
baseURL,
|
|
139
|
+
warn: (message) => log.warn(message),
|
|
140
|
+
}),
|
|
119
141
|
origin,
|
|
120
|
-
|
|
121
|
-
warn: (message) => log.warn(message),
|
|
122
|
-
}),
|
|
142
|
+
),
|
|
123
143
|
)
|
|
124
144
|
} catch (error) {
|
|
125
145
|
throw new SourceFailure(source, reason(error))
|
package/src/sitemap/paths.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createRouteRules } from "hamur/kit"
|
|
2
|
+
import { accessRuleOf } from "hamur/server/internal"
|
|
2
3
|
|
|
3
4
|
export interface PathsInput {
|
|
4
5
|
/** The paths of the page route table, copies of `@hamur/i18n` included, in table order. */
|
|
@@ -10,6 +11,8 @@ export interface PathsInput {
|
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
const ORIGIN = "http://localhost"
|
|
14
|
+
/** Files with a rule of their own, which a `/**` rule with `prerender: true` merges into. */
|
|
15
|
+
const FILES = new Set(["/_version.json", "/sw.js", "/robots.txt", "/sitemap.xml"])
|
|
13
16
|
const isDynamic = (path: string) => /[:*]/.test(path)
|
|
14
17
|
|
|
15
18
|
/** An app path in the form a request has: query and hash dropped, percent-encoded, one trailing `/` run removed; `undefined` for anything else. */
|
|
@@ -22,17 +25,22 @@ export function clean(path: string): string | undefined {
|
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
/** The page routes without params, then the paths the build knows the prerender seeds, each once, minus `noindex`, `redirect` and `
|
|
28
|
+
/** The page routes without params, then the paths the build knows the prerender seeds, each once, minus `noindex`, `redirect`, `exclude` and those an access rule covers that `/sitemap.xml` is not under. */
|
|
26
29
|
export function sitemapPaths({ pages, listed, rules, exclude }: PathsInput): string[] {
|
|
27
30
|
const matcher = createRouteRules({ ...rules })
|
|
28
31
|
const excluded = createRouteRules(Object.fromEntries(exclude.map((pattern) => [pattern, {}])))
|
|
32
|
+
const guard = accessRuleOf({ ...rules })
|
|
29
33
|
const found = new Set<string>()
|
|
30
|
-
for (const path of [
|
|
34
|
+
for (const path of [
|
|
35
|
+
...pages.filter((page) => !isDynamic(page)),
|
|
36
|
+
...listed,
|
|
37
|
+
...matcher.prerenderPaths().filter((path) => !FILES.has(path)),
|
|
38
|
+
]) {
|
|
31
39
|
const clear = clean(path)
|
|
32
40
|
if (clear !== undefined) found.add(clear)
|
|
33
41
|
}
|
|
34
42
|
return [...found].filter((path) => {
|
|
35
|
-
if (excluded.match(path).matches.length) return false
|
|
43
|
+
if (excluded.match(path).matches.length || guard(path, "/sitemap.xml")) return false
|
|
36
44
|
const { rule } = matcher.match(path)
|
|
37
45
|
return rule.noindex !== true && rule.redirect === undefined
|
|
38
46
|
})
|