@koehler8/cms 1.0.0-beta.20 → 1.0.0-beta.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koehler8/cms",
3
- "version": "1.0.0-beta.20",
3
+ "version": "1.0.0-beta.21",
4
4
  "description": "Vertex CMS — lightweight, config-driven Vue 3 framework with theming, extensions, and SSG support",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -50,6 +50,7 @@ export function usePageConfig({ pageId, pagePath, locale, onPageLoaded } = {}) {
50
50
  content: data.content || {},
51
51
  meta: data.meta || {},
52
52
  draft: data.draft,
53
+ jsonld: data.jsonld,
53
54
  };
54
55
  };
55
56
 
@@ -72,6 +73,7 @@ export function usePageConfig({ pageId, pagePath, locale, onPageLoaded } = {}) {
72
73
  content: data.content || {},
73
74
  meta: data.meta || {},
74
75
  draft: data.draft,
76
+ jsonld: data.jsonld,
75
77
  };
76
78
  }
77
79
  }
@@ -113,6 +115,7 @@ export function usePageConfig({ pageId, pagePath, locale, onPageLoaded } = {}) {
113
115
  content: firstData.content || {},
114
116
  meta: firstData.meta || {},
115
117
  draft: firstData.draft,
118
+ jsonld: firstData.jsonld,
116
119
  };
117
120
  }
118
121
 
@@ -3,8 +3,20 @@ import { useHead } from '@unhead/vue';
3
3
  import { isPathDraft } from '../utils/draftMode.js';
4
4
  import { buildCanonicalUrl } from '../utils/canonicalUrl.js';
5
5
  import { buildSocialMeta } from '../utils/socialMeta.js';
6
+ import { buildJsonLdScripts } from '../utils/jsonLd.js';
6
7
  import { availableLocales as configAvailableLocales, baseLocale as configBaseLocale } from '../utils/loadConfig.js';
7
8
 
9
+ // Site-verification meta-tag names per platform. Authors set
10
+ // `site.siteVerification.<platform>` in site.json with the token issued by
11
+ // the platform's webmaster console; we emit one <meta> per platform.
12
+ const SITE_VERIFICATION_META = {
13
+ google: 'google-site-verification',
14
+ bing: 'msvalidate.01',
15
+ yandex: 'yandex-verification',
16
+ pinterest: 'p:domain_verify',
17
+ facebook: 'facebook-domain-verification',
18
+ };
19
+
8
20
  const SPECIAL_PAGE_LABELS = {
9
21
  home: '',
10
22
  terms: 'Terms of Service',
@@ -162,6 +174,22 @@ export function usePageMeta({ siteData, currentPage, locale }) {
162
174
  isNotFound: isNotFound.value,
163
175
  });
164
176
  for (const entry of social) meta.push(entry);
177
+
178
+ // Site-verification meta tags. These are emitted on every page (not
179
+ // just home) — verification platforms typically only check homepage
180
+ // but emitting site-wide is harmless and matches what most CMSs do.
181
+ const verification = siteData.value?.site?.siteVerification;
182
+ if (verification && typeof verification === 'object') {
183
+ for (const [platform, token] of Object.entries(verification)) {
184
+ const metaName = SITE_VERIFICATION_META[platform];
185
+ if (!metaName) continue;
186
+ if (typeof token !== 'string') continue;
187
+ const trimmed = token.trim();
188
+ if (!trimmed) continue;
189
+ meta.push({ name: metaName, content: trimmed, key: `verify-${platform}` });
190
+ }
191
+ }
192
+
165
193
  const link = [];
166
194
  if (canonicalHref.value) {
167
195
  link.push({ rel: 'canonical', href: canonicalHref.value, key: 'canonical' });
@@ -169,10 +197,19 @@ export function usePageMeta({ siteData, currentPage, locale }) {
169
197
  for (const entry of hreflangLinks.value) {
170
198
  link.push(entry);
171
199
  }
200
+
201
+ const script = buildJsonLdScripts({
202
+ siteData: siteData.value,
203
+ currentPage: currentPage.value,
204
+ isDraft: isDraft.value,
205
+ isNotFound: isNotFound.value,
206
+ });
207
+
172
208
  return {
173
209
  title: pageMetaTitle.value,
174
210
  meta,
175
211
  link,
212
+ script,
176
213
  };
177
214
  });
