@brandlab-digital/site-core 3.3.3 → 3.4.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/dist/geography.d.ts +11 -1
- package/dist/geography.d.ts.map +1 -1
- package/dist/geography.js +978 -0
- package/dist/geography.js.map +1 -1
- package/dist/location-policy.d.ts +89 -0
- package/dist/location-policy.d.ts.map +1 -0
- package/dist/location-policy.js +119 -0
- package/dist/location-policy.js.map +1 -0
- package/dist/locations.d.ts +63 -0
- package/dist/locations.d.ts.map +1 -1
- package/dist/locations.js +111 -0
- package/dist/locations.js.map +1 -1
- package/dist/project.d.ts +34 -0
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +94 -0
- package/dist/project.js.map +1 -1
- package/dist/sitemaps.d.ts +19 -1
- package/dist/sitemaps.d.ts.map +1 -1
- package/dist/sitemaps.js +30 -0
- package/dist/sitemaps.js.map +1 -1
- package/package.json +5 -1
package/dist/sitemaps.js
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
import { getAbsoluteUrl } from './metadata.js';
|
|
2
2
|
import { normalizeBrandlabRoutePath, resolveBrandlabRouteIndexing } from './routes.js';
|
|
3
|
+
export const BRANDLAB_SITEMAP_FAMILIES = Object.freeze([
|
|
4
|
+
Object.freeze({ name: 'services', kinds: Object.freeze(['service']) }),
|
|
5
|
+
Object.freeze({ name: 'locations', kinds: Object.freeze(['location']) }),
|
|
6
|
+
Object.freeze({ name: 'service-locations', kinds: Object.freeze(['service-location']) }),
|
|
7
|
+
Object.freeze({ name: 'blog', kinds: Object.freeze(['blog-post']) }),
|
|
8
|
+
Object.freeze({ name: 'projects', kinds: Object.freeze(['project']) }),
|
|
9
|
+
]);
|
|
10
|
+
/** The sitemap family a route kind belongs to. */
|
|
11
|
+
export function sitemapFamilyForKind(kind) {
|
|
12
|
+
return BRANDLAB_SITEMAP_FAMILIES.find((family) => family.kinds.includes(kind))?.name ?? 'core';
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The newest of a page's content dates (its own edit, its newest job, its
|
|
16
|
+
* newest sourced fact), for `lastSignificantChange`. Missing values are
|
|
17
|
+
* skipped; undefined when there is none. A date is returned exactly as given,
|
|
18
|
+
* so date-only values stay date-only. Never pass the build time.
|
|
19
|
+
*/
|
|
20
|
+
export function latestContentDate(...dates) {
|
|
21
|
+
let latest;
|
|
22
|
+
for (const value of dates.flat()) {
|
|
23
|
+
if (value === null || value === undefined)
|
|
24
|
+
continue;
|
|
25
|
+
const time = typeof value === 'string' && value.trim() === value ? Date.parse(value) : Number.NaN;
|
|
26
|
+
if (Number.isNaN(time))
|
|
27
|
+
throw new Error(`Content date must be a valid date: "${String(value)}".`);
|
|
28
|
+
if (!latest || time > latest.time)
|
|
29
|
+
latest = { value, time };
|
|
30
|
+
}
|
|
31
|
+
return latest?.value;
|
|
32
|
+
}
|
|
3
33
|
export function escapeXml(value) {
|
|
4
34
|
return value
|
|
5
35
|
.replace(/&/g, '&')
|
package/dist/sitemaps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sitemaps.js","sourceRoot":"","sources":["../src/sitemaps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C,OAAO,EAAE,0BAA0B,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAYtF,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,OAAO,KAAK;SACT,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;AAC5B,CAAC;AAED;;;;GAIG;AACH,SAAS,kBAAkB,CAAC,KAAmC;IAC7D,IAAI,CAAC,KAAK;QAAE,OAAO,I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O,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAC9C,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG,CAAC,CACzE,CAAA;IACD,IAAI,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,SAAS,CAAC,GAAG,IAAI,CAAC,CAAA;IAE9F,OAAO,OAAO,CAAA;AAChB,CAAC","sourcesContent":["import { getAbsoluteUrl } from './metadata.js'\nimport type { BrandlabRouteCatalog } from './routes.js'\nimport { normalizeBrandlabRoutePath, resolveBrandlabRouteIndexing } from './routes.js'\n\nexport interface SitemapEntry {\n url: string\n lastModified?: string | Date\n}\n\nexport interface SitemapChunk {\n path: string\n entries: readonly SitemapEntry[]\n}\n\nexport function escapeXml(value: string): string {\n return value\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''')\n}\n\n/**\n * A `lastmod` exactly as Next's metadata `sitemap.ts` writes it: a string is\n * kept verbatim (a `YYYY-MM-DD` date stays date-only) and only a `Date` becomes\n * an ISO timestamp.\n */\nfunction formatLastModified(value: SitemapEntry['lastModified']) {\n if (!value) return null\n if (value instanceof Date) {\n if (Number.isNaN(value.getTime())) throw new Error('Sitemap lastModified must be a valid date.')\n return value.toISOString()\n }\n if (typeof value !== 'string' || value.trim() !== value || Number.isNaN(Date.parse(value))) {\n throw new Error(`Sitemap lastModified must be a valid date: \"${String(value)}\".`)\n }\n return escapeXml(value)\n}\n\nfunction assertSitemapUrl(value: string, field: string) {\n let url: URL\n try {\n url = new URL(value)\n } catch {\n throw new Error(`${field} must be an absolute HTTPS URL.`)\n }\n if (url.protocol !== 'https:' || url.username || url.password || url.hash) {\n throw new Error(`${field} must be an absolute HTTPS URL without credentials or a hash.`)\n }\n}\n\n/**\n * Exactly the headers Next 16's metadata `sitemap.ts` route sends, so a route\n * served by the shared sitemap helper is indistinguishable from it.\n */\nexport function getSitemapXmlHeaders() {\n return {\n 'content-type': 'application/xml',\n 'cache-control': 'public, max-age=0, must-revalidate',\n }\n}\n\nconst XML_DECLARATION = '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n'\nconst SITEMAP_NAMESPACE = 'http://www.sitemaps.org/schemas/sitemap/0.9'\n\nexport function serializeSitemap(entries: readonly SitemapEntry[]): string {\n entries.forEach((entry, index) => assertSitemapUrl(entry.url, `entries[${index}].url`))\n const duplicate = entries.find((entry, index) =>\n entries.slice(0, index).some((candidate) => candidate.url === entry.url),\n )\n if (duplicate) throw new Error(`Sitemap contains duplicate URL \"${duplicate.url}\".`)\n // Byte-for-byte the layout of Next's metadata sitemap (resolveSitemap).\n let xml = `${XML_DECLARATION}<urlset xmlns=\"${SITEMAP_NAMESPACE}\">\\n`\n for (const entry of entries) {\n const lastModified = formatLastModified(entry.lastModified)\n xml += `<url>\\n<loc>${escapeXml(entry.url)}</loc>\\n`\n if (lastModified) xml += `<lastmod>${lastModified}</lastmod>\\n`\n xml += '</url>\\n'\n }\n return `${xml}</urlset>\\n`\n}\n\nexport function serializeSitemapIndex(\n paths: readonly string[],\n options: { absoluteUrl: (path: string) => string },\n): string {\n let xml = `${XML_DECLARATION}<sitemapindex xmlns=\"${SITEMAP_NAMESPACE}\">\\n`\n paths.forEach((path, index) => {\n const url = options.absoluteUrl(path)\n assertSitemapUrl(url, `paths[${index}]`)\n xml += `<sitemap>\\n<loc>${escapeXml(url)}</loc>\\n</sitemap>\\n`\n })\n return `${xml}</sitemapindex>\\n`\n}\n\nexport function createSitemapChunks(\n entries: readonly SitemapEntry[],\n options: {\n pathPrefix: string\n maxUrlsPerSitemap?: number\n },\n): SitemapChunk[] {\n const maxUrlsPerSitemap = options.maxUrlsPerSitemap ?? 500\n\n if (!Number.isInteger(maxUrlsPerSitemap) || maxUrlsPerSitemap < 1 || maxUrlsPerSitemap > 50_000) {\n throw new Error('maxUrlsPerSitemap must be an integer between 1 and 50000.')\n }\n\n const pathPrefix = options.pathPrefix.startsWith('/')\n ? options.pathPrefix\n : `/${options.pathPrefix}`\n const normalizedPrefix = pathPrefix.replace(/\\.xml$/, '')\n const chunks: SitemapChunk[] = []\n\n for (let index = 0; index < entries.length; index += maxUrlsPerSitemap) {\n chunks.push({\n path: `${normalizedPrefix}-${chunks.length + 1}.xml`,\n entries: entries.slice(index, index + maxUrlsPerSitemap),\n })\n }\n\n return chunks\n}\n\nexport function filterSitemapIndexPaths(\n groups: readonly { path: string; entryCount: number; includeWhenEmpty?: boolean }[],\n) {\n return groups\n .filter((group) => group.includeWhenEmpty || group.entryCount > 0)\n .map((group) => group.path)\n}\n\n/**\n * Builds canonical sitemap entries from the route catalog. It deliberately\n * omits priority and changeFrequency because search engines do not use those\n * values as reliable crawl signals.\n */\nexport function buildSitemapEntries(\n routes: BrandlabRouteCatalog,\n options: { siteUrl: string },\n): SitemapEntry[] {\n const siteUrl = new URL(options.siteUrl)\n if (\n siteUrl.protocol !== 'https:' ||\n siteUrl.username ||\n siteUrl.password ||\n siteUrl.pathname !== '/' ||\n siteUrl.search ||\n siteUrl.hash\n ) {\n throw new Error('siteUrl must be an absolute HTTPS origin.')\n }\n\n const entries = routes\n .filter((route) => resolveBrandlabRouteIndexing(route) === 'index')\n .map((route) => {\n const path = normalizeBrandlabRoutePath(route.canonicalPath ?? route.path)\n const lastModified = route.lastSignificantChange\n\n if (lastModified && Number.isNaN(Date.parse(lastModified))) {\n throw new Error(`Route \"${route.id}\" has an invalid lastSignificantChange date.`)\n }\n\n return {\n url: getAbsoluteUrl(siteUrl.origin, path),\n ...(lastModified ? { lastModified } : {}),\n }\n })\n\n const duplicate = entries.find((entry, index) =>\n entries.slice(0, index).some((candidate) => candidate.url === entry.url),\n )\n if (duplicate) throw new Error(`Sitemap contains duplicate canonical URL \"${duplicate.url}\".`)\n\n return entries\n}\n"]}
|
|
1
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D,IAAI,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,SAAS,CAAC,GAAG,IAAI,CAAC,CAAA;IAE9F,OAAO,OAAO,CAAA;AAChB,CAAC","sourcesContent":["import { getAbsoluteUrl } from './metadata.js'\nimport type { BrandlabRouteCatalog, BrandlabRouteKind } from './routes.js'\nimport { normalizeBrandlabRoutePath, resolveBrandlabRouteIndexing } from './routes.js'\n\n/**\n * The page families a split sitemap writes to separate files, so Search\n * Console reports index coverage per family. Every other route kind is `core`.\n */\nexport type BrandlabSitemapFamily = 'core' | 'services' | 'locations' | 'service-locations' | 'blog' | 'projects'\n\nexport const BRANDLAB_SITEMAP_FAMILIES: readonly {\n name: Exclude<BrandlabSitemapFamily, 'core'>\n kinds: readonly BrandlabRouteKind[]\n}[] = Object.freeze([\n Object.freeze({ name: 'services', kinds: Object.freeze(['service'] as const) }),\n Object.freeze({ name: 'locations', kinds: Object.freeze(['location'] as const) }),\n Object.freeze({ name: 'service-locations', kinds: Object.freeze(['service-location'] as const) }),\n Object.freeze({ name: 'blog', kinds: Object.freeze(['blog-post'] as const) }),\n Object.freeze({ name: 'projects', kinds: Object.freeze(['project'] as const) }),\n])\n\n/** The sitemap family a route kind belongs to. */\nexport function sitemapFamilyForKind(kind: string): BrandlabSitemapFamily {\n return BRANDLAB_SITEMAP_FAMILIES.find((family) => (family.kinds as readonly string[]).includes(kind))?.name ?? 'core'\n}\n\n/**\n * The newest of a page's content dates (its own edit, its newest job, its\n * newest sourced fact), for `lastSignificantChange`. Missing values are\n * skipped; undefined when there is none. A date is returned exactly as given,\n * so date-only values stay date-only. Never pass the build time.\n */\nexport function latestContentDate(\n ...dates: readonly (string | null | undefined | readonly (string | null | undefined)[])[]\n): string | undefined {\n let latest: { value: string; time: number } | undefined\n for (const value of dates.flat()) {\n if (value === null || value === undefined) continue\n const time = typeof value === 'string' && value.trim() === value ? Date.parse(value) : Number.NaN\n if (Number.isNaN(time)) throw new Error(`Content date must be a valid date: \"${String(value)}\".`)\n if (!latest || time > latest.time) latest = { value, time }\n }\n return latest?.value\n}\n\nexport interface SitemapEntry {\n url: string\n lastModified?: string | Date\n}\n\nexport interface SitemapChunk {\n path: string\n entries: readonly SitemapEntry[]\n}\n\nexport function escapeXml(value: string): string {\n return value\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''')\n}\n\n/**\n * A `lastmod` exactly as Next's metadata `sitemap.ts` writes it: a string is\n * kept verbatim (a `YYYY-MM-DD` date stays date-only) and only a `Date` becomes\n * an ISO timestamp.\n */\nfunction formatLastModified(value: SitemapEntry['lastModified']) {\n if (!value) return null\n if (value instanceof Date) {\n if (Number.isNaN(value.getTime())) throw new Error('Sitemap lastModified must be a valid date.')\n return value.toISOString()\n }\n if (typeof value !== 'string' || value.trim() !== value || Number.isNaN(Date.parse(value))) {\n throw new Error(`Sitemap lastModified must be a valid date: \"${String(value)}\".`)\n }\n return escapeXml(value)\n}\n\nfunction assertSitemapUrl(value: string, field: string) {\n let url: URL\n try {\n url = new URL(value)\n } catch {\n throw new Error(`${field} must be an absolute HTTPS URL.`)\n }\n if (url.protocol !== 'https:' || url.username || url.password || url.hash) {\n throw new Error(`${field} must be an absolute HTTPS URL without credentials or a hash.`)\n }\n}\n\n/**\n * Exactly the headers Next 16's metadata `sitemap.ts` route sends, so a route\n * served by the shared sitemap helper is indistinguishable from it.\n */\nexport function getSitemapXmlHeaders() {\n return {\n 'content-type': 'application/xml',\n 'cache-control': 'public, max-age=0, must-revalidate',\n }\n}\n\nconst XML_DECLARATION = '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n'\nconst SITEMAP_NAMESPACE = 'http://www.sitemaps.org/schemas/sitemap/0.9'\n\nexport function serializeSitemap(entries: readonly SitemapEntry[]): string {\n entries.forEach((entry, index) => assertSitemapUrl(entry.url, `entries[${index}].url`))\n const duplicate = entries.find((entry, index) =>\n entries.slice(0, index).some((candidate) => candidate.url === entry.url),\n )\n if (duplicate) throw new Error(`Sitemap contains duplicate URL \"${duplicate.url}\".`)\n // Byte-for-byte the layout of Next's metadata sitemap (resolveSitemap).\n let xml = `${XML_DECLARATION}<urlset xmlns=\"${SITEMAP_NAMESPACE}\">\\n`\n for (const entry of entries) {\n const lastModified = formatLastModified(entry.lastModified)\n xml += `<url>\\n<loc>${escapeXml(entry.url)}</loc>\\n`\n if (lastModified) xml += `<lastmod>${lastModified}</lastmod>\\n`\n xml += '</url>\\n'\n }\n return `${xml}</urlset>\\n`\n}\n\nexport function serializeSitemapIndex(\n paths: readonly string[],\n options: { absoluteUrl: (path: string) => string },\n): string {\n let xml = `${XML_DECLARATION}<sitemapindex xmlns=\"${SITEMAP_NAMESPACE}\">\\n`\n paths.forEach((path, index) => {\n const url = options.absoluteUrl(path)\n assertSitemapUrl(url, `paths[${index}]`)\n xml += `<sitemap>\\n<loc>${escapeXml(url)}</loc>\\n</sitemap>\\n`\n })\n return `${xml}</sitemapindex>\\n`\n}\n\nexport function createSitemapChunks(\n entries: readonly SitemapEntry[],\n options: {\n pathPrefix: string\n maxUrlsPerSitemap?: number\n },\n): SitemapChunk[] {\n const maxUrlsPerSitemap = options.maxUrlsPerSitemap ?? 500\n\n if (!Number.isInteger(maxUrlsPerSitemap) || maxUrlsPerSitemap < 1 || maxUrlsPerSitemap > 50_000) {\n throw new Error('maxUrlsPerSitemap must be an integer between 1 and 50000.')\n }\n\n const pathPrefix = options.pathPrefix.startsWith('/')\n ? options.pathPrefix\n : `/${options.pathPrefix}`\n const normalizedPrefix = pathPrefix.replace(/\\.xml$/, '')\n const chunks: SitemapChunk[] = []\n\n for (let index = 0; index < entries.length; index += maxUrlsPerSitemap) {\n chunks.push({\n path: `${normalizedPrefix}-${chunks.length + 1}.xml`,\n entries: entries.slice(index, index + maxUrlsPerSitemap),\n })\n }\n\n return chunks\n}\n\nexport function filterSitemapIndexPaths(\n groups: readonly { path: string; entryCount: number; includeWhenEmpty?: boolean }[],\n) {\n return groups\n .filter((group) => group.includeWhenEmpty || group.entryCount > 0)\n .map((group) => group.path)\n}\n\n/**\n * Builds canonical sitemap entries from the route catalog. It deliberately\n * omits priority and changeFrequency because search engines do not use those\n * values as reliable crawl signals.\n */\nexport function buildSitemapEntries(\n routes: BrandlabRouteCatalog,\n options: { siteUrl: string },\n): SitemapEntry[] {\n const siteUrl = new URL(options.siteUrl)\n if (\n siteUrl.protocol !== 'https:' ||\n siteUrl.username ||\n siteUrl.password ||\n siteUrl.pathname !== '/' ||\n siteUrl.search ||\n siteUrl.hash\n ) {\n throw new Error('siteUrl must be an absolute HTTPS origin.')\n }\n\n const entries = routes\n .filter((route) => resolveBrandlabRouteIndexing(route) === 'index')\n .map((route) => {\n const path = normalizeBrandlabRoutePath(route.canonicalPath ?? route.path)\n const lastModified = route.lastSignificantChange\n\n if (lastModified && Number.isNaN(Date.parse(lastModified))) {\n throw new Error(`Route \"${route.id}\" has an invalid lastSignificantChange date.`)\n }\n\n return {\n url: getAbsoluteUrl(siteUrl.origin, path),\n ...(lastModified ? { lastModified } : {}),\n }\n })\n\n const duplicate = entries.find((entry, index) =>\n entries.slice(0, index).some((candidate) => candidate.url === entry.url),\n )\n if (duplicate) throw new Error(`Sitemap contains duplicate canonical URL \"${duplicate.url}\".`)\n\n return entries\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brandlab-digital/site-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -84,6 +84,10 @@
|
|
|
84
84
|
"types": "./dist/locations.d.ts",
|
|
85
85
|
"import": "./dist/locations.js"
|
|
86
86
|
},
|
|
87
|
+
"./location-policy": {
|
|
88
|
+
"types": "./dist/location-policy.d.ts",
|
|
89
|
+
"import": "./dist/location-policy.js"
|
|
90
|
+
},
|
|
87
91
|
"./geography": {
|
|
88
92
|
"types": "./dist/geography.d.ts",
|
|
89
93
|
"browser": null,
|