@hamur/seo 0.0.0-stage → 0.0.1
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/LICENSE +22 -0
- package/README.md +26 -2
- package/dist/chunks/bun-index-rnjhv41c.js +62 -0
- package/dist/chunks/bun-index-xf4srhvn.js +97 -0
- package/dist/src/adapters/html.js +40 -0
- package/dist/src/adapters/preact.js +36 -0
- package/dist/src/adapters/react.js +36 -0
- package/dist/src/adapters/solid.js +35 -0
- package/dist/src/adapters/svelte.js +35 -0
- package/dist/src/adapters/vue.js +43 -0
- package/dist/src/index.js +1375 -0
- package/dist/src/schema.js +51 -0
- package/dist/src/server/index.js +1 -0
- package/dist/src/share.js +40 -0
- package/dist/types/src/adapters/html.d.ts +6 -0
- package/dist/types/src/adapters/preact.d.ts +5 -0
- package/dist/types/src/adapters/react.d.ts +5 -0
- package/dist/types/src/adapters/solid.d.ts +6 -0
- package/dist/types/src/adapters/svelte.d.ts +5 -0
- package/dist/types/src/adapters/vue.d.ts +9 -0
- package/dist/types/src/build/links.d.ts +4 -0
- package/dist/types/src/build/llms.d.ts +6 -0
- package/dist/types/src/build/own.d.ts +5 -0
- package/dist/types/src/build/robots.d.ts +3 -0
- package/dist/types/src/build/schema.d.ts +4 -0
- package/dist/types/src/build/sitemap.d.ts +7 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/links/check.d.ts +7 -0
- package/dist/types/src/links/external.d.ts +6 -0
- package/dist/types/src/links/options.d.ts +12 -0
- package/dist/types/src/links/report.d.ts +4 -0
- package/dist/types/src/links/scan.d.ts +24 -0
- package/dist/types/src/llms/options.d.ts +9 -0
- package/dist/types/src/llms/paths.d.ts +8 -0
- package/dist/types/src/llms/text.d.ts +12 -0
- package/dist/types/src/module.d.ts +3 -0
- package/dist/types/src/robots/ai-bots.d.ts +2 -0
- package/dist/types/src/robots/body.d.ts +16 -0
- package/dist/types/src/robots/options.d.ts +9 -0
- package/dist/types/src/runtime/breadcrumbs.d.ts +37 -0
- package/dist/types/src/runtime/markdown.d.ts +15 -0
- package/dist/types/src/runtime/schema-plugin.d.ts +2 -0
- package/dist/types/src/runtime/schema-store.d.ts +34 -0
- package/dist/types/src/schema/graph.d.ts +13 -0
- package/dist/types/src/schema/helpers.d.ts +358 -0
- package/dist/types/src/schema/options.d.ts +7 -0
- package/dist/types/src/schema.d.ts +10 -0
- package/dist/types/src/server/agent.d.ts +4 -0
- package/dist/types/src/server/door.d.ts +5 -0
- package/dist/types/src/server/index.d.ts +1 -0
- package/dist/types/src/server/llms.d.ts +2 -0
- package/dist/types/src/server/render.d.ts +9 -0
- package/dist/types/src/server/robots.d.ts +1 -0
- package/dist/types/src/server/sitemap.d.ts +5 -0
- package/dist/types/src/share.d.ts +18 -0
- package/dist/types/src/sitemap/alternates.d.ts +14 -0
- package/dist/types/src/sitemap/answer.d.ts +6 -0
- package/dist/types/src/sitemap/entries.d.ts +9 -0
- package/dist/types/src/sitemap/options.d.ts +7 -0
- package/dist/types/src/sitemap/paths.d.ts +13 -0
- package/dist/types/src/sitemap/xml.d.ts +23 -0
- package/dist/types/src/types.d.ts +73 -0
- package/package.json +106 -4
- package/src/adapters/html.ts +43 -0
- package/src/adapters/preact.ts +37 -0
- package/src/adapters/react.ts +37 -0
- package/src/adapters/solid.ts +38 -0
- package/src/adapters/svelte.ts +37 -0
- package/src/adapters/vue.ts +55 -0
- package/src/build/links.ts +13 -0
- package/src/build/llms.ts +79 -0
- package/src/build/own.ts +46 -0
- package/src/build/robots.ts +58 -0
- package/src/build/schema.ts +23 -0
- package/src/build/sitemap.ts +101 -0
- package/src/env.d.ts +44 -0
- package/src/index.ts +14 -0
- package/src/links/check.ts +233 -0
- package/src/links/external.ts +41 -0
- package/src/links/options.ts +69 -0
- package/src/links/report.ts +49 -0
- package/src/links/scan.ts +123 -0
- package/src/llms/options.ts +49 -0
- package/src/llms/paths.ts +33 -0
- package/src/llms/text.ts +26 -0
- package/src/module.ts +22 -0
- package/src/robots/ai-bots.ts +14 -0
- package/src/robots/body.ts +51 -0
- package/src/robots/options.ts +75 -0
- package/src/runtime/breadcrumbs.ts +84 -0
- package/src/runtime/markdown.ts +381 -0
- package/src/runtime/schema-plugin.ts +22 -0
- package/src/runtime/schema-store.ts +144 -0
- package/src/schema/graph.ts +125 -0
- package/src/schema/helpers.ts +372 -0
- package/src/schema/options.ts +39 -0
- package/src/schema.ts +5 -0
- package/src/server/agent.ts +45 -0
- package/src/server/door.ts +8 -0
- package/src/server/index.ts +1 -0
- package/src/server/llms.ts +139 -0
- package/src/server/render.ts +33 -0
- package/src/server/robots.ts +19 -0
- package/src/server/sitemap.ts +222 -0
- package/src/share.ts +56 -0
- package/src/sitemap/alternates.ts +66 -0
- package/src/sitemap/answer.ts +42 -0
- package/src/sitemap/entries.ts +136 -0
- package/src/sitemap/options.ts +47 -0
- package/src/sitemap/paths.ts +39 -0
- package/src/sitemap/xml.ts +71 -0
- package/src/types.ts +89 -0
package/package.json
CHANGED
|
@@ -1,6 +1,108 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hamur/seo",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/productdevbook/hamur.git",
|
|
9
|
+
"directory": "packages/seo"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/types/src/index.d.ts",
|
|
14
|
+
"default": "./dist/src/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./server": {
|
|
17
|
+
"types": "./dist/types/src/server/index.d.ts",
|
|
18
|
+
"default": "./dist/src/server/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./schema": {
|
|
21
|
+
"types": "./dist/types/src/schema.d.ts",
|
|
22
|
+
"default": "./dist/src/schema.js"
|
|
23
|
+
},
|
|
24
|
+
"./share": {
|
|
25
|
+
"types": "./dist/types/src/share.d.ts",
|
|
26
|
+
"default": "./dist/src/share.js"
|
|
27
|
+
},
|
|
28
|
+
"./react": {
|
|
29
|
+
"types": "./dist/types/src/adapters/react.d.ts",
|
|
30
|
+
"default": "./dist/src/adapters/react.js"
|
|
31
|
+
},
|
|
32
|
+
"./vue": {
|
|
33
|
+
"types": "./dist/types/src/adapters/vue.d.ts",
|
|
34
|
+
"default": "./dist/src/adapters/vue.js"
|
|
35
|
+
},
|
|
36
|
+
"./preact": {
|
|
37
|
+
"types": "./dist/types/src/adapters/preact.d.ts",
|
|
38
|
+
"default": "./dist/src/adapters/preact.js"
|
|
39
|
+
},
|
|
40
|
+
"./svelte": {
|
|
41
|
+
"types": "./dist/types/src/adapters/svelte.d.ts",
|
|
42
|
+
"default": "./dist/src/adapters/svelte.js"
|
|
43
|
+
},
|
|
44
|
+
"./solid": {
|
|
45
|
+
"types": "./dist/types/src/adapters/solid.d.ts",
|
|
46
|
+
"default": "./dist/src/adapters/solid.js"
|
|
47
|
+
},
|
|
48
|
+
"./html": {
|
|
49
|
+
"types": "./dist/types/src/adapters/html.d.ts",
|
|
50
|
+
"default": "./dist/src/adapters/html.js"
|
|
51
|
+
},
|
|
52
|
+
"./package.json": "./package.json"
|
|
53
|
+
},
|
|
54
|
+
"files": [
|
|
55
|
+
"dist",
|
|
56
|
+
"src"
|
|
57
|
+
],
|
|
58
|
+
"dependencies": {},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"hamur": "~0.0.1",
|
|
61
|
+
"@hamur/adapter-react": "^0.0.1",
|
|
62
|
+
"@hamur/adapter-vue": "^0.0.1",
|
|
63
|
+
"@hamur/adapter-preact": "^0.0.1",
|
|
64
|
+
"@hamur/adapter-svelte": "^0.0.1",
|
|
65
|
+
"@hamur/adapter-solid": "^0.0.1",
|
|
66
|
+
"@hamur/adapter-html": "^0.0.1",
|
|
67
|
+
"react": "^19.3.1",
|
|
68
|
+
"preact": "^11.0.2",
|
|
69
|
+
"vue": "^3.5.44",
|
|
70
|
+
"svelte": "^5.57.2",
|
|
71
|
+
"solid-js": "^2.0.4"
|
|
72
|
+
},
|
|
73
|
+
"peerDependenciesMeta": {
|
|
74
|
+
"@hamur/adapter-react": {
|
|
75
|
+
"optional": true
|
|
76
|
+
},
|
|
77
|
+
"@hamur/adapter-vue": {
|
|
78
|
+
"optional": true
|
|
79
|
+
},
|
|
80
|
+
"@hamur/adapter-preact": {
|
|
81
|
+
"optional": true
|
|
82
|
+
},
|
|
83
|
+
"@hamur/adapter-svelte": {
|
|
84
|
+
"optional": true
|
|
85
|
+
},
|
|
86
|
+
"@hamur/adapter-solid": {
|
|
87
|
+
"optional": true
|
|
88
|
+
},
|
|
89
|
+
"@hamur/adapter-html": {
|
|
90
|
+
"optional": true
|
|
91
|
+
},
|
|
92
|
+
"react": {
|
|
93
|
+
"optional": true
|
|
94
|
+
},
|
|
95
|
+
"preact": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"vue": {
|
|
99
|
+
"optional": true
|
|
100
|
+
},
|
|
101
|
+
"svelte": {
|
|
102
|
+
"optional": true
|
|
103
|
+
},
|
|
104
|
+
"solid-js": {
|
|
105
|
+
"optional": true
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useApp, useId, useRoute } from "@hamur/adapter-html"
|
|
2
|
+
import type { AppContext } from "hamur/app"
|
|
3
|
+
import { appOfCall, nodeList, schemaStoreOf } from "../runtime/schema-store.ts"
|
|
4
|
+
import {
|
|
5
|
+
breadcrumbItems,
|
|
6
|
+
breadcrumbNodes,
|
|
7
|
+
i18nOf,
|
|
8
|
+
routeOf,
|
|
9
|
+
type BreadcrumbItem,
|
|
10
|
+
type BreadcrumbOptions,
|
|
11
|
+
} from "../runtime/breadcrumbs.ts"
|
|
12
|
+
import type { SchemaNode } from "../schema.ts"
|
|
13
|
+
|
|
14
|
+
export type { BreadcrumbItem, BreadcrumbOptions, SchemaNode }
|
|
15
|
+
|
|
16
|
+
const hooked = new WeakSet<AppContext>()
|
|
17
|
+
const last = new WeakMap<AppContext, number>()
|
|
18
|
+
|
|
19
|
+
/** The calls of a page render are numbered in order; a number that does not grow starts a new render, so the calls of the one before are dropped. */
|
|
20
|
+
export function useSchemaOrg(nodes: SchemaNode | SchemaNode[]): void {
|
|
21
|
+
const app = appOfCall(useApp)
|
|
22
|
+
const store = schemaStoreOf(app)
|
|
23
|
+
if (!hooked.has(app)) {
|
|
24
|
+
hooked.add(app)
|
|
25
|
+
app.hooks.hook("page:start", () => store.clear())
|
|
26
|
+
}
|
|
27
|
+
const id = useId()
|
|
28
|
+
const index = Number(id.slice(2))
|
|
29
|
+
if (index <= (last.get(app) ?? -1)) store.clear()
|
|
30
|
+
last.set(app, index)
|
|
31
|
+
store.set(id, nodeList(nodes))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function useBreadcrumbItems(options: BreadcrumbOptions = {}): BreadcrumbItem[] {
|
|
35
|
+
const app = appOfCall(useApp)
|
|
36
|
+
const path = useRoute().path
|
|
37
|
+
const items = breadcrumbItems(
|
|
38
|
+
{ path, resolve: (to) => routeOf(app, to), titles: schemaStoreOf(app).titles, i18n: i18nOf(app) },
|
|
39
|
+
options,
|
|
40
|
+
)
|
|
41
|
+
useSchemaOrg(breadcrumbNodes(app, items, options))
|
|
42
|
+
return items
|
|
43
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useApp, useRoute } from "@hamur/adapter-preact"
|
|
2
|
+
import { useLayoutEffect, useRef } from "preact/hooks"
|
|
3
|
+
import { appOfCall, nodeList, schemaStoreOf } from "../runtime/schema-store.ts"
|
|
4
|
+
import {
|
|
5
|
+
breadcrumbItems,
|
|
6
|
+
breadcrumbNodes,
|
|
7
|
+
i18nOf,
|
|
8
|
+
routeOf,
|
|
9
|
+
type BreadcrumbItem,
|
|
10
|
+
type BreadcrumbOptions,
|
|
11
|
+
} from "../runtime/breadcrumbs.ts"
|
|
12
|
+
import type { SchemaNode } from "../schema.ts"
|
|
13
|
+
|
|
14
|
+
export type { BreadcrumbItem, BreadcrumbOptions, SchemaNode }
|
|
15
|
+
|
|
16
|
+
const isServer = typeof window === "undefined"
|
|
17
|
+
|
|
18
|
+
export function useSchemaOrg(nodes: SchemaNode | SchemaNode[]): void {
|
|
19
|
+
const store = schemaStoreOf(appOfCall(useApp))
|
|
20
|
+
const key = useRef({}).current
|
|
21
|
+
if (isServer) store.set(key, nodeList(nodes))
|
|
22
|
+
useLayoutEffect(() => {
|
|
23
|
+
store.set(key, nodeList(nodes))
|
|
24
|
+
})
|
|
25
|
+
useLayoutEffect(() => () => store.remove(key), [store, key])
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function useBreadcrumbItems(options: BreadcrumbOptions = {}): BreadcrumbItem[] {
|
|
29
|
+
const app = appOfCall(useApp)
|
|
30
|
+
const path = useRoute().path
|
|
31
|
+
const items = breadcrumbItems(
|
|
32
|
+
{ path, resolve: (to) => routeOf(app, to), titles: schemaStoreOf(app).titles, i18n: i18nOf(app) },
|
|
33
|
+
options,
|
|
34
|
+
)
|
|
35
|
+
useSchemaOrg(breadcrumbNodes(app, items, options))
|
|
36
|
+
return items
|
|
37
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useApp, useRoute } from "@hamur/adapter-react"
|
|
2
|
+
import { useId, useLayoutEffect } from "react"
|
|
3
|
+
import { appOfCall, nodeList, schemaStoreOf } from "../runtime/schema-store.ts"
|
|
4
|
+
import {
|
|
5
|
+
breadcrumbItems,
|
|
6
|
+
breadcrumbNodes,
|
|
7
|
+
i18nOf,
|
|
8
|
+
routeOf,
|
|
9
|
+
type BreadcrumbItem,
|
|
10
|
+
type BreadcrumbOptions,
|
|
11
|
+
} from "../runtime/breadcrumbs.ts"
|
|
12
|
+
import type { SchemaNode } from "../schema.ts"
|
|
13
|
+
|
|
14
|
+
export type { BreadcrumbItem, BreadcrumbOptions, SchemaNode }
|
|
15
|
+
|
|
16
|
+
const isServer = typeof window === "undefined"
|
|
17
|
+
|
|
18
|
+
export function useSchemaOrg(nodes: SchemaNode | SchemaNode[]): void {
|
|
19
|
+
const store = schemaStoreOf(appOfCall(useApp))
|
|
20
|
+
const key = useId()
|
|
21
|
+
if (isServer) store.set(key, nodeList(nodes))
|
|
22
|
+
useLayoutEffect(() => {
|
|
23
|
+
store.set(key, nodeList(nodes))
|
|
24
|
+
})
|
|
25
|
+
useLayoutEffect(() => () => store.remove(key), [store, key])
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function useBreadcrumbItems(options: BreadcrumbOptions = {}): BreadcrumbItem[] {
|
|
29
|
+
const app = appOfCall(useApp)
|
|
30
|
+
const path = useRoute().path
|
|
31
|
+
const items = breadcrumbItems(
|
|
32
|
+
{ path, resolve: (to) => routeOf(app, to), titles: schemaStoreOf(app).titles, i18n: i18nOf(app) },
|
|
33
|
+
options,
|
|
34
|
+
)
|
|
35
|
+
useSchemaOrg(breadcrumbNodes(app, items, options))
|
|
36
|
+
return items
|
|
37
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useApp, useHead, useRoute } from "@hamur/adapter-solid"
|
|
2
|
+
import { createMemo, onCleanup, type Accessor } from "solid-js"
|
|
3
|
+
import { appOfCall, nodeList, schemaStoreOf } from "../runtime/schema-store.ts"
|
|
4
|
+
import {
|
|
5
|
+
breadcrumbItems,
|
|
6
|
+
breadcrumbNodes,
|
|
7
|
+
i18nOf,
|
|
8
|
+
routeOf,
|
|
9
|
+
type BreadcrumbItem,
|
|
10
|
+
type BreadcrumbOptions,
|
|
11
|
+
} from "../runtime/breadcrumbs.ts"
|
|
12
|
+
import type { SchemaNode } from "../schema.ts"
|
|
13
|
+
|
|
14
|
+
export type { BreadcrumbItem, BreadcrumbOptions, SchemaNode }
|
|
15
|
+
|
|
16
|
+
export function useSchemaOrg(nodes: SchemaNode | SchemaNode[] | (() => SchemaNode | SchemaNode[])): void {
|
|
17
|
+
const store = schemaStoreOf(appOfCall(useApp))
|
|
18
|
+
const key = {}
|
|
19
|
+
// useHead tracks the getter in an effect and owns the apply.
|
|
20
|
+
useHead(() => {
|
|
21
|
+
store.set(key, nodeList(typeof nodes === "function" ? nodes() : nodes))
|
|
22
|
+
return {}
|
|
23
|
+
})
|
|
24
|
+
if (typeof document !== "undefined") onCleanup(() => store.remove(key))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function useBreadcrumbItems(options: BreadcrumbOptions = {}): Accessor<BreadcrumbItem[]> {
|
|
28
|
+
const app = appOfCall(useApp)
|
|
29
|
+
const route = useRoute()
|
|
30
|
+
const items = createMemo(() =>
|
|
31
|
+
breadcrumbItems(
|
|
32
|
+
{ path: route().path, resolve: (to) => routeOf(app, to), titles: schemaStoreOf(app).titles, i18n: i18nOf(app) },
|
|
33
|
+
options,
|
|
34
|
+
),
|
|
35
|
+
)
|
|
36
|
+
useSchemaOrg(() => breadcrumbNodes(app, items(), options))
|
|
37
|
+
return items
|
|
38
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useApp, useHead, useRoute } from "@hamur/adapter-svelte"
|
|
2
|
+
import { onDestroy } from "svelte"
|
|
3
|
+
import { appOfCall, nodeList, schemaStoreOf } from "../runtime/schema-store.ts"
|
|
4
|
+
import {
|
|
5
|
+
breadcrumbItems,
|
|
6
|
+
breadcrumbNodes,
|
|
7
|
+
i18nOf,
|
|
8
|
+
routeOf,
|
|
9
|
+
type BreadcrumbItem,
|
|
10
|
+
type BreadcrumbOptions,
|
|
11
|
+
} from "../runtime/breadcrumbs.ts"
|
|
12
|
+
import type { SchemaNode } from "../schema.ts"
|
|
13
|
+
|
|
14
|
+
export type { BreadcrumbItem, BreadcrumbOptions, SchemaNode }
|
|
15
|
+
|
|
16
|
+
export function useSchemaOrg(nodes: SchemaNode | SchemaNode[] | (() => SchemaNode | SchemaNode[])): void {
|
|
17
|
+
const store = schemaStoreOf(appOfCall(useApp))
|
|
18
|
+
const key = {}
|
|
19
|
+
// useHead reads the getter again in an $effect and owns the apply.
|
|
20
|
+
useHead(() => {
|
|
21
|
+
store.set(key, nodeList(typeof nodes === "function" ? nodes() : nodes))
|
|
22
|
+
return {}
|
|
23
|
+
})
|
|
24
|
+
if (typeof document !== "undefined") onDestroy(() => store.remove(key))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function useBreadcrumbItems(options: BreadcrumbOptions = {}): BreadcrumbItem[] {
|
|
28
|
+
const app = appOfCall(useApp)
|
|
29
|
+
const route = useRoute()
|
|
30
|
+
const read = () =>
|
|
31
|
+
breadcrumbItems(
|
|
32
|
+
{ path: route.path, resolve: (to) => routeOf(app, to), titles: schemaStoreOf(app).titles, i18n: i18nOf(app) },
|
|
33
|
+
options,
|
|
34
|
+
)
|
|
35
|
+
useSchemaOrg(() => breadcrumbNodes(app, read(), options))
|
|
36
|
+
return read()
|
|
37
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useApp, useHead, useRoute } from "@hamur/adapter-vue"
|
|
2
|
+
import { computed, getCurrentScope, onScopeDispose, toValue, type ComputedRef, type MaybeRefOrGetter } from "vue"
|
|
3
|
+
import { appOfCall, nodeList, schemaStoreOf } from "../runtime/schema-store.ts"
|
|
4
|
+
import {
|
|
5
|
+
breadcrumbItems,
|
|
6
|
+
breadcrumbNodes,
|
|
7
|
+
i18nOf,
|
|
8
|
+
routeOf,
|
|
9
|
+
type BreadcrumbItem,
|
|
10
|
+
type BreadcrumbOptions,
|
|
11
|
+
} from "../runtime/breadcrumbs.ts"
|
|
12
|
+
import type { SchemaNode } from "../schema.ts"
|
|
13
|
+
|
|
14
|
+
export type { BreadcrumbItem, BreadcrumbOptions, SchemaNode }
|
|
15
|
+
|
|
16
|
+
type MaybeRefOrGetterDeep<T> = MaybeRefOrGetter<
|
|
17
|
+
T extends (...args: never[]) => unknown
|
|
18
|
+
? T
|
|
19
|
+
: T extends readonly (infer U)[]
|
|
20
|
+
? MaybeRefOrGetterDeep<U>[]
|
|
21
|
+
: T extends object
|
|
22
|
+
? { [K in keyof T]: MaybeRefOrGetterDeep<T[K]> }
|
|
23
|
+
: T
|
|
24
|
+
>
|
|
25
|
+
|
|
26
|
+
function resolve(value: unknown): unknown {
|
|
27
|
+
const read = toValue(value as MaybeRefOrGetter<unknown>)
|
|
28
|
+
if (Array.isArray(read)) return read.map(resolve)
|
|
29
|
+
if (typeof read !== "object" || read === null || read instanceof Date) return read
|
|
30
|
+
return Object.fromEntries(Object.entries(read).map(([name, item]) => [name, resolve(item)]))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function useSchemaOrg(nodes: MaybeRefOrGetterDeep<SchemaNode | SchemaNode[]>): void {
|
|
34
|
+
const store = schemaStoreOf(appOfCall(useApp))
|
|
35
|
+
const key = {}
|
|
36
|
+
// useHead re-reads the getter whenever a ref in it changes and owns the watch and the apply.
|
|
37
|
+
useHead(() => {
|
|
38
|
+
store.set(key, nodeList(resolve(nodes) as SchemaNode | SchemaNode[]))
|
|
39
|
+
return {}
|
|
40
|
+
})
|
|
41
|
+
if (typeof document !== "undefined" && getCurrentScope()) onScopeDispose(() => store.remove(key))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function useBreadcrumbItems(options: BreadcrumbOptions = {}): ComputedRef<BreadcrumbItem[]> {
|
|
45
|
+
const app = appOfCall(useApp)
|
|
46
|
+
const route = useRoute()
|
|
47
|
+
const items = computed(() =>
|
|
48
|
+
breadcrumbItems(
|
|
49
|
+
{ path: route.path, resolve: (to) => routeOf(app, to), titles: schemaStoreOf(app).titles, i18n: i18nOf(app) },
|
|
50
|
+
options,
|
|
51
|
+
),
|
|
52
|
+
)
|
|
53
|
+
useSchemaOrg((() => breadcrumbNodes(app, items.value, options)) as Parameters<typeof useSchemaOrg>[0])
|
|
54
|
+
return items
|
|
55
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HamurContext } from "hamur/kit"
|
|
2
|
+
import { createLinkChecker } from "../links/check.ts"
|
|
3
|
+
import { resolveLinkChecker } from "../links/options.ts"
|
|
4
|
+
import type { SeoConfig } from "../types.ts"
|
|
5
|
+
|
|
6
|
+
/** The link rules over every page the prerender writes, reported in `prerender:done`. */
|
|
7
|
+
export function setupLinkChecker(value: SeoConfig["linkChecker"], hamur: HamurContext): void {
|
|
8
|
+
const options = resolveLinkChecker(value)
|
|
9
|
+
if (!options) return
|
|
10
|
+
const checker = createLinkChecker(hamur, options)
|
|
11
|
+
hamur.hooks.hook("prerender:page", checker.page)
|
|
12
|
+
hamur.hooks.hook("prerender:done", checker.done)
|
|
13
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { existsSync } from "node:fs"
|
|
2
|
+
import { join } from "node:path"
|
|
3
|
+
import { addTemplate, createRouteRules, type HamurContext } from "hamur/kit"
|
|
4
|
+
import { absoluteUrl } from "hamur/server/internal"
|
|
5
|
+
import { htmlToMarkdown } from "../runtime/markdown.ts"
|
|
6
|
+
import { checkOwner, resolveLlms, type ResolvedLlms } from "../llms/options.ts"
|
|
7
|
+
import { markdownPath } from "../llms/paths.ts"
|
|
8
|
+
import { yieldToApp } from "./own.ts"
|
|
9
|
+
|
|
10
|
+
const PATH = "/llms.txt"
|
|
11
|
+
const FULL = "/llms-full.txt"
|
|
12
|
+
|
|
13
|
+
/** `seo.llms` as it resolved, `undefined` while it is off; fails when `content.llms` serves the same files. */
|
|
14
|
+
export function readLlms(input: unknown, hamur: HamurContext): ResolvedLlms | undefined {
|
|
15
|
+
const llms = resolveLlms(input)
|
|
16
|
+
if (llms) checkOwner((hamur.options as unknown as { content?: { llms?: unknown } }).content?.llms)
|
|
17
|
+
return llms
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** `/llms.txt`, `/llms-full.txt` and the agent Markdown of every page; the app's `public/llms.txt` or own route wins. */
|
|
21
|
+
export function setupLlms(llms: ResolvedLlms | undefined, hamur: HamurContext): void {
|
|
22
|
+
const { baseURL, trailingSlash, rootId } = hamur.options.app
|
|
23
|
+
const own = yieldToApp(hamur, PATH, llms !== undefined, [FULL])
|
|
24
|
+
if (!llms) {
|
|
25
|
+
addTemplate({
|
|
26
|
+
filename: "seo/llms",
|
|
27
|
+
getContents: () =>
|
|
28
|
+
'export const enabled = false;\nexport const title = null;\nexport const description = null;\nexport const exclude = [];\nexport const baseURL = "/";\nexport const trailingSlash = "ignore";\nexport const rootId = "";\n',
|
|
29
|
+
})
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
addTemplate({
|
|
33
|
+
filename: "seo/llms",
|
|
34
|
+
getContents: () =>
|
|
35
|
+
`${Object.entries({
|
|
36
|
+
enabled: true,
|
|
37
|
+
title: llms.title ?? null,
|
|
38
|
+
description: llms.description ?? null,
|
|
39
|
+
exclude: llms.exclude,
|
|
40
|
+
baseURL,
|
|
41
|
+
trailingSlash,
|
|
42
|
+
rootId,
|
|
43
|
+
})
|
|
44
|
+
.map(([name, value]) => `export const ${name} = ${JSON.stringify(value)};\n`)
|
|
45
|
+
.join("")}`,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const excluded = llms.exclude.length
|
|
49
|
+
? createRouteRules(Object.fromEntries(llms.exclude.map((pattern) => [pattern, {}])))
|
|
50
|
+
: undefined
|
|
51
|
+
hamur.hooks.hook("prerender:routes", (routes) => {
|
|
52
|
+
if (hamur.options.preset !== "static" || !own.served()) return
|
|
53
|
+
routes.add(PATH)
|
|
54
|
+
routes.add(FULL)
|
|
55
|
+
})
|
|
56
|
+
const converted = new Map<string, string>()
|
|
57
|
+
hamur.hooks.hook("prerender:page", (page) => {
|
|
58
|
+
if (
|
|
59
|
+
page.status !== 200 ||
|
|
60
|
+
typeof page.body !== "string" ||
|
|
61
|
+
!(page.headers.get("content-type") ?? "").toLowerCase().startsWith("text/html")
|
|
62
|
+
)
|
|
63
|
+
return
|
|
64
|
+
if (excluded?.match(page.path).matches.length) return
|
|
65
|
+
const origin = hamur.options.site.url ?? process.env.HAMUR_SITE_URL ?? "http://localhost"
|
|
66
|
+
const text = htmlToMarkdown(page.body, { base: absoluteUrl(origin, baseURL, page.path), rootId })
|
|
67
|
+
if (text !== "") converted.set(markdownPath(page.path), text)
|
|
68
|
+
})
|
|
69
|
+
hamur.hooks.hook("prerender:done", async () => {
|
|
70
|
+
const publicDirs = [hamur.options.publicDir, ...hamur.options.layers.map((layer) => layer.publicDir)]
|
|
71
|
+
const out = join(hamur.options.outputDir, "public")
|
|
72
|
+
for (const [path, text] of converted) {
|
|
73
|
+
const name = path.slice(1)
|
|
74
|
+
if ([out, ...publicDirs].some((dir) => existsSync(join(dir, name)))) continue
|
|
75
|
+
await Bun.write(join(out, name), text)
|
|
76
|
+
}
|
|
77
|
+
converted.clear()
|
|
78
|
+
})
|
|
79
|
+
}
|
package/src/build/own.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { existsSync } from "node:fs"
|
|
2
|
+
import { join, relative } from "node:path"
|
|
3
|
+
import { useLogger, type HamurContext } from "hamur/kit"
|
|
4
|
+
|
|
5
|
+
/** With `enabled` false the module's record is dropped without a word; otherwise the app's `public/<file>` or its own `GET` handler of `path` wins; the module then drops its record in `server:extend` and logs once. `served()` tells whether the module's route stands. `companions` are the module's other routes that stand and fall with it. */
|
|
6
|
+
export function yieldToApp(
|
|
7
|
+
hamur: HamurContext,
|
|
8
|
+
path: string,
|
|
9
|
+
enabled: boolean,
|
|
10
|
+
companions: string[] = [],
|
|
11
|
+
): { served(): boolean } {
|
|
12
|
+
const log = useLogger("seo")
|
|
13
|
+
const file = path.slice(1)
|
|
14
|
+
const { rootDir, layers } = hamur.options
|
|
15
|
+
const serverDirs = [hamur.options.serverDir, ...layers.map((layer) => layer.serverDir)]
|
|
16
|
+
const publicDirs = [hamur.options.publicDir, ...layers.map((layer) => layer.publicDir)]
|
|
17
|
+
const answers = (record: { path: string; method?: string }) =>
|
|
18
|
+
record.path === path && (record.method === undefined || record.method === "GET")
|
|
19
|
+
const ours = (record: { path: string; method?: string }) =>
|
|
20
|
+
answers(record) || (companions.includes(record.path) && (record.method === undefined || record.method === "GET"))
|
|
21
|
+
const said = new Set<string>()
|
|
22
|
+
let served = true
|
|
23
|
+
hamur.hooks.hook("server:extend", (records) => {
|
|
24
|
+
const dir = publicDirs.find((publicDir) => existsSync(join(publicDir, file)))
|
|
25
|
+
const own = records.find(
|
|
26
|
+
(record) => answers(record) && serverDirs.some((serverDir) => record.file.startsWith(`${serverDir}/`)),
|
|
27
|
+
)
|
|
28
|
+
const reason = dir
|
|
29
|
+
? `${relative(rootDir, join(dir, file))} exists; @hamur/seo serves no ${path}`
|
|
30
|
+
: own
|
|
31
|
+
? `${relative(rootDir, own.file)}#${own.fn.export} answers ${path}; @hamur/seo serves none`
|
|
32
|
+
: undefined
|
|
33
|
+
served = enabled && reason === undefined
|
|
34
|
+
if (served) return
|
|
35
|
+
if (reason !== undefined && enabled && !said.has(reason)) {
|
|
36
|
+
said.add(reason)
|
|
37
|
+
log.info(reason)
|
|
38
|
+
}
|
|
39
|
+
for (let index = records.length - 1; index >= 0; index--) {
|
|
40
|
+
const record = records[index]!
|
|
41
|
+
if (ours(record) && !serverDirs.some((serverDir) => record.file.startsWith(`${serverDir}/`)))
|
|
42
|
+
records.splice(index, 1)
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
return { served: () => served }
|
|
46
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { addRouteRules, addTemplate, diagnostic, useLogger, type HamurContext } from "hamur/kit"
|
|
2
|
+
import { yieldToApp } from "./own.ts"
|
|
3
|
+
import { robotsBody } from "../robots/body.ts"
|
|
4
|
+
import { resolveRobots } from "../robots/options.ts"
|
|
5
|
+
|
|
6
|
+
const PATH = "/robots.txt"
|
|
7
|
+
|
|
8
|
+
type I18nInput = { locales?: unknown; defaultLocale?: unknown; strategy?: unknown }
|
|
9
|
+
|
|
10
|
+
/** The codes whose pages `@hamur/i18n` copies under `/<code>`. */
|
|
11
|
+
function localePrefixes(hamur: HamurContext): string[] {
|
|
12
|
+
const i18n = (hamur.options as unknown as { i18n?: I18nInput }).i18n
|
|
13
|
+
if (!i18n || !Array.isArray(i18n.locales)) return []
|
|
14
|
+
const codes = i18n.locales
|
|
15
|
+
.map((locale: unknown) => (typeof locale === "string" ? locale : (locale as { code?: unknown } | null)?.code))
|
|
16
|
+
.filter((code): code is string => typeof code === "string")
|
|
17
|
+
return i18n.strategy === "prefix" ? codes : codes.filter((code) => code !== i18n.defaultLocale)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** `/robots.txt` from `seo.robots`; the app's own `public/robots.txt` or route wins. */
|
|
21
|
+
export function setupRobots(input: unknown, hamur: HamurContext, sitemap: boolean): void {
|
|
22
|
+
const robots = resolveRobots(input)
|
|
23
|
+
const own = yieldToApp(hamur, PATH, robots !== undefined)
|
|
24
|
+
if (!robots) {
|
|
25
|
+
addTemplate({
|
|
26
|
+
filename: "seo/robots",
|
|
27
|
+
getContents: () => 'export const body = "";\nexport const sitemap = null;\n',
|
|
28
|
+
})
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
const log = useLogger("seo")
|
|
32
|
+
const { baseURL } = hamur.options.app
|
|
33
|
+
if (baseURL !== "/")
|
|
34
|
+
log.warn(
|
|
35
|
+
diagnostic(
|
|
36
|
+
"HAMUR_W6409",
|
|
37
|
+
`app.baseURL is "${baseURL}": crawlers read robots.txt only at the origin's root, so ${baseURL}robots.txt is not read`,
|
|
38
|
+
),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
addTemplate({
|
|
42
|
+
filename: "seo/robots",
|
|
43
|
+
getContents: (ctx) => {
|
|
44
|
+
const noindex = Object.entries(ctx.routeRules).flatMap(([pattern, rule]) =>
|
|
45
|
+
!Array.isArray(rule) && !/\s/.test(pattern) && rule.noindex === true ? [pattern] : [],
|
|
46
|
+
)
|
|
47
|
+
const body = robotsBody({ robots, noindex, baseURL, prefixes: localePrefixes(ctx) })
|
|
48
|
+
return `export const body = ${JSON.stringify(body)};\nexport const sitemap = ${JSON.stringify(sitemap ? `${baseURL}sitemap.xml` : null)};\n`
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
addRouteRules({ [PATH]: { swr: 600 } })
|
|
52
|
+
|
|
53
|
+
if (hamur.options.preset === "static") {
|
|
54
|
+
hamur.hooks.hook("prerender:routes", (routes) => {
|
|
55
|
+
if (own.served()) routes.add(PATH)
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { addAppPlugin, addTemplate, createResolver, type HamurContext, type RouteRecord } from "hamur/kit"
|
|
2
|
+
import { resolveSchemaOrg } from "../schema/options.ts"
|
|
3
|
+
import type { SeoConfig } from "../types.ts"
|
|
4
|
+
|
|
5
|
+
const titlesOf = (routes: RouteRecord[]): Record<string, string> =>
|
|
6
|
+
Object.fromEntries(
|
|
7
|
+
routes.flatMap((route) => [
|
|
8
|
+
...(route.title === undefined ? [] : [[route.name, route.title]]),
|
|
9
|
+
...Object.entries(titlesOf(route.children)),
|
|
10
|
+
]),
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
/** The `#hamur/seo/schema-org` template and the app plugin that writes the page's graph on both sides. */
|
|
14
|
+
export function setupSchemaOrg(value: SeoConfig["schemaOrg"], hamur: HamurContext): void {
|
|
15
|
+
const { enabled, identity } = resolveSchemaOrg(value)
|
|
16
|
+
const { baseURL, trailingSlash } = hamur.options.app
|
|
17
|
+
addTemplate({
|
|
18
|
+
filename: "seo/schema-org",
|
|
19
|
+
getContents: (ctx) =>
|
|
20
|
+
`export default ${JSON.stringify({ enabled, identity: identity ?? null, baseURL, trailingSlash, titles: titlesOf(ctx.routes) })};\n`,
|
|
21
|
+
})
|
|
22
|
+
addAppPlugin({ src: createResolver(import.meta.url).resolve("../runtime/schema-plugin.ts"), mode: "all" })
|
|
23
|
+
}
|