178
215
 
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Normalize per-page + site-wide JSON-LD blocks into a flat list of
3
+ * @unhead/vue script descriptors ready for `useHead({ script: [...] })`.
4
+ *
5
+ * Authoring conventions in `pages/{id}.json` and `site.json`:
6
+ *
7
+ * "jsonld": { "@context": "https://schema.org", "@type": "Article", ... }
8
+ *
9
+ * or for multiple blocks on a page:
10
+ *
11
+ * "jsonld": [
12
+ * { "@type": "Article", ... },
13
+ * { "@type": "BreadcrumbList", ... }
14
+ * ]
15
+ *
16
+ * Page blocks ALWAYS append to site blocks (there's no "override" semantic
17
+ * — each schema.org block is an independent assertion, so listing both is
18
+ * the right behavior for a sitewide Organization + a page-specific Article).
19
+ *
20
+ * Skipped entirely on drafts and 404s; structured data on those would
21
+ * mislead crawlers (drafts shouldn't be indexed; 404s aren't authoritative).
22
+ */
23
+
24
+ function normalizeBlock(block) {
25
+ if (!block || typeof block !== 'object' || Array.isArray(block)) return null;
26
+ // Inject the schema.org @context if the author omitted it. JSON-LD blocks
27
+ // without @context are ignored by all major consumers, so adding it
28
+ // defensively is the right default.
29
+ if (!block['@context']) {
30
+ return { '@context': 'https://schema.org', ...block };
31
+ }
32
+ return block;
33
+ }
34
+
35
+ function collectBlocks(input) {
36
+ if (!input) return [];
37
+ if (Array.isArray(input)) {
38
+ return input.map(normalizeBlock).filter(Boolean);
39
+ }
40
+ const single = normalizeBlock(input);
41
+ return single ? [single] : [];
42
+ }
43
+
44
+ export function buildJsonLdScripts({ siteData, currentPage, isDraft, isNotFound } = {}) {
45
+ if (isDraft || isNotFound) return [];
46
+
47
+ const siteBlocks = collectBlocks(siteData?.site?.jsonld);
48
+ const pageBlocks = collectBlocks(currentPage?.jsonld);
49
+
50
+ const all = [...siteBlocks, ...pageBlocks];
51
+ if (all.length === 0) return [];
52
+
53
+ return all.map((block, i) => ({
54
+ type: 'application/ld+json',
55
+ innerHTML: JSON.stringify(block),
56
+ key: `jsonld-${block['@type'] || 'block'}-${i}`,
57
+ }));
58
+ }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Build a Web App Manifest (manifest.json) from the inflated site config.
3
+ *
4
+ * Returns the manifest object — the plugin JSON-stringifies and writes it
5
+ * to `siteRoot/public/manifest.json`. Browsers consume the file when the
6
+ * page emits `<link rel="manifest" href="/manifest.json">`.
7
+ *
8
+ * Authoring conventions in `site.json`:
9
+ *
10
+ * "manifest.name": "...", // overrides site.title
11
+ * "manifest.shortName": "...", // overrides truncated site.title
12
+ * "manifest.themeColor": "#...", // mobile chrome / splash bar color
13
+ * "manifest.backgroundColor": "#...", // splash background
14
+ * "manifest.startUrl": "/", // landing path on launch
15
+ * "manifest.display": "standalone",// browser, standalone, fullscreen, minimal-ui
16
+ * "manifest.icons[0].src": "...", // override default icon set
17
+ * "manifest.icons[0].sizes": "256x256",
18
+ * "manifest.icons[0].type": "image/png"
19
+ *
20
+ * Defaults are derived from existing site config and the icons that
21
+ * cms-generate-public-assets writes (favicon-256.png + favicon.ico).
22
+ */
23
+
24
+ const DEFAULT_DISPLAY = 'standalone';
25
+ const DEFAULT_BG = '#ffffff';
26
+ const DEFAULT_THEME = '#ffffff';
27
+ const DEFAULT_START = '/';
28
+
29
+ function trim(value, fallback = '') {
30
+ if (typeof value !== 'string') return fallback;
31
+ const t = value.trim();
32
+ return t || fallback;
33
+ }
34
+
35
+ function defaultIcons() {
36
+ // Mirrors what cms-generate-public-assets writes into public/.
37
+ // Browsers pick the best size; the 256x256 PNG is the primary, the
38
+ // .ico is the legacy fallback for older Android.
39
+ return [
40
+ { src: '/favicon-256.png', sizes: '256x256', type: 'image/png', purpose: 'any maskable' },
41
+ { src: '/favicon.ico', sizes: '64x64 32x32 16x16', type: 'image/x-icon' },
42
+ ];
43
+ }
44
+
45
+ export function buildWebAppManifest(siteConfig) {
46
+ const site = (siteConfig && siteConfig.site) || {};
47
+ const m = (site.manifest && typeof site.manifest === 'object') ? site.manifest : {};
48
+
49
+ const siteTitle = trim(site.title);
50
+ const name = trim(m.name, siteTitle) || 'Site';
51
+ const shortName = trim(m.shortName, name.length <= 12 ? name : name.slice(0, 12));
52
+
53
+ const description = trim(m.description, trim(site.description));
54
+
55
+ const themeColor = trim(m.themeColor, DEFAULT_THEME);
56
+ const backgroundColor = trim(m.backgroundColor, DEFAULT_BG);
57
+ const startUrl = trim(m.startUrl, DEFAULT_START);
58
+ const display = trim(m.display, DEFAULT_DISPLAY);
59
+ const lang = trim(m.lang);
60
+
61
+ const customIcons = Array.isArray(m.icons)
62
+ ? m.icons
63
+ .filter((icon) => icon && typeof icon === 'object' && typeof icon.src === 'string')
64
+ .map((icon) => ({ ...icon }))
65
+ : null;
66
+ const icons = customIcons && customIcons.length ? customIcons : defaultIcons();
67
+
68
+ const manifest = {
69
+ name,
70
+ short_name: shortName,
71
+ start_url: startUrl,
72
+ display,
73
+ theme_color: themeColor,
74
+ background_color: backgroundColor,
75
+ icons,
76
+ };
77
+
78
+ if (description) manifest.description = description;
79
+ if (lang) manifest.lang = lang;
80
+
81
+ return manifest;
82
+ }
@@ -5,12 +5,13 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <!--
7
7
  Per-page <title>, <meta name="description">, og:*, twitter:*, canonical,
