brease-client 0.1.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/LICENSE +21 -0
- package/README.md +164 -0
- package/dist/astro.cjs +69 -0
- package/dist/astro.d.cts +7 -0
- package/dist/astro.d.ts +7 -0
- package/dist/astro.js +10 -0
- package/dist/chunk-L7GXI4GK.js +8 -0
- package/dist/chunk-PKBMQBKP.js +5 -0
- package/dist/chunk-SSDAREDA.js +60 -0
- package/dist/html.cjs +64 -0
- package/dist/html.d.cts +16 -0
- package/dist/html.d.ts +16 -0
- package/dist/html.js +2 -0
- package/dist/image.cjs +40 -0
- package/dist/image.d.cts +28 -0
- package/dist/image.d.ts +28 -0
- package/dist/image.js +36 -0
- package/dist/index.cjs +171 -0
- package/dist/index.d.cts +50 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +157 -0
- package/dist/next.cjs +108 -0
- package/dist/next.d.cts +47 -0
- package/dist/next.d.ts +47 -0
- package/dist/next.js +98 -0
- package/dist/types-V0ELFvwy.d.cts +113 -0
- package/dist/types-V0ELFvwy.d.ts +113 -0
- package/package.json +84 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Designatives
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# brease-client
|
|
2
|
+
|
|
3
|
+
Typed client for the Brease delivery API. Zero runtime dependencies, ESM + CJS, runs on Node 18+, edge runtimes, Deno, Bun and browsers.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pnpm add brease-client
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Set two environment variables (Brease writes them into your Vercel project at onboarding):
|
|
10
|
+
|
|
11
|
+
| Variable | Purpose |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| `BREASE_TOKEN` | Read-only delivery token (`brs_live_…`). It identifies the site. |
|
|
14
|
+
| `BREASE_API_URL` | Optional. Defaults to `https://api.brease.io`. Inside a Brease sandbox it points at the local content server. |
|
|
15
|
+
| `BREASE_REVALIDATE_SECRET` | ISR/SSR sites only: secret for the revalidate route. |
|
|
16
|
+
|
|
17
|
+
## API
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { createBrease } from 'brease-client'
|
|
21
|
+
|
|
22
|
+
const brease = createBrease({
|
|
23
|
+
token: process.env.BREASE_TOKEN, // default
|
|
24
|
+
apiUrl: process.env.BREASE_API_URL, // default, falls back to https://api.brease.io
|
|
25
|
+
commit: process.env.VERCEL_GIT_COMMIT_SHA, // default; false disables commit pinning
|
|
26
|
+
fetch // optional custom fetch, e.g. to add framework cache options
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
await brease.getSite() // name, locales, defaultLocale, localeStrategy, global SEO
|
|
30
|
+
await brease.getPage<Home>('', { locale: 'en' }) // Page<Home> | null ('' is the home page)
|
|
31
|
+
await brease.getPages({ locale: 'en' }) // [{ pageId, locale, slug, url, hidden }]
|
|
32
|
+
await brease.getNavigation('main', { locale: 'en' }) // { key, locale, items } | null
|
|
33
|
+
await brease.getRedirects() // [{ source, destination, status }]
|
|
34
|
+
await brease.resolve('/en/about') // { slug: 'about', locale: 'en' } | null
|
|
35
|
+
await brease.sitemap('https://example.com') // [{ url, alternates }]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
- `null` means 404. Every other failure throws a `BreaseError` with `status`, `code`, `requestId` and `details`.
|
|
39
|
+
- 429 and 5xx responses (and network errors) are retried twice with backoff; `Retry-After` is honoured.
|
|
40
|
+
- Commit pinning: the `x-brease-commit` header is sent from `VERCEL_GIT_COMMIT_SHA`, so every deployment reads the content release that was built and tested with its code.
|
|
41
|
+
- `sitemap()` has no `lastModified`: releases are immutable snapshots and do not track per-page edit times.
|
|
42
|
+
- `buildPath(settings, slug, locale)` and `resolvePath(settings, pathname)` are exported for routing code that already has the site settings.
|
|
43
|
+
|
|
44
|
+
## Next.js (App Router)
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
// lib/brease.ts
|
|
48
|
+
import { createBrease } from 'brease-client'
|
|
49
|
+
import { breaseFetch } from 'brease-client/next'
|
|
50
|
+
|
|
51
|
+
export const brease = createBrease({ fetch: breaseFetch() }) // tags requests with 'brease'
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
// app/[[...slug]]/page.tsx
|
|
56
|
+
import { notFound } from 'next/navigation'
|
|
57
|
+
import { toMetadata } from 'brease-client/next'
|
|
58
|
+
import { brease } from '@/lib/brease'
|
|
59
|
+
|
|
60
|
+
export const revalidate = 60
|
|
61
|
+
|
|
62
|
+
type Props = { params: Promise<{ slug?: string[] }> }
|
|
63
|
+
|
|
64
|
+
async function load(params: Props['params']) {
|
|
65
|
+
const { slug = [] } = await params
|
|
66
|
+
const target = await brease.resolve(`/${slug.join('/')}`)
|
|
67
|
+
return target ? brease.getPage<{ hero: { title: string } }>(target.slug, { locale: target.locale }) : null
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function generateStaticParams() {
|
|
71
|
+
const pages = await brease.getPages()
|
|
72
|
+
return pages.filter((p) => !p.hidden).map((p) => ({ slug: p.url.split('/').filter(Boolean) }))
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function generateMetadata({ params }: Props) {
|
|
76
|
+
const page = await load(params)
|
|
77
|
+
return page ? toMetadata(page.resolvedSeo) : {}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default async function Page({ params }: Props) {
|
|
81
|
+
const page = await load(params)
|
|
82
|
+
if (!page) notFound()
|
|
83
|
+
return <h1 data-brease="hero.title">{page.content.hero.title}</h1>
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
// app/api/revalidate/route.ts
|
|
89
|
+
import { revalidateHandler } from 'brease-client/next'
|
|
90
|
+
|
|
91
|
+
export const POST = revalidateHandler() // uses BREASE_REVALIDATE_SECRET
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
// next.config.ts: redirects managed in Brease
|
|
96
|
+
import { createBrease } from 'brease-client'
|
|
97
|
+
|
|
98
|
+
export default {
|
|
99
|
+
async redirects() {
|
|
100
|
+
const redirects = await createBrease().getRedirects()
|
|
101
|
+
return redirects.map((r) => ({ source: r.source, destination: r.destination, permanent: r.status === 301 || r.status === 308 }))
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Revalidation signature
|
|
107
|
+
|
|
108
|
+
After a content-only release goes live, Brease POSTs JSON `{ urls, tags?, releaseId, siteId }` to the site's revalidate URL with two headers:
|
|
109
|
+
|
|
110
|
+
- `x-brease-timestamp`: milliseconds since epoch
|
|
111
|
+
- `x-brease-signature`: hex HMAC-SHA256 of `` `${timestamp}.${rawBody}` `` keyed with the revalidate secret
|
|
112
|
+
|
|
113
|
+
Requests older than five minutes are rejected. The handler calls `revalidatePath` for each URL's pathname and `revalidateTag` for each tag, always including `brease`.
|
|
114
|
+
|
|
115
|
+
## Astro
|
|
116
|
+
|
|
117
|
+
```astro
|
|
118
|
+
---
|
|
119
|
+
import { createBrease } from 'brease-client'
|
|
120
|
+
import { breaseHead } from 'brease-client/astro'
|
|
121
|
+
|
|
122
|
+
const brease = createBrease({ token: import.meta.env.BREASE_TOKEN, apiUrl: import.meta.env.BREASE_API_URL })
|
|
123
|
+
const target = await brease.resolve(Astro.url.pathname)
|
|
124
|
+
const page = target && (await brease.getPage(target.slug, { locale: target.locale }))
|
|
125
|
+
if (!page) return Astro.redirect('/404')
|
|
126
|
+
---
|
|
127
|
+
<html lang={page.locale}>
|
|
128
|
+
<head><Fragment set:html={breaseHead(page.resolvedSeo)} /></head>
|
|
129
|
+
<body><h1 data-brease="hero.title">{page.content.hero.title}</h1></body>
|
|
130
|
+
</html>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`headTagList(seo)` returns the same tags as structured `{ tag, attrs, content }` objects.
|
|
134
|
+
|
|
135
|
+
## Plain HTML / other servers
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
import { headTags } from 'brease-client/html'
|
|
139
|
+
|
|
140
|
+
const html = `<head>${headTags(page.resolvedSeo, { xDefault: 'https://example.com/' })}</head>`
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
`customHead` and `customCode` from the site's SEO settings are inserted as raw HTML (they are authored by the site's team); pass `{ includeCustom: false }` to leave them out.
|
|
144
|
+
|
|
145
|
+
## Images
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
import { imageProps, srcset } from 'brease-client/image'
|
|
149
|
+
|
|
150
|
+
const props = imageProps(page.content.hero.image, { sizes: '(min-width: 768px) 50vw, 100vw' })
|
|
151
|
+
// <img src={props.src} srcSet={props.srcSet} sizes={props.sizes} />
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Supabase Storage URLs are rewritten to image transformation URLs; other URLs pass through unchanged (with an empty srcset).
|
|
155
|
+
|
|
156
|
+
## Without JavaScript
|
|
157
|
+
|
|
158
|
+
Every call is a plain REST request:
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
curl -H "Authorization: Bearer $BREASE_TOKEN" "https://api.brease.io/v1/page?slug=about&locale=en"
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Routes: `GET /v1/site`, `/v1/pages?locale=`, `/v1/page?slug=&locale=`, `/v1/navigations/:key?locale=`, `/v1/redirects`, `/v1/release`.
|
package/dist/astro.cjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/html.ts
|
|
4
|
+
function headTagList(seo, opts = {}) {
|
|
5
|
+
const tags = [{ tag: "title", attrs: {}, content: seo.title }];
|
|
6
|
+
const meta = (key, name, value) => {
|
|
7
|
+
if (value) tags.push({ tag: "meta", attrs: { [key]: name, content: value } });
|
|
8
|
+
};
|
|
9
|
+
meta("name", "description", seo.description);
|
|
10
|
+
if (seo.canonical) tags.push({ tag: "link", attrs: { rel: "canonical", href: seo.canonical } });
|
|
11
|
+
meta(
|
|
12
|
+
"name",
|
|
13
|
+
"robots",
|
|
14
|
+
`${seo.robots.index ? "index" : "noindex"}, ${seo.robots.follow ? "follow" : "nofollow"}`
|
|
15
|
+
);
|
|
16
|
+
for (const [lang, href] of Object.entries(seo.alternates)) {
|
|
17
|
+
tags.push({ tag: "link", attrs: { rel: "alternate", hreflang: lang, href } });
|
|
18
|
+
}
|
|
19
|
+
if (opts.xDefault) {
|
|
20
|
+
tags.push({ tag: "link", attrs: { rel: "alternate", hreflang: "x-default", href: opts.xDefault } });
|
|
21
|
+
}
|
|
22
|
+
const og = seo.openGraph;
|
|
23
|
+
meta("property", "og:type", og.type);
|
|
24
|
+
meta("property", "og:title", og.title);
|
|
25
|
+
meta("property", "og:description", og.description);
|
|
26
|
+
meta("property", "og:image", og.image);
|
|
27
|
+
meta("property", "og:url", og.url);
|
|
28
|
+
meta("property", "og:site_name", og.siteName);
|
|
29
|
+
const tw = seo.twitter;
|
|
30
|
+
meta("name", "twitter:card", tw.card);
|
|
31
|
+
meta("name", "twitter:site", tw.site);
|
|
32
|
+
meta("name", "twitter:creator", tw.creator);
|
|
33
|
+
meta("name", "twitter:title", tw.title);
|
|
34
|
+
meta("name", "twitter:description", tw.description);
|
|
35
|
+
meta("name", "twitter:image", tw.image);
|
|
36
|
+
if (seo.favicon) tags.push({ tag: "link", attrs: { rel: "icon", href: seo.favicon } });
|
|
37
|
+
for (const data of seo.structuredData) {
|
|
38
|
+
tags.push({
|
|
39
|
+
tag: "script",
|
|
40
|
+
attrs: { type: "application/ld+json" },
|
|
41
|
+
content: JSON.stringify(data).replace(/</g, "\\u003c")
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return tags;
|
|
45
|
+
}
|
|
46
|
+
var escapeHtml = (value) => value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
47
|
+
function renderTag(t) {
|
|
48
|
+
const attrs = Object.entries(t.attrs).map(([k, v]) => ` ${k}="${escapeHtml(v)}"`).join("");
|
|
49
|
+
if (t.tag === "meta" || t.tag === "link") return `<${t.tag}${attrs}>`;
|
|
50
|
+
const content = t.tag === "script" ? t.content ?? "" : escapeHtml(t.content ?? "");
|
|
51
|
+
return `<${t.tag}${attrs}>${content}</${t.tag}>`;
|
|
52
|
+
}
|
|
53
|
+
function headTags(seo, opts = {}) {
|
|
54
|
+
const parts = headTagList(seo, opts).map(renderTag);
|
|
55
|
+
if (opts.includeCustom !== false) {
|
|
56
|
+
if (seo.customHead) parts.push(seo.customHead);
|
|
57
|
+
if (seo.customCode) parts.push(seo.customCode);
|
|
58
|
+
}
|
|
59
|
+
return parts.join("\n");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/astro.ts
|
|
63
|
+
function breaseHead(seo, opts) {
|
|
64
|
+
return headTags(seo, opts);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
exports.breaseHead = breaseHead;
|
|
68
|
+
exports.headTagList = headTagList;
|
|
69
|
+
exports.headTags = headTags;
|
package/dist/astro.d.cts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HeadOptions } from './html.cjs';
|
|
2
|
+
export { HeadTag, headTagList, headTags } from './html.cjs';
|
|
3
|
+
import { R as ResolvedSeo } from './types-V0ELFvwy.cjs';
|
|
4
|
+
|
|
5
|
+
declare function breaseHead(seo: ResolvedSeo, opts?: HeadOptions): string;
|
|
6
|
+
|
|
7
|
+
export { HeadOptions, breaseHead };
|
package/dist/astro.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HeadOptions } from './html.js';
|
|
2
|
+
export { HeadTag, headTagList, headTags } from './html.js';
|
|
3
|
+
import { R as ResolvedSeo } from './types-V0ELFvwy.js';
|
|
4
|
+
|
|
5
|
+
declare function breaseHead(seo: ResolvedSeo, opts?: HeadOptions): string;
|
|
6
|
+
|
|
7
|
+
export { HeadOptions, breaseHead };
|
package/dist/astro.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
export { __publicField };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/html.ts
|
|
2
|
+
function headTagList(seo, opts = {}) {
|
|
3
|
+
const tags = [{ tag: "title", attrs: {}, content: seo.title }];
|
|
4
|
+
const meta = (key, name, value) => {
|
|
5
|
+
if (value) tags.push({ tag: "meta", attrs: { [key]: name, content: value } });
|
|
6
|
+
};
|
|
7
|
+
meta("name", "description", seo.description);
|
|
8
|
+
if (seo.canonical) tags.push({ tag: "link", attrs: { rel: "canonical", href: seo.canonical } });
|
|
9
|
+
meta(
|
|
10
|
+
"name",
|
|
11
|
+
"robots",
|
|
12
|
+
`${seo.robots.index ? "index" : "noindex"}, ${seo.robots.follow ? "follow" : "nofollow"}`
|
|
13
|
+
);
|
|
14
|
+
for (const [lang, href] of Object.entries(seo.alternates)) {
|
|
15
|
+
tags.push({ tag: "link", attrs: { rel: "alternate", hreflang: lang, href } });
|
|
16
|
+
}
|
|
17
|
+
if (opts.xDefault) {
|
|
18
|
+
tags.push({ tag: "link", attrs: { rel: "alternate", hreflang: "x-default", href: opts.xDefault } });
|
|
19
|
+
}
|
|
20
|
+
const og = seo.openGraph;
|
|
21
|
+
meta("property", "og:type", og.type);
|
|
22
|
+
meta("property", "og:title", og.title);
|
|
23
|
+
meta("property", "og:description", og.description);
|
|
24
|
+
meta("property", "og:image", og.image);
|
|
25
|
+
meta("property", "og:url", og.url);
|
|
26
|
+
meta("property", "og:site_name", og.siteName);
|
|
27
|
+
const tw = seo.twitter;
|
|
28
|
+
meta("name", "twitter:card", tw.card);
|
|
29
|
+
meta("name", "twitter:site", tw.site);
|
|
30
|
+
meta("name", "twitter:creator", tw.creator);
|
|
31
|
+
meta("name", "twitter:title", tw.title);
|
|
32
|
+
meta("name", "twitter:description", tw.description);
|
|
33
|
+
meta("name", "twitter:image", tw.image);
|
|
34
|
+
if (seo.favicon) tags.push({ tag: "link", attrs: { rel: "icon", href: seo.favicon } });
|
|
35
|
+
for (const data of seo.structuredData) {
|
|
36
|
+
tags.push({
|
|
37
|
+
tag: "script",
|
|
38
|
+
attrs: { type: "application/ld+json" },
|
|
39
|
+
content: JSON.stringify(data).replace(/</g, "\\u003c")
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return tags;
|
|
43
|
+
}
|
|
44
|
+
var escapeHtml = (value) => value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
45
|
+
function renderTag(t) {
|
|
46
|
+
const attrs = Object.entries(t.attrs).map(([k, v]) => ` ${k}="${escapeHtml(v)}"`).join("");
|
|
47
|
+
if (t.tag === "meta" || t.tag === "link") return `<${t.tag}${attrs}>`;
|
|
48
|
+
const content = t.tag === "script" ? t.content ?? "" : escapeHtml(t.content ?? "");
|
|
49
|
+
return `<${t.tag}${attrs}>${content}</${t.tag}>`;
|
|
50
|
+
}
|
|
51
|
+
function headTags(seo, opts = {}) {
|
|
52
|
+
const parts = headTagList(seo, opts).map(renderTag);
|
|
53
|
+
if (opts.includeCustom !== false) {
|
|
54
|
+
if (seo.customHead) parts.push(seo.customHead);
|
|
55
|
+
if (seo.customCode) parts.push(seo.customCode);
|
|
56
|
+
}
|
|
57
|
+
return parts.join("\n");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { headTagList, headTags, renderTag };
|
package/dist/html.cjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/html.ts
|
|
4
|
+
function headTagList(seo, opts = {}) {
|
|
5
|
+
const tags = [{ tag: "title", attrs: {}, content: seo.title }];
|
|
6
|
+
const meta = (key, name, value) => {
|
|
7
|
+
if (value) tags.push({ tag: "meta", attrs: { [key]: name, content: value } });
|
|
8
|
+
};
|
|
9
|
+
meta("name", "description", seo.description);
|
|
10
|
+
if (seo.canonical) tags.push({ tag: "link", attrs: { rel: "canonical", href: seo.canonical } });
|
|
11
|
+
meta(
|
|
12
|
+
"name",
|
|
13
|
+
"robots",
|
|
14
|
+
`${seo.robots.index ? "index" : "noindex"}, ${seo.robots.follow ? "follow" : "nofollow"}`
|
|
15
|
+
);
|
|
16
|
+
for (const [lang, href] of Object.entries(seo.alternates)) {
|
|
17
|
+
tags.push({ tag: "link", attrs: { rel: "alternate", hreflang: lang, href } });
|
|
18
|
+
}
|
|
19
|
+
if (opts.xDefault) {
|
|
20
|
+
tags.push({ tag: "link", attrs: { rel: "alternate", hreflang: "x-default", href: opts.xDefault } });
|
|
21
|
+
}
|
|
22
|
+
const og = seo.openGraph;
|
|
23
|
+
meta("property", "og:type", og.type);
|
|
24
|
+
meta("property", "og:title", og.title);
|
|
25
|
+
meta("property", "og:description", og.description);
|
|
26
|
+
meta("property", "og:image", og.image);
|
|
27
|
+
meta("property", "og:url", og.url);
|
|
28
|
+
meta("property", "og:site_name", og.siteName);
|
|
29
|
+
const tw = seo.twitter;
|
|
30
|
+
meta("name", "twitter:card", tw.card);
|
|
31
|
+
meta("name", "twitter:site", tw.site);
|
|
32
|
+
meta("name", "twitter:creator", tw.creator);
|
|
33
|
+
meta("name", "twitter:title", tw.title);
|
|
34
|
+
meta("name", "twitter:description", tw.description);
|
|
35
|
+
meta("name", "twitter:image", tw.image);
|
|
36
|
+
if (seo.favicon) tags.push({ tag: "link", attrs: { rel: "icon", href: seo.favicon } });
|
|
37
|
+
for (const data of seo.structuredData) {
|
|
38
|
+
tags.push({
|
|
39
|
+
tag: "script",
|
|
40
|
+
attrs: { type: "application/ld+json" },
|
|
41
|
+
content: JSON.stringify(data).replace(/</g, "\\u003c")
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return tags;
|
|
45
|
+
}
|
|
46
|
+
var escapeHtml = (value) => value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
47
|
+
function renderTag(t) {
|
|
48
|
+
const attrs = Object.entries(t.attrs).map(([k, v]) => ` ${k}="${escapeHtml(v)}"`).join("");
|
|
49
|
+
if (t.tag === "meta" || t.tag === "link") return `<${t.tag}${attrs}>`;
|
|
50
|
+
const content = t.tag === "script" ? t.content ?? "" : escapeHtml(t.content ?? "");
|
|
51
|
+
return `<${t.tag}${attrs}>${content}</${t.tag}>`;
|
|
52
|
+
}
|
|
53
|
+
function headTags(seo, opts = {}) {
|
|
54
|
+
const parts = headTagList(seo, opts).map(renderTag);
|
|
55
|
+
if (opts.includeCustom !== false) {
|
|
56
|
+
if (seo.customHead) parts.push(seo.customHead);
|
|
57
|
+
if (seo.customCode) parts.push(seo.customCode);
|
|
58
|
+
}
|
|
59
|
+
return parts.join("\n");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
exports.headTagList = headTagList;
|
|
63
|
+
exports.headTags = headTags;
|
|
64
|
+
exports.renderTag = renderTag;
|
package/dist/html.d.cts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { R as ResolvedSeo } from './types-V0ELFvwy.cjs';
|
|
2
|
+
|
|
3
|
+
type HeadOptions = {
|
|
4
|
+
xDefault?: string;
|
|
5
|
+
includeCustom?: boolean;
|
|
6
|
+
};
|
|
7
|
+
type HeadTag = {
|
|
8
|
+
tag: 'title' | 'meta' | 'link' | 'script';
|
|
9
|
+
attrs: Record<string, string>;
|
|
10
|
+
content?: string;
|
|
11
|
+
};
|
|
12
|
+
declare function headTagList(seo: ResolvedSeo, opts?: HeadOptions): HeadTag[];
|
|
13
|
+
declare function renderTag(t: HeadTag): string;
|
|
14
|
+
declare function headTags(seo: ResolvedSeo, opts?: HeadOptions): string;
|
|
15
|
+
|
|
16
|
+
export { type HeadOptions, type HeadTag, headTagList, headTags, renderTag };
|
package/dist/html.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { R as ResolvedSeo } from './types-V0ELFvwy.js';
|
|
2
|
+
|
|
3
|
+
type HeadOptions = {
|
|
4
|
+
xDefault?: string;
|
|
5
|
+
includeCustom?: boolean;
|
|
6
|
+
};
|
|
7
|
+
type HeadTag = {
|
|
8
|
+
tag: 'title' | 'meta' | 'link' | 'script';
|
|
9
|
+
attrs: Record<string, string>;
|
|
10
|
+
content?: string;
|
|
11
|
+
};
|
|
12
|
+
declare function headTagList(seo: ResolvedSeo, opts?: HeadOptions): HeadTag[];
|
|
13
|
+
declare function renderTag(t: HeadTag): string;
|
|
14
|
+
declare function headTags(seo: ResolvedSeo, opts?: HeadOptions): string;
|
|
15
|
+
|
|
16
|
+
export { type HeadOptions, type HeadTag, headTagList, headTags, renderTag };
|
package/dist/html.js
ADDED
package/dist/image.cjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/image.ts
|
|
4
|
+
var OBJECT_PATH = "/storage/v1/object/public/";
|
|
5
|
+
var RENDER_PATH = "/storage/v1/render/image/public/";
|
|
6
|
+
var DEFAULT_WIDTHS = [320, 640, 960, 1280, 1920];
|
|
7
|
+
function isSupabaseImage(src) {
|
|
8
|
+
return src.includes(OBJECT_PATH) || src.includes(RENDER_PATH);
|
|
9
|
+
}
|
|
10
|
+
function imageUrl(src, opts = {}) {
|
|
11
|
+
if (!isSupabaseImage(src)) return src;
|
|
12
|
+
let url;
|
|
13
|
+
try {
|
|
14
|
+
url = new URL(src.replace(OBJECT_PATH, RENDER_PATH));
|
|
15
|
+
} catch {
|
|
16
|
+
return src;
|
|
17
|
+
}
|
|
18
|
+
if (opts.width) url.searchParams.set("width", String(Math.round(opts.width)));
|
|
19
|
+
if (opts.height) url.searchParams.set("height", String(Math.round(opts.height)));
|
|
20
|
+
if (opts.quality) url.searchParams.set("quality", String(opts.quality));
|
|
21
|
+
if (opts.resize) url.searchParams.set("resize", opts.resize);
|
|
22
|
+
return url.toString();
|
|
23
|
+
}
|
|
24
|
+
function srcset(src, opts = {}) {
|
|
25
|
+
if (!isSupabaseImage(src)) return "";
|
|
26
|
+
return (opts.widths ?? DEFAULT_WIDTHS).map((w) => `${imageUrl(src, { width: w, quality: opts.quality, resize: opts.resize })} ${w}w`).join(", ");
|
|
27
|
+
}
|
|
28
|
+
function imageProps(src, opts = {}) {
|
|
29
|
+
return {
|
|
30
|
+
src: imageUrl(src, { width: opts.width, height: opts.height, quality: opts.quality }),
|
|
31
|
+
srcSet: srcset(src, { widths: opts.widths, quality: opts.quality }),
|
|
32
|
+
sizes: opts.sizes ?? "100vw"
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
exports.DEFAULT_WIDTHS = DEFAULT_WIDTHS;
|
|
37
|
+
exports.imageProps = imageProps;
|
|
38
|
+
exports.imageUrl = imageUrl;
|
|
39
|
+
exports.isSupabaseImage = isSupabaseImage;
|
|
40
|
+
exports.srcset = srcset;
|
package/dist/image.d.cts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
type Resize = 'cover' | 'contain' | 'fill';
|
|
2
|
+
type ImageOptions = {
|
|
3
|
+
width?: number;
|
|
4
|
+
height?: number;
|
|
5
|
+
quality?: number;
|
|
6
|
+
resize?: Resize;
|
|
7
|
+
};
|
|
8
|
+
declare const DEFAULT_WIDTHS: number[];
|
|
9
|
+
declare function isSupabaseImage(src: string): boolean;
|
|
10
|
+
declare function imageUrl(src: string, opts?: ImageOptions): string;
|
|
11
|
+
declare function srcset(src: string, opts?: {
|
|
12
|
+
widths?: number[];
|
|
13
|
+
quality?: number;
|
|
14
|
+
resize?: Resize;
|
|
15
|
+
}): string;
|
|
16
|
+
declare function imageProps(src: string, opts?: {
|
|
17
|
+
sizes?: string;
|
|
18
|
+
widths?: number[];
|
|
19
|
+
width?: number;
|
|
20
|
+
height?: number;
|
|
21
|
+
quality?: number;
|
|
22
|
+
}): {
|
|
23
|
+
src: string;
|
|
24
|
+
srcSet: string;
|
|
25
|
+
sizes: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { DEFAULT_WIDTHS, type ImageOptions, type Resize, imageProps, imageUrl, isSupabaseImage, srcset };
|
package/dist/image.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
type Resize = 'cover' | 'contain' | 'fill';
|
|
2
|
+
type ImageOptions = {
|
|
3
|
+
width?: number;
|
|
4
|
+
height?: number;
|
|
5
|
+
quality?: number;
|
|
6
|
+
resize?: Resize;
|
|
7
|
+
};
|
|
8
|
+
declare const DEFAULT_WIDTHS: number[];
|
|
9
|
+
declare function isSupabaseImage(src: string): boolean;
|
|
10
|
+
declare function imageUrl(src: string, opts?: ImageOptions): string;
|
|
11
|
+
declare function srcset(src: string, opts?: {
|
|
12
|
+
widths?: number[];
|
|
13
|
+
quality?: number;
|
|
14
|
+
resize?: Resize;
|
|
15
|
+
}): string;
|
|
16
|
+
declare function imageProps(src: string, opts?: {
|
|
17
|
+
sizes?: string;
|
|
18
|
+
widths?: number[];
|
|
19
|
+
width?: number;
|
|
20
|
+
height?: number;
|
|
21
|
+
quality?: number;
|
|
22
|
+
}): {
|
|
23
|
+
src: string;
|
|
24
|
+
srcSet: string;
|
|
25
|
+
sizes: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { DEFAULT_WIDTHS, type ImageOptions, type Resize, imageProps, imageUrl, isSupabaseImage, srcset };
|
package/dist/image.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import './chunk-PKBMQBKP.js';
|
|
2
|
+
|
|
3
|
+
// src/image.ts
|
|
4
|
+
var OBJECT_PATH = "/storage/v1/object/public/";
|
|
5
|
+
var RENDER_PATH = "/storage/v1/render/image/public/";
|
|
6
|
+
var DEFAULT_WIDTHS = [320, 640, 960, 1280, 1920];
|
|
7
|
+
function isSupabaseImage(src) {
|
|
8
|
+
return src.includes(OBJECT_PATH) || src.includes(RENDER_PATH);
|
|
9
|
+
}
|
|
10
|
+
function imageUrl(src, opts = {}) {
|
|
11
|
+
if (!isSupabaseImage(src)) return src;
|
|
12
|
+
let url;
|
|
13
|
+
try {
|
|
14
|
+
url = new URL(src.replace(OBJECT_PATH, RENDER_PATH));
|
|
15
|
+
} catch {
|
|
16
|
+
return src;
|
|
17
|
+
}
|
|
18
|
+
if (opts.width) url.searchParams.set("width", String(Math.round(opts.width)));
|
|
19
|
+
if (opts.height) url.searchParams.set("height", String(Math.round(opts.height)));
|
|
20
|
+
if (opts.quality) url.searchParams.set("quality", String(opts.quality));
|
|
21
|
+
if (opts.resize) url.searchParams.set("resize", opts.resize);
|
|
22
|
+
return url.toString();
|
|
23
|
+
}
|
|
24
|
+
function srcset(src, opts = {}) {
|
|
25
|
+
if (!isSupabaseImage(src)) return "";
|
|
26
|
+
return (opts.widths ?? DEFAULT_WIDTHS).map((w) => `${imageUrl(src, { width: w, quality: opts.quality, resize: opts.resize })} ${w}w`).join(", ");
|
|
27
|
+
}
|
|
28
|
+
function imageProps(src, opts = {}) {
|
|
29
|
+
return {
|
|
30
|
+
src: imageUrl(src, { width: opts.width, height: opts.height, quality: opts.quality }),
|
|
31
|
+
srcSet: srcset(src, { widths: opts.widths, quality: opts.quality }),
|
|
32
|
+
sizes: opts.sizes ?? "100vw"
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { DEFAULT_WIDTHS, imageProps, imageUrl, isSupabaseImage, srcset };
|