@hamur/seo 0.0.0-stage → 0.0.2
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 +136 -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/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 productdevbook
|
|
4
|
+
Copyright (c) 2019 Material-UI SAS
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @hamur/seo
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The first-party SEO module for [Hamur](https://github.com/productdevbook/hamur), a full-stack web framework for Bun. It serves `/robots.txt` from the `seo.robots` config and the route rules marked `noindex`, `/sitemap.xml` from the route table and the prerender list, and answers `Disallow: /` on any deploy whose `site.indexable` is false. It has no dependency.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
bun add @hamur/seo
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Add it to `modules` in `hamur.config.ts` and set the `seo` key:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { defineConfig } from "hamur"
|
|
15
|
+
import seo from "@hamur/seo"
|
|
16
|
+
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
modules: [seo],
|
|
19
|
+
site: { url: "https://example.com" },
|
|
20
|
+
seo: { robots: { groups: [{ userAgent: "*", disallow: ["/drafts/"] }], blockAiBots: true } },
|
|
21
|
+
routeRules: { "/admin/**": { noindex: true } },
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Docs
|
|
26
|
+
|
|
27
|
+
[Documentation](https://docs.productdevbook.com/) and the [API reference](https://docs.productdevbook.com/api-reference/seo). MIT license.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/seo/src/schema/helpers.ts
|
|
3
|
+
var withType = (type, value) => {
|
|
4
|
+
if (Array.isArray(value))
|
|
5
|
+
return value.map((item) => withType(type, item));
|
|
6
|
+
if (typeof value !== "object" || value === null || value instanceof Date || "@type" in value)
|
|
7
|
+
return value;
|
|
8
|
+
return { "@type": type, ...value };
|
|
9
|
+
};
|
|
10
|
+
var define = (type, input, nested = {}) => {
|
|
11
|
+
const node = { "@type": type, ...input };
|
|
12
|
+
for (const [key, nestedType] of Object.entries(nested))
|
|
13
|
+
if (key in node)
|
|
14
|
+
node[key] = withType(nestedType, node[key]);
|
|
15
|
+
return node;
|
|
16
|
+
};
|
|
17
|
+
var nestedTypes = {
|
|
18
|
+
reviewRating: "Rating",
|
|
19
|
+
aggregateRating: "AggregateRating",
|
|
20
|
+
review: "Review",
|
|
21
|
+
offers: "Offer",
|
|
22
|
+
address: "PostalAddress",
|
|
23
|
+
contactPoint: "ContactPoint"
|
|
24
|
+
};
|
|
25
|
+
var defineWebSite2 = (input = {}) => define("WebSite", input);
|
|
26
|
+
var defineWebPage2 = (input = {}) => define("WebPage", input);
|
|
27
|
+
var defineOrganization2 = (input) => define("Organization", input, nestedTypes);
|
|
28
|
+
var definePerson2 = (input) => define("Person", input, nestedTypes);
|
|
29
|
+
var defineLocalBusiness2 = (input) => define("LocalBusiness", input, nestedTypes);
|
|
30
|
+
var defineArticle2 = (input) => define("Article", input);
|
|
31
|
+
var defineBlogPosting2 = (input) => define("BlogPosting", input);
|
|
32
|
+
var defineProduct2 = (input) => define("Product", input, nestedTypes);
|
|
33
|
+
var defineOffer2 = (input) => define("Offer", input);
|
|
34
|
+
var defineAggregateRating2 = (input) => define("AggregateRating", input);
|
|
35
|
+
var defineReview2 = (input) => define("Review", input, nestedTypes);
|
|
36
|
+
var defineQuestion2 = (input) => define("Question", input, { acceptedAnswer: "Answer" });
|
|
37
|
+
var questions = (value) => {
|
|
38
|
+
if (Array.isArray(value))
|
|
39
|
+
return value.map(questions);
|
|
40
|
+
if (typeof value !== "object" || value === null || "@type" in value || !("acceptedAnswer" in value))
|
|
41
|
+
return value;
|
|
42
|
+
return defineQuestion2(value);
|
|
43
|
+
};
|
|
44
|
+
var defineFaqPage2 = (input) => define("FAQPage", { ...input, mainEntity: questions(input.mainEntity) }, { mainEntity: "Question" });
|
|
45
|
+
var defineHowTo2 = (input) => define("HowTo", input, { step: "HowToStep" });
|
|
46
|
+
var defineEvent2 = (input) => define("Event", input, { offers: "Offer", location: "Place" });
|
|
47
|
+
var defineRecipe2 = (input) => define("Recipe", input, nestedTypes);
|
|
48
|
+
var defineVideoObject2 = (input) => define("VideoObject", input);
|
|
49
|
+
var defineImageObject2 = (input) => define("ImageObject", input);
|
|
50
|
+
var defineSoftwareApp2 = (input) => define("SoftwareApplication", input, nestedTypes);
|
|
51
|
+
var defineBook2 = (input) => define("Book", input, nestedTypes);
|
|
52
|
+
var defineCourse2 = (input) => define("Course", input, { offers: "Offer" });
|
|
53
|
+
var defineJobPosting2 = (input) => define("JobPosting", input);
|
|
54
|
+
var defineBreadcrumbList2 = (input) => {
|
|
55
|
+
const items = input.itemListElement.map((item, index) => {
|
|
56
|
+
const entry = item;
|
|
57
|
+
return "@type" in entry || !(("name" in entry) || ("item" in entry) || ("position" in entry)) ? item : { "@type": "ListItem", position: index + 1, ...entry };
|
|
58
|
+
});
|
|
59
|
+
return { "@type": "BreadcrumbList", ...input, itemListElement: items };
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { defineWebSite2, defineWebPage2, defineOrganization2, definePerson2, defineLocalBusiness2, defineArticle2, defineBlogPosting2, defineProduct2, defineOffer2, defineAggregateRating2, defineReview2, defineQuestion2, defineFaqPage2, defineHowTo2, defineEvent2, defineRecipe2, defineVideoObject2, defineImageObject2, defineSoftwareApp2, defineBook2, defineCourse2, defineJobPosting2, defineBreadcrumbList2 };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
defineBreadcrumbList2
|
|
4
|
+
} from "./bun-index-rnjhv41c.js";
|
|
5
|
+
|
|
6
|
+
// packages/seo/src/runtime/schema-store.ts
|
|
7
|
+
import { siteConfigOf, canonicalURL } from "hamur/adapter";
|
|
8
|
+
|
|
9
|
+
// packages/seo/src/schema/graph.ts
|
|
10
|
+
var URL_KEYS = new Set(["url", "image", "logo", "item", "contentUrl", "thumbnailUrl", "embedUrl", "sameAs"]);
|
|
11
|
+
var WEB_PAGES = new Set([
|
|
12
|
+
"WebPage",
|
|
13
|
+
"AboutPage",
|
|
14
|
+
"CheckoutPage",
|
|
15
|
+
"CollectionPage",
|
|
16
|
+
"ContactPage",
|
|
17
|
+
"FAQPage",
|
|
18
|
+
"ItemPage",
|
|
19
|
+
"MedicalWebPage",
|
|
20
|
+
"ProfilePage",
|
|
21
|
+
"QAPage",
|
|
22
|
+
"RealEstateListing",
|
|
23
|
+
"SearchResultsPage"
|
|
24
|
+
]);
|
|
25
|
+
var ARTICLES = new Set(["Article", "BlogPosting", "NewsArticle", "TechArticle", "Report", "ScholarlyArticle"]);
|
|
26
|
+
|
|
27
|
+
// packages/seo/src/runtime/schema-store.ts
|
|
28
|
+
var warned = new Set;
|
|
29
|
+
var stores = new WeakMap;
|
|
30
|
+
function schemaStoreOf(app) {
|
|
31
|
+
const store = stores.get(app);
|
|
32
|
+
if (!store)
|
|
33
|
+
throw new Error('useSchemaOrg() needs the "@hamur/seo" module in modules');
|
|
34
|
+
return store;
|
|
35
|
+
}
|
|
36
|
+
var nodeList = (nodes) => Array.isArray(nodes) ? nodes : [nodes];
|
|
37
|
+
function appOfCall(useApp) {
|
|
38
|
+
try {
|
|
39
|
+
return useApp();
|
|
40
|
+
} catch {
|
|
41
|
+
throw new Error("useSchemaOrg() must be called inside a Hamur app");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// packages/seo/src/runtime/breadcrumbs.ts
|
|
46
|
+
import { matchRoute } from "hamur/app";
|
|
47
|
+
var SEPARATOR = "___";
|
|
48
|
+
var fromSegment = (segment) => {
|
|
49
|
+
let text = segment;
|
|
50
|
+
try {
|
|
51
|
+
text = decodeURIComponent(segment);
|
|
52
|
+
} catch {}
|
|
53
|
+
text = text.replaceAll("-", " ");
|
|
54
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
55
|
+
};
|
|
56
|
+
function breadcrumbItems(env, options = {}) {
|
|
57
|
+
const code = env.i18n?.localeOf(env.path).code;
|
|
58
|
+
const segments = env.path.split("/").filter(Boolean);
|
|
59
|
+
if (segments[0] === code)
|
|
60
|
+
segments.shift();
|
|
61
|
+
const items = [];
|
|
62
|
+
for (let count = 0;count <= segments.length; count++) {
|
|
63
|
+
const prefix = `/${segments.slice(0, count).join("/")}`;
|
|
64
|
+
const path = env.i18n && code ? env.i18n.localePath(prefix, code) : prefix;
|
|
65
|
+
const name = env.resolve(path).name;
|
|
66
|
+
const title = name === undefined ? undefined : env.titles[name] ?? env.titles[name.split(SEPARATOR)[0]];
|
|
67
|
+
const label = title ?? (count === 0 ? "Home" : fromSegment(segments[count - 1]));
|
|
68
|
+
items.push({ label, to: name === undefined ? undefined : path, current: count === segments.length });
|
|
69
|
+
}
|
|
70
|
+
const shown = options.hideRoot ? items.slice(1) : items;
|
|
71
|
+
return shown.flatMap((item, index) => {
|
|
72
|
+
const override = options.overrides?.[index];
|
|
73
|
+
if (override === false)
|
|
74
|
+
return [];
|
|
75
|
+
return [override ? { ...item, ...override } : item];
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function breadcrumbNodes(app, items, options) {
|
|
79
|
+
if (options.schemaOrg === false)
|
|
80
|
+
return [];
|
|
81
|
+
const store = schemaStoreOf(app);
|
|
82
|
+
return [
|
|
83
|
+
defineBreadcrumbList2({
|
|
84
|
+
itemListElement: items.map(({ label, to }) => {
|
|
85
|
+
const item = to === undefined ? undefined : store.urlOf(to);
|
|
86
|
+
return { name: label, ...item === undefined ? {} : { item } };
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
var i18nOf = (app) => app.i18n;
|
|
92
|
+
function routeOf(app, path) {
|
|
93
|
+
const name = matchRoute(`${schemaStoreOf(app).base}${path}`)?.name;
|
|
94
|
+
return name === undefined ? {} : { name };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { schemaStoreOf, nodeList, appOfCall, breadcrumbItems, breadcrumbNodes, i18nOf, routeOf };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
schemaStoreOf,
|
|
4
|
+
nodeList,
|
|
5
|
+
appOfCall,
|
|
6
|
+
breadcrumbItems,
|
|
7
|
+
breadcrumbNodes,
|
|
8
|
+
i18nOf,
|
|
9
|
+
routeOf
|
|
10
|
+
} from "../../chunks/bun-index-xf4srhvn.js";
|
|
11
|
+
|
|
12
|
+
// packages/seo/src/adapters/html.ts
|
|
13
|
+
import { useApp, useId, useRoute } from "@hamur/adapter-html";
|
|
14
|
+
var hooked = new WeakSet;
|
|
15
|
+
var last = new WeakMap;
|
|
16
|
+
function useSchemaOrg(nodes) {
|
|
17
|
+
const app = appOfCall(useApp);
|
|
18
|
+
const store = schemaStoreOf(app);
|
|
19
|
+
if (!hooked.has(app)) {
|
|
20
|
+
hooked.add(app);
|
|
21
|
+
app.hooks.hook("page:start", () => store.clear());
|
|
22
|
+
}
|
|
23
|
+
const id = useId();
|
|
24
|
+
const index = Number(id.slice(2));
|
|
25
|
+
if (index <= (last.get(app) ?? -1))
|
|
26
|
+
store.clear();
|
|
27
|
+
last.set(app, index);
|
|
28
|
+
store.set(id, nodeList(nodes));
|
|
29
|
+
}
|
|
30
|
+
function useBreadcrumbItems(options = {}) {
|
|
31
|
+
const app = appOfCall(useApp);
|
|
32
|
+
const path = useRoute().path;
|
|
33
|
+
const items = breadcrumbItems({ path, resolve: (to) => routeOf(app, to), titles: schemaStoreOf(app).titles, i18n: i18nOf(app) }, options);
|
|
34
|
+
useSchemaOrg(breadcrumbNodes(app, items, options));
|
|
35
|
+
return items;
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
useBreadcrumbItems,
|
|
39
|
+
useSchemaOrg
|
|
40
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
schemaStoreOf,
|
|
4
|
+
nodeList,
|
|
5
|
+
appOfCall,
|
|
6
|
+
breadcrumbItems,
|
|
7
|
+
breadcrumbNodes,
|
|
8
|
+
i18nOf,
|
|
9
|
+
routeOf
|
|
10
|
+
} from "../../chunks/bun-index-xf4srhvn.js";
|
|
11
|
+
|
|
12
|
+
// packages/seo/src/adapters/preact.ts
|
|
13
|
+
import { useApp, useRoute } from "@hamur/adapter-preact";
|
|
14
|
+
import { useLayoutEffect, useRef } from "preact/hooks";
|
|
15
|
+
var isServer = typeof window === "undefined";
|
|
16
|
+
function useSchemaOrg(nodes) {
|
|
17
|
+
const store = schemaStoreOf(appOfCall(useApp));
|
|
18
|
+
const key = useRef({}).current;
|
|
19
|
+
if (isServer)
|
|
20
|
+
store.set(key, nodeList(nodes));
|
|
21
|
+
useLayoutEffect(() => {
|
|
22
|
+
store.set(key, nodeList(nodes));
|
|
23
|
+
});
|
|
24
|
+
useLayoutEffect(() => () => store.remove(key), [store, key]);
|
|
25
|
+
}
|
|
26
|
+
function useBreadcrumbItems(options = {}) {
|
|
27
|
+
const app = appOfCall(useApp);
|
|
28
|
+
const path = useRoute().path;
|
|
29
|
+
const items = breadcrumbItems({ path, resolve: (to) => routeOf(app, to), titles: schemaStoreOf(app).titles, i18n: i18nOf(app) }, options);
|
|
30
|
+
useSchemaOrg(breadcrumbNodes(app, items, options));
|
|
31
|
+
return items;
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
useBreadcrumbItems,
|
|
35
|
+
useSchemaOrg
|
|
36
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
schemaStoreOf,
|
|
4
|
+
nodeList,
|
|
5
|
+
appOfCall,
|
|
6
|
+
breadcrumbItems,
|
|
7
|
+
breadcrumbNodes,
|
|
8
|
+
i18nOf,
|
|
9
|
+
routeOf
|
|
10
|
+
} from "../../chunks/bun-index-xf4srhvn.js";
|
|
11
|
+
|
|
12
|
+
// packages/seo/src/adapters/react.ts
|
|
13
|
+
import { useApp, useRoute } from "@hamur/adapter-react";
|
|
14
|
+
import { useId, useLayoutEffect } from "react";
|
|
15
|
+
var isServer = typeof window === "undefined";
|
|
16
|
+
function useSchemaOrg(nodes) {
|
|
17
|
+
const store = schemaStoreOf(appOfCall(useApp));
|
|
18
|
+
const key = useId();
|
|
19
|
+
if (isServer)
|
|
20
|
+
store.set(key, nodeList(nodes));
|
|
21
|
+
useLayoutEffect(() => {
|
|
22
|
+
store.set(key, nodeList(nodes));
|
|
23
|
+
});
|
|
24
|
+
useLayoutEffect(() => () => store.remove(key), [store, key]);
|
|
25
|
+
}
|
|
26
|
+
function useBreadcrumbItems(options = {}) {
|
|
27
|
+
const app = appOfCall(useApp);
|
|
28
|
+
const path = useRoute().path;
|
|
29
|
+
const items = breadcrumbItems({ path, resolve: (to) => routeOf(app, to), titles: schemaStoreOf(app).titles, i18n: i18nOf(app) }, options);
|
|
30
|
+
useSchemaOrg(breadcrumbNodes(app, items, options));
|
|
31
|
+
return items;
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
useBreadcrumbItems,
|
|
35
|
+
useSchemaOrg
|
|
36
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
schemaStoreOf,
|
|
4
|
+
nodeList,
|
|
5
|
+
appOfCall,
|
|
6
|
+
breadcrumbItems,
|
|
7
|
+
breadcrumbNodes,
|
|
8
|
+
i18nOf,
|
|
9
|
+
routeOf
|
|
10
|
+
} from "../../chunks/bun-index-xf4srhvn.js";
|
|
11
|
+
|
|
12
|
+
// packages/seo/src/adapters/solid.ts
|
|
13
|
+
import { useApp, useHead, useRoute } from "@hamur/adapter-solid";
|
|
14
|
+
import { createMemo, onCleanup } from "solid-js";
|
|
15
|
+
function useSchemaOrg(nodes) {
|
|
16
|
+
const store = schemaStoreOf(appOfCall(useApp));
|
|
17
|
+
const key = {};
|
|
18
|
+
useHead(() => {
|
|
19
|
+
store.set(key, nodeList(typeof nodes === "function" ? nodes() : nodes));
|
|
20
|
+
return {};
|
|
21
|
+
});
|
|
22
|
+
if (typeof document !== "undefined")
|
|
23
|
+
onCleanup(() => store.remove(key));
|
|
24
|
+
}
|
|
25
|
+
function useBreadcrumbItems(options = {}) {
|
|
26
|
+
const app = appOfCall(useApp);
|
|
27
|
+
const route = useRoute();
|
|
28
|
+
const items = createMemo(() => breadcrumbItems({ path: route().path, resolve: (to) => routeOf(app, to), titles: schemaStoreOf(app).titles, i18n: i18nOf(app) }, options));
|
|
29
|
+
useSchemaOrg(() => breadcrumbNodes(app, items(), options));
|
|
30
|
+
return items;
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
useBreadcrumbItems,
|
|
34
|
+
useSchemaOrg
|
|
35
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
schemaStoreOf,
|
|
4
|
+
nodeList,
|
|
5
|
+
appOfCall,
|
|
6
|
+
breadcrumbItems,
|
|
7
|
+
breadcrumbNodes,
|
|
8
|
+
i18nOf,
|
|
9
|
+
routeOf
|
|
10
|
+
} from "../../chunks/bun-index-xf4srhvn.js";
|
|
11
|
+
|
|
12
|
+
// packages/seo/src/adapters/svelte.ts
|
|
13
|
+
import { useApp, useHead, useRoute } from "@hamur/adapter-svelte";
|
|
14
|
+
import { onDestroy } from "svelte";
|
|
15
|
+
function useSchemaOrg(nodes) {
|
|
16
|
+
const store = schemaStoreOf(appOfCall(useApp));
|
|
17
|
+
const key = {};
|
|
18
|
+
useHead(() => {
|
|
19
|
+
store.set(key, nodeList(typeof nodes === "function" ? nodes() : nodes));
|
|
20
|
+
return {};
|
|
21
|
+
});
|
|
22
|
+
if (typeof document !== "undefined")
|
|
23
|
+
onDestroy(() => store.remove(key));
|
|
24
|
+
}
|
|
25
|
+
function useBreadcrumbItems(options = {}) {
|
|
26
|
+
const app = appOfCall(useApp);
|
|
27
|
+
const route = useRoute();
|
|
28
|
+
const read = () => breadcrumbItems({ path: route.path, resolve: (to) => routeOf(app, to), titles: schemaStoreOf(app).titles, i18n: i18nOf(app) }, options);
|
|
29
|
+
useSchemaOrg(() => breadcrumbNodes(app, read(), options));
|
|
30
|
+
return read();
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
useBreadcrumbItems,
|
|
34
|
+
useSchemaOrg
|
|
35
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
schemaStoreOf,
|
|
4
|
+
nodeList,
|
|
5
|
+
appOfCall,
|
|
6
|
+
breadcrumbItems,
|
|
7
|
+
breadcrumbNodes,
|
|
8
|
+
i18nOf,
|
|
9
|
+
routeOf
|
|
10
|
+
} from "../../chunks/bun-index-xf4srhvn.js";
|
|
11
|
+
|
|
12
|
+
// packages/seo/src/adapters/vue.ts
|
|
13
|
+
import { useApp, useHead, useRoute } from "@hamur/adapter-vue";
|
|
14
|
+
import { computed, getCurrentScope, onScopeDispose, toValue } from "vue";
|
|
15
|
+
function resolve(value) {
|
|
16
|
+
const read = toValue(value);
|
|
17
|
+
if (Array.isArray(read))
|
|
18
|
+
return read.map(resolve);
|
|
19
|
+
if (typeof read !== "object" || read === null || read instanceof Date)
|
|
20
|
+
return read;
|
|
21
|
+
return Object.fromEntries(Object.entries(read).map(([name, item]) => [name, resolve(item)]));
|
|
22
|
+
}
|
|
23
|
+
function useSchemaOrg(nodes) {
|
|
24
|
+
const store = schemaStoreOf(appOfCall(useApp));
|
|
25
|
+
const key = {};
|
|
26
|
+
useHead(() => {
|
|
27
|
+
store.set(key, nodeList(resolve(nodes)));
|
|
28
|
+
return {};
|
|
29
|
+
});
|
|
30
|
+
if (typeof document !== "undefined" && getCurrentScope())
|
|
31
|
+
onScopeDispose(() => store.remove(key));
|
|
32
|
+
}
|
|
33
|
+
function useBreadcrumbItems(options = {}) {
|
|
34
|
+
const app = appOfCall(useApp);
|
|
35
|
+
const route = useRoute();
|
|
36
|
+
const items = computed(() => breadcrumbItems({ path: route.path, resolve: (to) => routeOf(app, to), titles: schemaStoreOf(app).titles, i18n: i18nOf(app) }, options));
|
|
37
|
+
useSchemaOrg(() => breadcrumbNodes(app, items.value, options));
|
|
38
|
+
return items;
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
useBreadcrumbItems,
|
|
42
|
+
useSchemaOrg
|
|
43
|
+
};
|