8
- and hreflang are emitted by usePageMeta at SSG render time. Site-wide
9
- structured-data (the JSON-LD Organization snippet below) and the
10
- static <link rel="icon"> remain in this template since they don't
11
- vary per page.
8
+ hreflang, and JSON-LD blocks are emitted by usePageMeta at SSG render
9
+ time. Site-wide invariants (favicon, web-app manifest, the JSON-LD
10
+ Organization snippet, mobile-chrome theme color) live here.
12
11
  -->
13
12
  <link rel="icon" href="/favicon.ico">
13
+ <link rel="manifest" href="/manifest.json">
14
+ <meta name="theme-color" content="<%= manifestThemeColor %>">
14
15
  <script type="application/ld+json">
15
16
  {
16
17
  "@context": "https://schema.org",
package/vite-plugin.js CHANGED
@@ -15,6 +15,7 @@ import vue from '@vitejs/plugin-vue';
15
15
  import { inflateFlatConfig } from './src/utils/inflateFlatConfig.js';
16
16
  import { buildRobotsTxt } from './src/utils/robotsGenerator.js';
17
17
  import { buildSitemap, getSitemapUrl } from './src/utils/sitemapGenerator.js';
18
+ import { buildWebAppManifest } from './src/utils/webAppManifest.js';
18
19
  import { sha256Hex } from './src/utils/sha256.js';
19
20
 
20
21
  // ---- Helpers ----
@@ -117,6 +118,7 @@ function extractSiteMetadata(siteConfig) {
117
118
  url: siteUrl = '',
118
119
  googleId: siteGoogleId = '',
119
120
  sameAs: siteSameAs = [],
121
+ manifest: siteManifest = {},
120
122
  } = siteConfig.site || {};
121
123
 
122
124
  const siteSameAsList = Array.isArray(siteSameAs)
@@ -124,7 +126,14 @@ function extractSiteMetadata(siteConfig) {
124
126
  : [];
125
127
  const siteSameAsJson = JSON.stringify(siteSameAsList);
126
128
 
127
- return { siteTitle, siteDescription, siteUrl, siteGoogleId, siteSameAsJson };
129
+ // Mobile chrome bar / PWA splash color. Defaults match buildWebAppManifest's
130
+ // default so the rendered <meta name="theme-color"> matches whatever
131
+ // manifest.json advertises.
132
+ const manifestThemeColor = (typeof siteManifest.themeColor === 'string'
133
+ ? siteManifest.themeColor.trim()
134
+ : '') || '#ffffff';
135
+
136
+ return { siteTitle, siteDescription, siteUrl, siteGoogleId, siteSameAsJson, manifestThemeColor };
128
137
  }
129
138
 
130
139
  const __filename = fileURLToPath(import.meta.url);
@@ -354,6 +363,7 @@ export default function cmsPlugin(options = {}) {
354
363
  siteUrl: metadata.siteUrl,
355
364
  siteGoogleId: metadata.siteGoogleId,
356
365
  siteSameAsJson: metadata.siteSameAsJson,
366
+ manifestThemeColor: metadata.manifestThemeColor,
357
367
  });
358
368
 
359
369
  const processed = html.replace(
@@ -418,6 +428,16 @@ export default function cmsPlugin(options = {}) {
418
428
  const sitemapUrl = sitemapXml ? getSitemapUrl(siteConfig) : '';
419
429
  const robotsBody = buildRobotsTxt(siteConfig, sitemapUrl);
420
430
  fs.writeFileSync(path.join(sitePublicDir, 'robots.txt'), robotsBody, 'utf-8');
431
+
432
+ // Web App Manifest. The template emits <link rel="manifest"> on every
433
+ // page; browsers use this to enable Add-to-Home-Screen + control
434
+ // splash colors when the site is launched from a homescreen icon.
435
+ const manifest = buildWebAppManifest(siteConfig);
436
+ fs.writeFileSync(
437
+ path.join(sitePublicDir, 'manifest.json'),
438
+ JSON.stringify(manifest, null, 2) + '\n',
439
+ 'utf-8',
440
+ );
421
441
  };
422
442
 
423
443
  const cmsCore = {
@@ -832,6 +852,7 @@ export const assetUrlMap = resolver.assetUrlMap;
832
852
  siteUrl: metadata.siteUrl,
833
853
  siteGoogleId: metadata.siteGoogleId,
834
854
  siteSameAsJson: metadata.siteSameAsJson,
855
+ manifestThemeColor: metadata.manifestThemeColor,
835
856
  });
836
857
 
837
858
  html = html.replace(