brease-client 0.8.0 → 0.8.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/README.md +18 -1
- package/dist/astro.d.cts +1 -1
- package/dist/astro.d.ts +1 -1
- package/dist/{chunk-SO4BD4ME.js → chunk-MWTYINWA.js} +14 -2
- package/dist/html.d.cts +1 -1
- package/dist/html.d.ts +1 -1
- package/dist/image.d.cts +1 -1
- package/dist/image.d.ts +1 -1
- package/dist/index.cjs +14 -1
- package/dist/index.d.cts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +1 -1
- package/dist/next.cjs +6 -1
- package/dist/next.d.cts +1 -1
- package/dist/next.d.ts +1 -1
- package/dist/next.js +2 -2
- package/dist/{types-DeS_3KtO.d.cts → types-D5mwpqAP.d.cts} +3 -1
- package/dist/{types-DeS_3KtO.d.ts → types-D5mwpqAP.d.ts} +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,7 +28,8 @@ const brease = createBrease({
|
|
|
28
28
|
|
|
29
29
|
await brease.getSite() // name, url (the public address), locales, defaultLocale, localeStrategy, global SEO, analytics
|
|
30
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, name, index, parentId, order }]
|
|
31
|
+
await brease.getPages({ locale: 'en' }) // [{ pageId, locale, slug, url, hidden, name, index, parentId, order, template }]
|
|
32
|
+
await brease.getPages({ locale: 'en', parentId: news.pageId, withContent: true }) // a news list, with each page's content
|
|
32
33
|
await brease.getNavigation('main', { locale: 'en' }) // { key, locale, items } | null
|
|
33
34
|
await brease.getRedirects() // [{ source, destination, status }], cached for a minute
|
|
34
35
|
await brease.resolve('/en/about') // { slug: 'about', locale: 'en' } | null
|
|
@@ -42,6 +43,9 @@ await brease.sitemap(site.url) // [{ url, alternates }]: pages search may show
|
|
|
42
43
|
- 429 and 5xx responses (and network errors) are retried twice with backoff; `Retry-After` is honoured.
|
|
43
44
|
- 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.
|
|
44
45
|
- `sitemap()` lists only pages search may show: not hidden, not kept out of search (`index: false`, the page's "Show in search results" switch), and no site-wide `_` pages. It has no `lastModified`: releases are immutable snapshots and do not track per-page edit times.
|
|
46
|
+
- `getPages({ parentId, template, withContent })` narrows the list to a page's children or one template, and with
|
|
47
|
+
`withContent` adds each page's content (one locale, hidden pages left out, up to 100 pages): build news, team or
|
|
48
|
+
job lists from it instead of fetching every page.
|
|
45
49
|
- `site.url` is the site's public address (its primary domain), the one Brease uses in canonical URLs and hreflang; use it for the sitemap and `metadataBase` rather than an env variable of your own.
|
|
46
50
|
- `getSite()` is cached for a minute, so a locale added in Brease is served without a restart.
|
|
47
51
|
- `buildPath(settings, slug, locale)` and `resolvePath(settings, pathname)` are exported for routing code that already has the site settings.
|
|
@@ -122,6 +126,19 @@ export const config = { matcher: ['/((?!_next|api|.*\\..*).*)'] }
|
|
|
122
126
|
Sources may use parameters as in Next's redirects (`/blog/:slug`, `/docs/:rest*`). `breaseRedirects()` (from
|
|
123
127
|
`brease-client/next`, for `next.config`) still works, but only reads redirects at build time.
|
|
124
128
|
|
|
129
|
+
`route()` also resolves other forms of a page's URL (`/en/about` where English has no prefix, `/about` where every
|
|
130
|
+
locale is prefixed); `resolvedSeo.canonical` points search engines at the real one. To redirect those forms too,
|
|
131
|
+
add this to the same proxy, before `NextResponse.next()`:
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import { canonicalPath } from 'brease-client'
|
|
135
|
+
|
|
136
|
+
const site = await brease.getSite()
|
|
137
|
+
const canonical = canonicalPath(site, req.nextUrl.pathname)
|
|
138
|
+
if (canonical && (await brease.getPages()).some((p) => p.url === canonical))
|
|
139
|
+
return NextResponse.redirect(new URL(canonical + req.nextUrl.search, req.url), 308)
|
|
140
|
+
```
|
|
141
|
+
|
|
125
142
|
### Structured data (JSON-LD)
|
|
126
143
|
|
|
127
144
|
Structured data is content: the page's own entries (its SEO in Brease) and the site's (site SEO) come together in
|
package/dist/astro.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HeadOptions } from './html.cjs';
|
|
2
2
|
export { HeadTag, headTagList, headTags } from './html.cjs';
|
|
3
|
-
import { R as ResolvedSeo } from './types-
|
|
3
|
+
import { R as ResolvedSeo } from './types-D5mwpqAP.cjs';
|
|
4
4
|
|
|
5
5
|
declare function breaseHead(seo: ResolvedSeo, opts?: HeadOptions): string;
|
|
6
6
|
|
package/dist/astro.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HeadOptions } from './html.js';
|
|
2
2
|
export { HeadTag, headTagList, headTags } from './html.js';
|
|
3
|
-
import { R as ResolvedSeo } from './types-
|
|
3
|
+
import { R as ResolvedSeo } from './types-D5mwpqAP.js';
|
|
4
4
|
|
|
5
5
|
declare function breaseHead(seo: ResolvedSeo, opts?: HeadOptions): string;
|
|
6
6
|
|
|
@@ -72,6 +72,13 @@ function resolvePath(settings, pathname) {
|
|
|
72
72
|
}
|
|
73
73
|
return { slug: clean, locale: settings.defaultLocale };
|
|
74
74
|
}
|
|
75
|
+
function canonicalPath(settings, pathname) {
|
|
76
|
+
const path = pathname.split(/[?#]/)[0] ?? "";
|
|
77
|
+
const { slug, locale } = resolvePath(settings, path);
|
|
78
|
+
const canonical = buildPath(settings, slug, locale);
|
|
79
|
+
const trim = (p) => p.length > 1 ? p.replace(/\/+$/, "") : p;
|
|
80
|
+
return trim(decodeURIComponent(path)) === trim(canonical) ? null : canonical;
|
|
81
|
+
}
|
|
75
82
|
|
|
76
83
|
// src/analytics.ts
|
|
77
84
|
var MEASUREMENT_ID = /^G-[A-Z0-9]+$/;
|
|
@@ -290,7 +297,12 @@ function createBrease(opts = {}) {
|
|
|
290
297
|
return request("/content-api/page", { slug, locale }, true);
|
|
291
298
|
},
|
|
292
299
|
getPages(o = {}) {
|
|
293
|
-
return request("/content-api/pages", {
|
|
300
|
+
return request("/content-api/pages", {
|
|
301
|
+
locale: o.locale,
|
|
302
|
+
parentId: o.parentId,
|
|
303
|
+
template: o.template,
|
|
304
|
+
withContent: o.withContent ? "1" : void 0
|
|
305
|
+
});
|
|
294
306
|
},
|
|
295
307
|
getNavigation(key, { locale }) {
|
|
296
308
|
return request(`/content-api/navigations/${encodeURIComponent(key)}`, { locale }, true);
|
|
@@ -368,4 +380,4 @@ function pathOf(url) {
|
|
|
368
380
|
}
|
|
369
381
|
}
|
|
370
382
|
|
|
371
|
-
export { BreaseError, buildPath, createBrease, customTags, env, fieldPath, ga4Html, ga4Tag, grantAnalytics, hmacHex, localeHref, localeLinks, matchRedirect, nativeName, navPath, normalizeSlug, resolvePath, verifyRevalidate, verifySignature };
|
|
383
|
+
export { BreaseError, buildPath, canonicalPath, createBrease, customTags, env, fieldPath, ga4Html, ga4Tag, grantAnalytics, hmacHex, localeHref, localeLinks, matchRedirect, nativeName, navPath, normalizeSlug, resolvePath, verifyRevalidate, verifySignature };
|
package/dist/html.d.cts
CHANGED
package/dist/html.d.ts
CHANGED
package/dist/image.d.cts
CHANGED
package/dist/image.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -76,6 +76,13 @@ function resolvePath(settings, pathname) {
|
|
|
76
76
|
}
|
|
77
77
|
return { slug: clean, locale: settings.defaultLocale };
|
|
78
78
|
}
|
|
79
|
+
function canonicalPath(settings, pathname) {
|
|
80
|
+
const path = pathname.split(/[?#]/)[0] ?? "";
|
|
81
|
+
const { slug, locale } = resolvePath(settings, path);
|
|
82
|
+
const canonical = buildPath(settings, slug, locale);
|
|
83
|
+
const trim = (p) => p.length > 1 ? p.replace(/\/+$/, "") : p;
|
|
84
|
+
return trim(decodeURIComponent(path)) === trim(canonical) ? null : canonical;
|
|
85
|
+
}
|
|
79
86
|
|
|
80
87
|
// src/analytics.ts
|
|
81
88
|
var MEASUREMENT_ID = /^G-[A-Z0-9]+$/;
|
|
@@ -381,7 +388,12 @@ function createBrease(opts = {}) {
|
|
|
381
388
|
return request("/content-api/page", { slug, locale }, true);
|
|
382
389
|
},
|
|
383
390
|
getPages(o = {}) {
|
|
384
|
-
return request("/content-api/pages", {
|
|
391
|
+
return request("/content-api/pages", {
|
|
392
|
+
locale: o.locale,
|
|
393
|
+
parentId: o.parentId,
|
|
394
|
+
template: o.template,
|
|
395
|
+
withContent: o.withContent ? "1" : void 0
|
|
396
|
+
});
|
|
385
397
|
},
|
|
386
398
|
getNavigation(key, { locale }) {
|
|
387
399
|
return request(`/content-api/navigations/${encodeURIComponent(key)}`, { locale }, true);
|
|
@@ -461,6 +473,7 @@ function pathOf(url) {
|
|
|
461
473
|
|
|
462
474
|
exports.BreaseError = BreaseError;
|
|
463
475
|
exports.buildPath = buildPath;
|
|
476
|
+
exports.canonicalPath = canonicalPath;
|
|
464
477
|
exports.checkSections = checkSections;
|
|
465
478
|
exports.createBrease = createBrease;
|
|
466
479
|
exports.customTags = customTags;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Site, R as ResolvedSeo, U as UrlSettings, a as Redirect, P as Page, b as PageRef, N as Navigation, c as Release, d as SitemapEntry } from './types-
|
|
2
|
-
export { B as BreaseImage, e as BreaseLink, L as LocaleStrategy, f as NavigationItem, O as OpenGraph, g as PageSeo, h as Robots, i as SiteSeo, T as Twitter } from './types-
|
|
1
|
+
import { S as Site, R as ResolvedSeo, U as UrlSettings, a as Redirect, P as Page, b as PageRef, N as Navigation, c as Release, d as SitemapEntry } from './types-D5mwpqAP.cjs';
|
|
2
|
+
export { B as BreaseImage, e as BreaseLink, L as LocaleStrategy, f as NavigationItem, O as OpenGraph, g as PageSeo, h as Robots, i as SiteSeo, T as Twitter } from './types-D5mwpqAP.cjs';
|
|
3
3
|
|
|
4
4
|
type Ga4Tag = {
|
|
5
5
|
id: string;
|
|
@@ -102,6 +102,7 @@ declare function resolvePath(settings: UrlSettings, pathname: string): {
|
|
|
102
102
|
slug: string;
|
|
103
103
|
locale: string;
|
|
104
104
|
};
|
|
105
|
+
declare function canonicalPath(settings: UrlSettings, pathname: string): string | null;
|
|
105
106
|
|
|
106
107
|
type LocaleContext = {
|
|
107
108
|
locale: string;
|
|
@@ -124,6 +125,9 @@ interface Brease {
|
|
|
124
125
|
}): Promise<Page<T> | null>;
|
|
125
126
|
getPages(opts?: {
|
|
126
127
|
locale?: string;
|
|
128
|
+
parentId?: string;
|
|
129
|
+
template?: string;
|
|
130
|
+
withContent?: boolean;
|
|
127
131
|
}): Promise<PageRef[]>;
|
|
128
132
|
getNavigation(key: string, opts: {
|
|
129
133
|
locale: string;
|
|
@@ -146,4 +150,4 @@ interface Brease {
|
|
|
146
150
|
}
|
|
147
151
|
declare function createBrease(opts?: BreaseOptions): Brease;
|
|
148
152
|
|
|
149
|
-
export { type Brease, BreaseError, type BreaseOptions, type BreaseSection, type CustomTag, type Ga4Tag, type JsonLd, type LocaleContext, type LocaleLink, Navigation, Page, PageRef, Redirect, Release, ResolvedSeo, type RevalidateBody, type RevalidateTarget, Site, SitemapEntry, UrlSettings, buildPath, checkSections, createBrease, customTags, fieldPath, ga4Html, ga4Tag, grantAnalytics, hmacHex, jsonLd, jsonLdHtml, localeHref, localeLinks, matchRedirect, nativeName, navPath, normalizeSlug, resolvePath, sectionAttrs, sectionsAttrs, verifyRevalidate, verifySignature };
|
|
153
|
+
export { type Brease, BreaseError, type BreaseOptions, type BreaseSection, type CustomTag, type Ga4Tag, type JsonLd, type LocaleContext, type LocaleLink, Navigation, Page, PageRef, Redirect, Release, ResolvedSeo, type RevalidateBody, type RevalidateTarget, Site, SitemapEntry, UrlSettings, buildPath, canonicalPath, checkSections, createBrease, customTags, fieldPath, ga4Html, ga4Tag, grantAnalytics, hmacHex, jsonLd, jsonLdHtml, localeHref, localeLinks, matchRedirect, nativeName, navPath, normalizeSlug, resolvePath, sectionAttrs, sectionsAttrs, verifyRevalidate, verifySignature };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Site, R as ResolvedSeo, U as UrlSettings, a as Redirect, P as Page, b as PageRef, N as Navigation, c as Release, d as SitemapEntry } from './types-
|
|
2
|
-
export { B as BreaseImage, e as BreaseLink, L as LocaleStrategy, f as NavigationItem, O as OpenGraph, g as PageSeo, h as Robots, i as SiteSeo, T as Twitter } from './types-
|
|
1
|
+
import { S as Site, R as ResolvedSeo, U as UrlSettings, a as Redirect, P as Page, b as PageRef, N as Navigation, c as Release, d as SitemapEntry } from './types-D5mwpqAP.js';
|
|
2
|
+
export { B as BreaseImage, e as BreaseLink, L as LocaleStrategy, f as NavigationItem, O as OpenGraph, g as PageSeo, h as Robots, i as SiteSeo, T as Twitter } from './types-D5mwpqAP.js';
|
|
3
3
|
|
|
4
4
|
type Ga4Tag = {
|
|
5
5
|
id: string;
|
|
@@ -102,6 +102,7 @@ declare function resolvePath(settings: UrlSettings, pathname: string): {
|
|
|
102
102
|
slug: string;
|
|
103
103
|
locale: string;
|
|
104
104
|
};
|
|
105
|
+
declare function canonicalPath(settings: UrlSettings, pathname: string): string | null;
|
|
105
106
|
|
|
106
107
|
type LocaleContext = {
|
|
107
108
|
locale: string;
|
|
@@ -124,6 +125,9 @@ interface Brease {
|
|
|
124
125
|
}): Promise<Page<T> | null>;
|
|
125
126
|
getPages(opts?: {
|
|
126
127
|
locale?: string;
|
|
128
|
+
parentId?: string;
|
|
129
|
+
template?: string;
|
|
130
|
+
withContent?: boolean;
|
|
127
131
|
}): Promise<PageRef[]>;
|
|
128
132
|
getNavigation(key: string, opts: {
|
|
129
133
|
locale: string;
|
|
@@ -146,4 +150,4 @@ interface Brease {
|
|
|
146
150
|
}
|
|
147
151
|
declare function createBrease(opts?: BreaseOptions): Brease;
|
|
148
152
|
|
|
149
|
-
export { type Brease, BreaseError, type BreaseOptions, type BreaseSection, type CustomTag, type Ga4Tag, type JsonLd, type LocaleContext, type LocaleLink, Navigation, Page, PageRef, Redirect, Release, ResolvedSeo, type RevalidateBody, type RevalidateTarget, Site, SitemapEntry, UrlSettings, buildPath, checkSections, createBrease, customTags, fieldPath, ga4Html, ga4Tag, grantAnalytics, hmacHex, jsonLd, jsonLdHtml, localeHref, localeLinks, matchRedirect, nativeName, navPath, normalizeSlug, resolvePath, sectionAttrs, sectionsAttrs, verifyRevalidate, verifySignature };
|
|
153
|
+
export { type Brease, BreaseError, type BreaseOptions, type BreaseSection, type CustomTag, type Ga4Tag, type JsonLd, type LocaleContext, type LocaleLink, Navigation, Page, PageRef, Redirect, Release, ResolvedSeo, type RevalidateBody, type RevalidateTarget, Site, SitemapEntry, UrlSettings, buildPath, canonicalPath, checkSections, createBrease, customTags, fieldPath, ga4Html, ga4Tag, grantAnalytics, hmacHex, jsonLd, jsonLdHtml, localeHref, localeLinks, matchRedirect, nativeName, navPath, normalizeSlug, resolvePath, sectionAttrs, sectionsAttrs, verifyRevalidate, verifySignature };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { BreaseError, buildPath, createBrease, customTags, fieldPath, ga4Html, ga4Tag, grantAnalytics, hmacHex, localeHref, localeLinks, matchRedirect, nativeName, navPath, normalizeSlug, resolvePath, verifyRevalidate, verifySignature } from './chunk-
|
|
1
|
+
export { BreaseError, buildPath, canonicalPath, createBrease, customTags, fieldPath, ga4Html, ga4Tag, grantAnalytics, hmacHex, localeHref, localeLinks, matchRedirect, nativeName, navPath, normalizeSlug, resolvePath, verifyRevalidate, verifySignature } from './chunk-MWTYINWA.js';
|
|
2
2
|
export { checkSections, sectionAttrs, sectionsAttrs } from './chunk-CQZLTZGN.js';
|
|
3
3
|
export { jsonLd, jsonLdHtml } from './chunk-N3QOL5EU.js';
|
|
4
4
|
import './chunk-PKBMQBKP.js';
|
package/dist/next.cjs
CHANGED
|
@@ -176,7 +176,12 @@ function createBrease(opts = {}) {
|
|
|
176
176
|
return request("/content-api/page", { slug, locale }, true);
|
|
177
177
|
},
|
|
178
178
|
getPages(o = {}) {
|
|
179
|
-
return request("/content-api/pages", {
|
|
179
|
+
return request("/content-api/pages", {
|
|
180
|
+
locale: o.locale,
|
|
181
|
+
parentId: o.parentId,
|
|
182
|
+
template: o.template,
|
|
183
|
+
withContent: o.withContent ? "1" : void 0
|
|
184
|
+
});
|
|
180
185
|
},
|
|
181
186
|
getNavigation(key, { locale }) {
|
|
182
187
|
return request(`/content-api/navigations/${encodeURIComponent(key)}`, { locale }, true);
|
package/dist/next.d.cts
CHANGED
package/dist/next.d.ts
CHANGED
package/dist/next.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { env, verifyRevalidate, createBrease } from './chunk-
|
|
2
|
-
export { hmacHex, verifySignature } from './chunk-
|
|
1
|
+
import { env, verifyRevalidate, createBrease } from './chunk-MWTYINWA.js';
|
|
2
|
+
export { hmacHex, verifySignature } from './chunk-MWTYINWA.js';
|
|
3
3
|
import './chunk-CQZLTZGN.js';
|
|
4
4
|
import './chunk-N3QOL5EU.js';
|
|
5
5
|
import './chunk-PKBMQBKP.js';
|
|
@@ -103,11 +103,13 @@ type Page<T = Record<string, unknown>> = {
|
|
|
103
103
|
resolvedSeo: ResolvedSeo;
|
|
104
104
|
alternates: Record<string, string>;
|
|
105
105
|
};
|
|
106
|
-
type PageRef = Pick<Page, 'pageId' | 'locale' | 'slug' | 'url' | 'hidden'> & {
|
|
106
|
+
type PageRef<T = Record<string, unknown>> = Pick<Page, 'pageId' | 'locale' | 'slug' | 'url' | 'hidden'> & {
|
|
107
107
|
name?: string;
|
|
108
108
|
index?: boolean;
|
|
109
109
|
parentId?: string | null;
|
|
110
110
|
order?: number;
|
|
111
|
+
template?: string | null;
|
|
112
|
+
content?: T;
|
|
111
113
|
};
|
|
112
114
|
type NavigationItem = {
|
|
113
115
|
id: string;
|
|
@@ -103,11 +103,13 @@ type Page<T = Record<string, unknown>> = {
|
|
|
103
103
|
resolvedSeo: ResolvedSeo;
|
|
104
104
|
alternates: Record<string, string>;
|
|
105
105
|
};
|
|
106
|
-
type PageRef = Pick<Page, 'pageId' | 'locale' | 'slug' | 'url' | 'hidden'> & {
|
|
106
|
+
type PageRef<T = Record<string, unknown>> = Pick<Page, 'pageId' | 'locale' | 'slug' | 'url' | 'hidden'> & {
|
|
107
107
|
name?: string;
|
|
108
108
|
index?: boolean;
|
|
109
109
|
parentId?: string | null;
|
|
110
110
|
order?: number;
|
|
111
|
+
template?: string | null;
|
|
112
|
+
content?: T;
|
|
111
113
|
};
|
|
112
114
|
type NavigationItem = {
|
|
113
115
|
id: string;
|