@oktis-works/web 0.17.2 → 1.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/README.md +20 -112
- package/dist/index.js +60 -43
- package/dist/index.js.map +1 -1
- package/dist/jsonld.d.ts +1 -1
- package/dist/jsonld.js +1 -1
- package/dist/rendering.d.ts +11 -33
- package/dist/rendering.d.ts.map +1 -1
- package/dist/rendering.js +57 -261
- package/dist/rendering.js.map +1 -1
- package/dist/rss.d.ts +2 -0
- package/dist/rss.d.ts.map +1 -1
- package/dist/rss.js +9 -9
- package/dist/rss.js.map +1 -1
- package/dist/theme-bridge.d.ts +13 -0
- package/dist/theme-bridge.d.ts.map +1 -0
- package/dist/theme-bridge.js +116 -0
- package/dist/theme-bridge.js.map +1 -0
- package/dist/theme-data.js +1 -1
- package/dist/theme-data.js.map +1 -1
- package/package.json +9 -9
package/dist/rendering.d.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { getConnection } from '@oktis-works/database';
|
|
2
2
|
import type { EnqueuedAsset } from '@oktis-works/plugin-sdk';
|
|
3
|
-
import { RuntimeRouter,
|
|
4
|
-
import type { ThemeHydrationPayload, ThemeRenderData } from '@oktis-works/theme-sdk';
|
|
5
|
-
/** Adaptador do checker do TemplateHierarchyResolver sobre o resolver único. */
|
|
6
|
-
export declare function createTemplateChecker(themesRoot: string, activeTheme: string): TemplateFileChecker;
|
|
7
|
-
/**
|
|
8
|
-
* B1 — carrega o ARQUIVO do template do tema ativo (fallback _shared → default).
|
|
9
|
-
* Retorna null quando nenhum candidato existe (rota cai no 404 do tema).
|
|
10
|
-
*/
|
|
11
|
-
export declare function loadTemplateSource(themesRoot: string, activeTheme: string, file: string): string | null;
|
|
3
|
+
import { RuntimeRouter, type ContentLookup } from '@oktis-works/theme-runtime';
|
|
4
|
+
import type { ThemeHydrationPayload, ThemeRenderData, ThemeSdkBridge } from '@oktis-works/theme-sdk';
|
|
12
5
|
export interface SiteSettings {
|
|
13
6
|
siteTitle: string;
|
|
14
7
|
siteDescription: string;
|
|
@@ -30,7 +23,6 @@ export declare function toSiteSettings(raw: Record<string, unknown>): SiteSettin
|
|
|
30
23
|
* during preview (defense in depth, preview is request-only anyway).
|
|
31
24
|
*/
|
|
32
25
|
export declare function mergePreviewSettings(saved: Record<string, unknown> | null | undefined, previewParam: string | undefined, allowedKeys?: string[]): Record<string, unknown> | null;
|
|
33
|
-
export declare const themeRenderer: ThemeRenderer;
|
|
34
26
|
/**
|
|
35
27
|
* Configurações do tema para os templates: defaults declarados em
|
|
36
28
|
* `manifest.settings` sobrescritos pelo `config` salvo na tela Temas do
|
|
@@ -75,12 +67,12 @@ export interface ContentPageRenderInput {
|
|
|
75
67
|
head: string;
|
|
76
68
|
footer: string;
|
|
77
69
|
};
|
|
70
|
+
/** Explicit request-scoped bridge supplied by the web host. */
|
|
71
|
+
themeSdk?: ThemeSdkBridge;
|
|
78
72
|
}
|
|
79
|
-
export declare function renderContentPage(input: ContentPageRenderInput): string;
|
|
80
73
|
/**
|
|
81
|
-
* Engine-aware render entry point.
|
|
82
|
-
*
|
|
83
|
-
* artifact and rendered through the compiled adapter.
|
|
74
|
+
* Engine-aware render entry point. All themes are compiled React/Solid
|
|
75
|
+
* modules and are rendered through the explicit SDK bridge.
|
|
84
76
|
*/
|
|
85
77
|
export declare function renderContentPageAsync(input: ContentPageRenderInput): Promise<string>;
|
|
86
78
|
/**
|
|
@@ -110,17 +102,8 @@ export declare function sanitizePluginHtml(value: string): string;
|
|
|
110
102
|
/** Renders serialized editor blocks with plugin-owned SSR renderers. */
|
|
111
103
|
export declare function renderPluginBlocks(blocks: unknown, catalog: ReadonlyArray<PublicBlockCatalogEntry>, pluginsRoot: string, patterns?: ReadonlyArray<PublicPatternCatalogEntry>): Promise<string | null>;
|
|
112
104
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* sai sem <link> quebrado (nada de 404 silencioso no console).
|
|
116
|
-
*/
|
|
117
|
-
export declare function resolveThemeStylesheet(themesRoot: string, activeTheme: string): string | null;
|
|
118
|
-
/** Returns all inherited legacy styles in parent-to-child order. */
|
|
119
|
-
export declare function resolveThemeStylesheets(themesRoot: string, activeTheme: string): string[];
|
|
120
|
-
/**
|
|
121
|
-
* B1 — envolve o fragmento do template num documento completo com title/meta
|
|
122
|
-
* das settings + CSS do tema + injeções de plugins via hook `theme:head`.
|
|
123
|
-
* Template que já emite documento completo passa intocado (temas headless/full-control).
|
|
105
|
+
* Wraps a theme fragment in the host document with settings, SEO metadata,
|
|
106
|
+
* compiled theme assets, and plugin head injections.
|
|
124
107
|
*/
|
|
125
108
|
export interface ThemeDocumentAssets {
|
|
126
109
|
/** Theme that owns the extra styles/scripts. */
|
|
@@ -172,7 +155,7 @@ export interface SeoMeta {
|
|
|
172
155
|
/** Robots meta directive (index,follow, noindex,nofollow, etc.) */
|
|
173
156
|
robots?: string;
|
|
174
157
|
}
|
|
175
|
-
export declare function wrapDocument(body: string, pageTitle: string, settings: SiteSettings, activeTheme: string,
|
|
158
|
+
export declare function wrapDocument(body: string, pageTitle: string, settings: SiteSettings, activeTheme: string, pluginAssets?: {
|
|
176
159
|
head: string;
|
|
177
160
|
footer: string;
|
|
178
161
|
}, seo?: SeoMeta, themeAssets?: ThemeDocumentAssets): string;
|
|
@@ -201,11 +184,6 @@ export declare function enrichItemsMedia(sql: ReturnType<typeof getConnection>,
|
|
|
201
184
|
* object. Parses defensively — invalid JSON degrades to an empty body and
|
|
202
185
|
* never breaks the render.
|
|
203
186
|
*/
|
|
204
|
-
export declare function createContentLookup(): ContentLookup;
|
|
205
|
-
export declare function createRouter(themesRoot: string, activeTheme: string): RuntimeRouter;
|
|
206
|
-
/**
|
|
207
|
-
* Registra o hook registry no Theme SDK para habilitar os filtros theme:data:*.
|
|
208
|
-
* Awaited no boot do web — fire-and-forget deixava a janela inicial sem hooks.
|
|
209
|
-
*/
|
|
210
|
-
export declare function wireThemeHooks(): Promise<void>;
|
|
187
|
+
export declare function createContentLookup(tenantId?: string): ContentLookup;
|
|
188
|
+
export declare function createRouter(themesRoot: string, activeTheme: string, tenantId: string): RuntimeRouter;
|
|
211
189
|
//# sourceMappingURL=rendering.d.ts.map
|
package/dist/rendering.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rendering.d.ts","sourceRoot":"","sources":["../src/rendering.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAItD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAEL,aAAa,
|
|
1
|
+
{"version":3,"file":"rendering.d.ts","sourceRoot":"","sources":["../src/rendering.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAItD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAEL,aAAa,EAIb,KAAK,aAAa,EACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,qBAAqB,EAAiB,eAAe,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAEpH,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,+FAA+F;IAC/F,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY,CAOzE;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,EACjD,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,WAA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,EAAE,OAAO,CAAC,CAAC,GACpC,OAAO,CAAC,IAAI,CAAC,CAcf;AA2BD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,SAAK,GAAG,aAAa,CAwJhE;AAED,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,aAAa,CAYrG"}
|
package/dist/rendering.js
CHANGED
|
@@ -1,92 +1,20 @@
|
|
|
1
1
|
// @oktis-works/web - Runtime Rendering (catch-all SSR com hierarquia de templates)
|
|
2
|
-
import {
|
|
2
|
+
import { realpathSync } from 'node:fs';
|
|
3
3
|
import { createHash } from 'node:crypto';
|
|
4
|
-
import {
|
|
4
|
+
import { relative, resolve, sep } from 'node:path';
|
|
5
5
|
import { pathToFileURL } from 'node:url';
|
|
6
6
|
import { createRequire } from 'node:module';
|
|
7
7
|
import { getConnection } from '@oktis-works/database';
|
|
8
8
|
import { normalizeLogicalValues } from '@oktis-works/validation';
|
|
9
9
|
import { getHookRegistry } from '@oktis-works/plugin-runtime';
|
|
10
10
|
import { postTypeRegistry, HOOK_POINTS } from '@oktis-works/core';
|
|
11
|
-
import {
|
|
12
|
-
import { CMS_VERSION } from '@oktis-works/validation';
|
|
13
|
-
/**
|
|
14
|
-
* B1/Unificação (FEAT-095): a cadeia de templates do projeto
|
|
15
|
-
* (tema ativo → `_shared` → `default`), o saneamento dos nomes de tema e o
|
|
16
|
-
* guard contra traversal vivem **apenas** no `@oktis-works/theme-runtime` —
|
|
17
|
-
* este app só consome a fonte única, sem reimplementação local.
|
|
18
|
-
*/
|
|
19
|
-
function projectTemplates(themesRoot, activeTheme) {
|
|
20
|
-
return createProjectTemplateResolver(themesRoot, activeTheme);
|
|
21
|
-
}
|
|
22
|
-
/** Adaptador do checker do TemplateHierarchyResolver sobre o resolver único. */
|
|
23
|
-
export function createTemplateChecker(themesRoot, activeTheme) {
|
|
24
|
-
const resolver = projectTemplates(themesRoot, activeTheme);
|
|
25
|
-
return {
|
|
26
|
-
exists(file) {
|
|
27
|
-
return resolver.exists(file);
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* B1 — carrega o ARQUIVO do template do tema ativo (fallback _shared → default).
|
|
33
|
-
* Retorna null quando nenhum candidato existe (rota cai no 404 do tema).
|
|
34
|
-
*/
|
|
35
|
-
export function loadTemplateSource(themesRoot, activeTheme, file) {
|
|
36
|
-
return projectTemplates(themesRoot, activeTheme).read(file);
|
|
37
|
-
}
|
|
38
|
-
/** Registers manifest-declared legacy components from parent to child. */
|
|
39
|
-
function registerThemeComponents(themesRoot, activeTheme) {
|
|
40
|
-
const chain = resolveProjectThemeChain(themesRoot, activeTheme);
|
|
41
|
-
themeRenderer.clearComponents();
|
|
42
|
-
for (const themeName of [...chain].reverse()) {
|
|
43
|
-
const themeDir = resolve(themesRoot, themeName);
|
|
44
|
-
const manifestPath = join(themeDir, 'theme.json');
|
|
45
|
-
if (!existsSync(manifestPath))
|
|
46
|
-
continue;
|
|
47
|
-
let manifest;
|
|
48
|
-
try {
|
|
49
|
-
manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
const components = Array.isArray(manifest['components']) ? manifest['components'] : [];
|
|
55
|
-
for (const value of components) {
|
|
56
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
57
|
-
continue;
|
|
58
|
-
const component = value;
|
|
59
|
-
const name = typeof component['name'] === 'string' ? component['name'] : '';
|
|
60
|
-
const file = typeof component['file'] === 'string' ? component['file'] : '';
|
|
61
|
-
if (!name || !file || file.includes('..') || file.includes('\\') || file.startsWith('/'))
|
|
62
|
-
continue;
|
|
63
|
-
const target = resolve(themeDir, file);
|
|
64
|
-
if (!target.startsWith(themeDir + sep) || !existsSync(target))
|
|
65
|
-
continue;
|
|
66
|
-
try {
|
|
67
|
-
const realThemeDir = realpathSync(themeDir);
|
|
68
|
-
const realTarget = realpathSync(target);
|
|
69
|
-
if (realTarget !== realThemeDir && !realTarget.startsWith(realThemeDir + sep))
|
|
70
|
-
continue;
|
|
71
|
-
themeRenderer.registerComponent({
|
|
72
|
-
name,
|
|
73
|
-
type: component['type'],
|
|
74
|
-
file: realTarget,
|
|
75
|
-
props: component['props'],
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
catch {
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
11
|
+
import { ThemeTemplateResolver, RuntimeRouter, loadThemeCatalog, findTemplateProvider, renderCompiledTheme, } from '@oktis-works/theme-runtime';
|
|
84
12
|
export function toSiteSettings(raw) {
|
|
85
13
|
return {
|
|
86
|
-
siteTitle: toText(raw['siteTitle']) || 'OkCMS',
|
|
87
|
-
siteDescription: toText(raw['siteDescription']) || '',
|
|
88
|
-
siteUrl: toText(raw['siteUrl']) || '',
|
|
89
|
-
language: toText(raw['language']) || 'pt-BR',
|
|
14
|
+
siteTitle: toText(raw['siteTitle'] ?? raw['seo.siteTitle']) || 'OkCMS',
|
|
15
|
+
siteDescription: toText(raw['siteDescription'] ?? raw['seo.siteDescription']) || '',
|
|
16
|
+
siteUrl: toText(raw['siteUrl'] ?? raw['seo.siteUrl']) || '',
|
|
17
|
+
language: toText(raw['language'] ?? raw['seo.language']) || 'pt-BR',
|
|
90
18
|
};
|
|
91
19
|
}
|
|
92
20
|
/**
|
|
@@ -146,7 +74,6 @@ function toText(value) {
|
|
|
146
74
|
return String(value);
|
|
147
75
|
return '';
|
|
148
76
|
}
|
|
149
|
-
export const themeRenderer = new ThemeRenderer();
|
|
150
77
|
/**
|
|
151
78
|
* Deep merge two objects, with source overriding target.
|
|
152
79
|
* Arrays are replaced, not merged.
|
|
@@ -280,9 +207,8 @@ function prepareContentPage(input, file) {
|
|
|
280
207
|
/** Wraps a rendered body in the document and runs the post-render hook. */
|
|
281
208
|
function finalizeContentPage(input, prepared, body, themeAssets) {
|
|
282
209
|
// Compiled artifacts carry their own versioned stylesheet list. Linking the
|
|
283
|
-
//
|
|
210
|
+
// unversioned stable path as well would defeat cache versioning and may load a
|
|
284
211
|
// stale CSS generation.
|
|
285
|
-
const stylesheet = themeAssets ? null : resolveThemeStylesheets(input.themesRoot, input.activeTheme);
|
|
286
212
|
// Build canonical URL for SEO
|
|
287
213
|
const canonicalPath = input.resolution.canonicalPath ?? '';
|
|
288
214
|
const siteUrl = input.settings['siteUrl'] || '';
|
|
@@ -295,79 +221,58 @@ function finalizeContentPage(input, prepared, body, themeAssets) {
|
|
|
295
221
|
const pageRobots = input.contentRow?.['seo_robots'] ?? undefined;
|
|
296
222
|
const pageCanonical = input.contentRow?.['seo_canonical_url'] ?? undefined;
|
|
297
223
|
const pageOgImage = input.contentRow?.['seo_og_image'] ?? undefined;
|
|
298
|
-
const configuredOgImage = toText(input.settings['ogImage']) || undefined;
|
|
299
|
-
const html = wrapDocument(body, prepared.title, input.settings, input.activeTheme,
|
|
224
|
+
const configuredOgImage = toText(input.settings['ogImage'] ?? input.settings['seo.ogImage']) || undefined;
|
|
225
|
+
const html = wrapDocument(body, prepared.title, input.settings, input.activeTheme, input.pluginAssets, {
|
|
300
226
|
canonicalUrl: pageCanonical ?? canonicalUrl,
|
|
301
227
|
pageDescription,
|
|
302
228
|
ogTitle: prepared.title,
|
|
303
229
|
ogDescription: pageDescription,
|
|
304
230
|
ogImage: pageOgImage ?? configuredOgImage,
|
|
305
|
-
ogType: input.settings['ogType'] ?? 'website',
|
|
231
|
+
ogType: (input.settings['ogType'] ?? input.settings['seo.ogType']) ?? 'website',
|
|
306
232
|
ogSiteName: input.settings.siteTitle,
|
|
307
233
|
ogLocale: input.settings.language ?? 'pt-BR',
|
|
308
|
-
twitterCard: input.settings['twitterCard'] ?? 'summary_large_image',
|
|
234
|
+
twitterCard: (input.settings['twitterCard'] ?? input.settings['seo.twitterCard']) ?? 'summary_large_image',
|
|
309
235
|
twitterTitle: prepared.title,
|
|
310
236
|
twitterDescription: pageDescription,
|
|
311
237
|
twitterImage: pageOgImage ?? configuredOgImage,
|
|
312
|
-
robots: pageRobots ?? input.settings['defaultRobots'] ?? 'index,follow',
|
|
238
|
+
robots: pageRobots ?? (input.settings['defaultRobots'] ?? input.settings['seo.defaultRobots']) ?? 'index,follow',
|
|
313
239
|
}, themeAssets);
|
|
314
240
|
return prepared.registry.applyFilters(HOOK_POINTS.THEME_AFTER_RENDER, html, prepared.hookContext);
|
|
315
241
|
}
|
|
316
|
-
export function renderContentPage(input) {
|
|
317
|
-
const file = input.resolution.template ?? 'index.astro';
|
|
318
|
-
const template = loadTemplateSource(input.themesRoot, input.activeTheme, file);
|
|
319
|
-
if (!template) {
|
|
320
|
-
return renderFallbackPage(input, input.pluginAssets);
|
|
321
|
-
}
|
|
322
|
-
const prepared = prepareContentPage(input, file);
|
|
323
|
-
registerThemeComponents(input.themesRoot, input.activeTheme);
|
|
324
|
-
const body = themeRenderer.wrapWithThemeScope(themeRenderer.renderString(template, prepared.context, { ...prepared.themeRecord }), input.activeTheme);
|
|
325
|
-
return finalizeContentPage(input, prepared, body);
|
|
326
|
-
}
|
|
327
242
|
/**
|
|
328
|
-
* Engine-aware render entry point.
|
|
329
|
-
*
|
|
330
|
-
* artifact and rendered through the compiled adapter.
|
|
243
|
+
* Engine-aware render entry point. All themes are compiled React/Solid
|
|
244
|
+
* modules and are rendered through the explicit SDK bridge.
|
|
331
245
|
*/
|
|
332
246
|
export async function renderContentPageAsync(input) {
|
|
333
247
|
const catalog = loadThemeCatalog(input.themesRoot, input.activeTheme);
|
|
334
248
|
const active = catalog.entries[0] ?? null;
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
return renderContentPage(input);
|
|
338
|
-
}
|
|
249
|
+
if (!active)
|
|
250
|
+
throw new Error(`Active theme "${input.activeTheme}" was not found`);
|
|
339
251
|
if (active.problems.length > 0) {
|
|
340
|
-
throw new Error(`
|
|
252
|
+
throw new Error(`Active theme "${input.activeTheme}" is invalid: ${active.problems.join('; ')}`);
|
|
341
253
|
}
|
|
342
|
-
const
|
|
343
|
-
const requestedKey = templateKeyFromFile(file);
|
|
254
|
+
const requestedKey = input.resolution.template ?? 'index';
|
|
344
255
|
const provider = findTemplateProvider(catalog, requestedKey, active.engine) ??
|
|
345
256
|
findTemplateProvider(catalog, '404', active.engine);
|
|
346
|
-
if (!provider?.build)
|
|
347
|
-
|
|
348
|
-
}
|
|
257
|
+
if (!provider?.build)
|
|
258
|
+
throw new Error(`No compiled theme provides render key "${requestedKey}"`);
|
|
349
259
|
if (provider.build.engine !== active.engine) {
|
|
350
260
|
throw new Error(`Theme "${provider.name}" engine mismatch: theme.json says ${active.engine}, artifact says ${provider.build.engine}.`);
|
|
351
261
|
}
|
|
352
262
|
const templateKey = provider.build.templates.includes(requestedKey) ? requestedKey : '404';
|
|
353
|
-
const prepared = prepareContentPage(input,
|
|
263
|
+
const prepared = prepareContentPage(input, requestedKey);
|
|
354
264
|
const styleAssets = catalog.entries
|
|
355
265
|
.filter((entry) => entry.problems.length === 0)
|
|
356
|
-
.flatMap((entry) =>
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
return existsSync(join(entry.dir, 'dist', 'theme.css'))
|
|
361
|
-
? [{ themeName: entry.name, styles: ['dist/theme.css'] }]
|
|
362
|
-
: [];
|
|
363
|
-
});
|
|
266
|
+
.flatMap((entry) => entry.build
|
|
267
|
+
? [{ themeName: entry.name, styles: entry.build.styles, buildId: entry.build.buildId }]
|
|
268
|
+
: []);
|
|
364
269
|
const output = await renderCompiledTheme({
|
|
365
270
|
themeDir: provider.dir,
|
|
366
271
|
build: provider.build,
|
|
367
272
|
templateKey,
|
|
368
273
|
data: prepared.context,
|
|
369
|
-
//
|
|
370
|
-
//
|
|
274
|
+
// The bridge and component props must see the same post-hook public record,
|
|
275
|
+
// not the pre-hook storage row.
|
|
371
276
|
record: {
|
|
372
277
|
...prepared.themeRecord,
|
|
373
278
|
body: {
|
|
@@ -386,9 +291,10 @@ export async function renderContentPageAsync(input) {
|
|
|
386
291
|
templateKey,
|
|
387
292
|
buildId: provider.build.buildId,
|
|
388
293
|
},
|
|
294
|
+
sdk: input.themeSdk,
|
|
389
295
|
automaticAssets: provider.build.hydration === 'islands' || styleAssets.some((asset) => asset.styles.length > 0),
|
|
390
296
|
});
|
|
391
|
-
const body =
|
|
297
|
+
const body = output.html;
|
|
392
298
|
const outputScripts = output.scripts ?? [];
|
|
393
299
|
const scripts = outputScripts.length > 0
|
|
394
300
|
? outputScripts
|
|
@@ -558,20 +464,6 @@ export async function renderPluginBlocks(blocks, catalog, pluginsRoot, patterns
|
|
|
558
464
|
}
|
|
559
465
|
return output.join('\n');
|
|
560
466
|
}
|
|
561
|
-
/**
|
|
562
|
-
* Primeiro fornecedor real de `dist/theme.css` na cadeia (tema ativo →
|
|
563
|
-
* _shared → default). `null` quando ninguém compilou estilos — o documento
|
|
564
|
-
* sai sem <link> quebrado (nada de 404 silencioso no console).
|
|
565
|
-
*/
|
|
566
|
-
export function resolveThemeStylesheet(themesRoot, activeTheme) {
|
|
567
|
-
return resolveThemeStylesheets(themesRoot, activeTheme)[0] ?? null;
|
|
568
|
-
}
|
|
569
|
-
/** Returns all inherited legacy styles in parent-to-child order. */
|
|
570
|
-
export function resolveThemeStylesheets(themesRoot, activeTheme) {
|
|
571
|
-
return [...resolveProjectThemeChain(themesRoot, activeTheme)]
|
|
572
|
-
.reverse()
|
|
573
|
-
.filter((theme) => existsSync(join(themesRoot, theme, 'dist', 'theme.css')));
|
|
574
|
-
}
|
|
575
467
|
/** Escapes JSON for an application/json script (never executable HTML). */
|
|
576
468
|
export function serializeThemeHydration(payload) {
|
|
577
469
|
return JSON.stringify(payload)
|
|
@@ -579,20 +471,12 @@ export function serializeThemeHydration(payload) {
|
|
|
579
471
|
.replace(/>/g, '\\u003e')
|
|
580
472
|
.replace(/&/g, '\\u0026');
|
|
581
473
|
}
|
|
582
|
-
export function wrapDocument(body, pageTitle, settings, activeTheme,
|
|
474
|
+
export function wrapDocument(body, pageTitle, settings, activeTheme, pluginAssets, seo, themeAssets) {
|
|
583
475
|
if (body.includes('<html') || body.includes('<!DOCTYPE')) {
|
|
584
476
|
return body;
|
|
585
477
|
}
|
|
586
478
|
const title = pageTitle && pageTitle !== settings.siteTitle ? `${pageTitle} | ${settings.siteTitle}` : settings.siteTitle;
|
|
587
479
|
const lang = escapeHtml(settings.language || 'pt-BR');
|
|
588
|
-
const stylesheetNames = stylesheetTheme === null
|
|
589
|
-
? []
|
|
590
|
-
: Array.isArray(stylesheetTheme)
|
|
591
|
-
? stylesheetTheme
|
|
592
|
-
: [stylesheetTheme];
|
|
593
|
-
const stylesheet = stylesheetNames
|
|
594
|
-
.map((themeName) => ` <link rel="stylesheet" href="/themes/${escapeHtml(themeName)}/dist/theme.css" data-theme-style="${escapeHtml(themeName)}" />`)
|
|
595
|
-
.join('\n');
|
|
596
480
|
// Compiled themes may emit extra styles/scripts/head from their artifact.
|
|
597
481
|
const styleAssets = themeAssets
|
|
598
482
|
? themeAssets.styleAssets ?? [{ themeName: themeAssets.themeName, styles: themeAssets.styles ?? [], buildId: themeAssets.buildId }]
|
|
@@ -610,7 +494,6 @@ export function wrapDocument(body, pageTitle, settings, activeTheme, stylesheetT
|
|
|
610
494
|
.filter((style) => !(style === 'dist/theme.css' && asset.buildId))
|
|
611
495
|
.map((style) => ` <link rel="stylesheet" href="/themes/${escapeHtml(asset.themeName)}/${escapeHtml(style)}${asset.buildId ? `?v=${encodeURIComponent(asset.buildId)}` : ''}" data-theme-style="${escapeHtml(asset.themeName)}" />`))
|
|
612
496
|
.join('\n');
|
|
613
|
-
const legacyStyles = stylesheet ? `${stylesheet}\n` : '';
|
|
614
497
|
const compiledStyles = extraStyles ? `${extraStyles}\n` : '';
|
|
615
498
|
const themeHead = themeAssets?.head ? `${themeAssets.head}\n` : '';
|
|
616
499
|
const themeScripts = themeAssets
|
|
@@ -621,6 +504,7 @@ export function wrapDocument(body, pageTitle, settings, activeTheme, stylesheetT
|
|
|
621
504
|
const hydrationScript = themeAssets?.hydration
|
|
622
505
|
? `<script type="application/json" id="okcms-theme-hydration">${serializeThemeHydration(themeAssets.hydration)}</script>`
|
|
623
506
|
: '';
|
|
507
|
+
const renderedBody = hydrationScript ? `<div id="root">${body}</div>` : body;
|
|
624
508
|
// WP6: ponto de extensão theme:head — plugins injetam tags no <head>
|
|
625
509
|
const registry = getHookRegistry();
|
|
626
510
|
const headInjections = registry.applyFilters(HOOK_POINTS.THEME_HEAD, '', { settings, activeTheme });
|
|
@@ -678,15 +562,14 @@ export function wrapDocument(body, pageTitle, settings, activeTheme, stylesheetT
|
|
|
678
562
|
<head>
|
|
679
563
|
<meta charset="UTF-8">
|
|
680
564
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
681
|
-
<meta name="generator" content="OkCMS ${CMS_VERSION}">
|
|
682
565
|
<title>${escapeHtml(title)}</title>
|
|
683
566
|
<meta name="description" content="${description}">
|
|
684
567
|
${robotsTag}
|
|
685
568
|
${canonicalTag}
|
|
686
569
|
${ogTags.join('\n')}
|
|
687
570
|
${twitterTags.join('\n')}
|
|
688
|
-
${seoMetaTags}${
|
|
689
|
-
${
|
|
571
|
+
${seoMetaTags}${compiledStyles}${themeHead}${headInjections}${assetHead}</head> <body>
|
|
572
|
+
${renderedBody}${assetFooter}${hydrationScript ? `\n${hydrationScript}` : ''}${themeScripts ? `\n${themeScripts}` : ''}
|
|
690
573
|
</body>
|
|
691
574
|
</html>`;
|
|
692
575
|
}
|
|
@@ -725,91 +608,6 @@ function sanitizePublicValue(value) {
|
|
|
725
608
|
function publicContentRecord(row) {
|
|
726
609
|
return sanitizePublicValue(row);
|
|
727
610
|
}
|
|
728
|
-
/** Tema sem template para a rota: HTML mínimo com os dados reais (nunca stub). */
|
|
729
|
-
function renderFallbackPage(input, pluginAssets) {
|
|
730
|
-
const title = toText((input.contentRow ?? {})['title']) || input.settings.siteTitle;
|
|
731
|
-
const lang = escapeHtml(input.settings.language || 'pt-BR');
|
|
732
|
-
// SEO for fallback page
|
|
733
|
-
const canonicalPath = input.resolution.canonicalPath ?? '';
|
|
734
|
-
const siteUrl = input.settings['siteUrl'] || '';
|
|
735
|
-
const canonicalUrl = canonicalPath && siteUrl ? new URL(canonicalPath, siteUrl).toString() : '';
|
|
736
|
-
const pageDescription = (input.contentRow
|
|
737
|
-
? input.contentRow['seo_description'] ?? input.contentRow['excerpt']
|
|
738
|
-
: undefined) ?? input.settings.siteDescription;
|
|
739
|
-
const ogTitle = title;
|
|
740
|
-
const ogDescription = pageDescription;
|
|
741
|
-
const ogImage = '';
|
|
742
|
-
const ogType = 'website';
|
|
743
|
-
const ogSiteName = input.settings.siteTitle;
|
|
744
|
-
const ogLocale = input.settings.language ?? 'pt-BR';
|
|
745
|
-
const twitterCard = 'summary_large_image';
|
|
746
|
-
const twitterTitle = ogTitle;
|
|
747
|
-
const twitterDescription = ogDescription;
|
|
748
|
-
const twitterImage = ogImage;
|
|
749
|
-
const robotsDirective = input.settings['defaultRobots'] ?? 'index,follow';
|
|
750
|
-
// WP6: ponto de extensão theme:head — plugins injetam tags no <head>
|
|
751
|
-
const registry = getHookRegistry();
|
|
752
|
-
const headInjections = registry.applyFilters(HOOK_POINTS.THEME_HEAD, '', { settings: input.settings, activeTheme: input.activeTheme });
|
|
753
|
-
const seoMetaTags = String(registry.applyFilters('okcms.seo.meta.tags', '', { settings: input.settings, activeTheme: input.activeTheme, seo: undefined }));
|
|
754
|
-
const assetHead = pluginAssets?.head ? `${pluginAssets.head}\n` : '';
|
|
755
|
-
const assetFooter = pluginAssets?.footer ? `\n${pluginAssets.footer}` : '';
|
|
756
|
-
const canonicalTag = canonicalUrl ? ` <link rel="canonical" href="${escapeHtml(canonicalUrl)}">\n` : '';
|
|
757
|
-
const ogTags = [];
|
|
758
|
-
if (ogTitle)
|
|
759
|
-
ogTags.push(` <meta property="og:title" content="${escapeHtml(ogTitle)}">`);
|
|
760
|
-
if (ogDescription)
|
|
761
|
-
ogTags.push(` <meta property="og:description" content="${escapeHtml(ogDescription)}">`);
|
|
762
|
-
if (ogImage)
|
|
763
|
-
ogTags.push(` <meta property="og:image" content="${escapeHtml(ogImage)}">`);
|
|
764
|
-
ogTags.push(` <meta property="og:type" content="${escapeHtml(ogType)}">`);
|
|
765
|
-
if (ogSiteName)
|
|
766
|
-
ogTags.push(` <meta property="og:site_name" content="${escapeHtml(ogSiteName)}">`);
|
|
767
|
-
if (canonicalUrl)
|
|
768
|
-
ogTags.push(` <meta property="og:url" content="${escapeHtml(canonicalUrl)}">`);
|
|
769
|
-
ogTags.push(` <meta property="og:locale" content="${escapeHtml(ogLocale)}">`);
|
|
770
|
-
const twitterTags = [];
|
|
771
|
-
twitterTags.push(` <meta name="twitter:card" content="${escapeHtml(twitterCard)}">`);
|
|
772
|
-
if (twitterTitle)
|
|
773
|
-
twitterTags.push(` <meta name="twitter:title" content="${escapeHtml(twitterTitle)}">`);
|
|
774
|
-
if (twitterDescription)
|
|
775
|
-
twitterTags.push(` <meta name="twitter:description" content="${escapeHtml(twitterDescription)}">`);
|
|
776
|
-
if (twitterImage)
|
|
777
|
-
twitterTags.push(` <meta name="twitter:image" content="${escapeHtml(twitterImage)}">`);
|
|
778
|
-
const robotsTag = ` <meta name="robots" content="${escapeHtml(robotsDirective)}">`;
|
|
779
|
-
return `<!DOCTYPE html>
|
|
780
|
-
<html lang="${lang}">
|
|
781
|
-
<head>
|
|
782
|
-
<meta charset="UTF-8">
|
|
783
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
784
|
-
<title>${escapeHtml(title)} | ${escapeHtml(input.settings.siteTitle)}</title>
|
|
785
|
-
<meta name="description" content="${escapeHtml(pageDescription)}">
|
|
786
|
-
${robotsTag}
|
|
787
|
-
${canonicalTag}
|
|
788
|
-
${ogTags.join('\n')}
|
|
789
|
-
${twitterTags.join('\n')}
|
|
790
|
-
${seoMetaTags}<style>
|
|
791
|
-
body { font-family: system-ui, sans-serif; margin: 0; color: #111; }
|
|
792
|
-
main { max-width: 46rem; margin: 0 auto; padding: 3rem 1.5rem; }
|
|
793
|
-
.fallback__hint { color: #555; line-height: 1.5; }
|
|
794
|
-
details { margin-top: 2rem; }
|
|
795
|
-
summary { cursor: pointer; color: #555; }
|
|
796
|
-
pre { background: #f5f5f5; border: 1px solid #e3e3e3; border-radius: 6px; padding: 1rem; overflow: auto; font-size: 0.85rem; }
|
|
797
|
-
</style>
|
|
798
|
-
${headInjections}${assetHead}</head>
|
|
799
|
-
<body>
|
|
800
|
-
<main data-theme="${escapeHtml(input.activeTheme)}">
|
|
801
|
-
<article>
|
|
802
|
-
<h1>${escapeHtml(title)}</h1>
|
|
803
|
-
<p class="fallback__hint">Este tema não possui template para esta rota — os dados reais do conteúdo estão abaixo.</p>
|
|
804
|
-
<details>
|
|
805
|
-
<summary>Dados (JSON)</summary>
|
|
806
|
-
<pre>${escapeHtml(JSON.stringify(input.data, null, 2))}</pre>
|
|
807
|
-
</details>
|
|
808
|
-
</article>
|
|
809
|
-
</main>${assetFooter}
|
|
810
|
-
</body>
|
|
811
|
-
</html>`;
|
|
812
|
-
}
|
|
813
611
|
export function escapeHtml(value) {
|
|
814
612
|
return value.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
|
815
613
|
}
|
|
@@ -973,11 +771,11 @@ async function attachTerms(sql, contentId, data) {
|
|
|
973
771
|
* object. Parses defensively — invalid JSON degrades to an empty body and
|
|
974
772
|
* never breaks the render.
|
|
975
773
|
*/
|
|
976
|
-
export function createContentLookup() {
|
|
774
|
+
export function createContentLookup(tenantId = '') {
|
|
977
775
|
return {
|
|
978
776
|
async findByPath(path) {
|
|
979
777
|
const sql = getConnection();
|
|
980
|
-
const result = await sql.unsafe("SELECT * FROM content WHERE slug = $1 AND status = 'PUBLISHED' LIMIT 1", [path]);
|
|
778
|
+
const result = await sql.unsafe("SELECT * FROM content WHERE slug = $1 AND tenant_id = $2 AND status = 'PUBLISHED' LIMIT 1", [path, tenantId]);
|
|
981
779
|
const row = result[0];
|
|
982
780
|
if (!row)
|
|
983
781
|
return null;
|
|
@@ -1000,7 +798,7 @@ export function createContentLookup() {
|
|
|
1000
798
|
},
|
|
1001
799
|
async findById(id) {
|
|
1002
800
|
const sql = getConnection();
|
|
1003
|
-
const result = await sql.unsafe("SELECT * FROM content WHERE id = $1 AND status = 'PUBLISHED' LIMIT 1", [id]);
|
|
801
|
+
const result = await sql.unsafe("SELECT * FROM content WHERE id = $1 AND tenant_id = $2 AND status = 'PUBLISHED' LIMIT 1", [id, tenantId]);
|
|
1004
802
|
const row = result[0];
|
|
1005
803
|
if (!row)
|
|
1006
804
|
return null;
|
|
@@ -1022,7 +820,10 @@ export function createContentLookup() {
|
|
|
1022
820
|
},
|
|
1023
821
|
async getSetting(key) {
|
|
1024
822
|
const sql = getConnection();
|
|
1025
|
-
const result = await sql.unsafe(`SELECT value FROM settings
|
|
823
|
+
const result = await sql.unsafe(`SELECT value FROM settings
|
|
824
|
+
WHERE key = $1 AND (tenant_id IS NULL OR tenant_id = $2)
|
|
825
|
+
ORDER BY CASE WHEN tenant_id = $2 THEN 0 ELSE 1 END
|
|
826
|
+
LIMIT 1`, [key, tenantId]);
|
|
1026
827
|
const row = result[0];
|
|
1027
828
|
if (!row)
|
|
1028
829
|
return null;
|
|
@@ -1042,8 +843,8 @@ export function createContentLookup() {
|
|
|
1042
843
|
FROM content
|
|
1043
844
|
WHERE type = 'page'
|
|
1044
845
|
AND status = 'PUBLISHED'
|
|
1045
|
-
AND metadata
|
|
1046
|
-
AND tenant_id =
|
|
846
|
+
AND metadata->>'hub_type' IS NOT NULL
|
|
847
|
+
AND tenant_id = $1`, [tenantId]);
|
|
1047
848
|
return result
|
|
1048
849
|
.filter((r) => r.hub_type && r.slug)
|
|
1049
850
|
.map((r) => ({ type: r.hub_type, base: r.slug, hubPageId: r.id }));
|
|
@@ -1051,7 +852,7 @@ export function createContentLookup() {
|
|
|
1051
852
|
// NOVO: buscar pai direto (para walk-up validation)
|
|
1052
853
|
async findParent(parentId) {
|
|
1053
854
|
const sql = getConnection();
|
|
1054
|
-
const result = await sql.unsafe(`SELECT id, slug, type FROM content WHERE id = $1`, [parentId]);
|
|
855
|
+
const result = await sql.unsafe(`SELECT id, slug, type FROM content WHERE id = $1 AND tenant_id = $2`, [parentId, tenantId]);
|
|
1055
856
|
const row = result[0];
|
|
1056
857
|
if (!row)
|
|
1057
858
|
return null;
|
|
@@ -1066,19 +867,19 @@ export function createContentLookup() {
|
|
|
1066
867
|
const sql = getConnection();
|
|
1067
868
|
// Exact match
|
|
1068
869
|
const exactResult = await sql.unsafe(`SELECT target_path, redirect_type FROM url_redirects
|
|
1069
|
-
WHERE tenant_id =
|
|
870
|
+
WHERE tenant_id = $2
|
|
1070
871
|
AND source_path = $1
|
|
1071
872
|
AND is_prefix = false
|
|
1072
|
-
ORDER BY created_at DESC LIMIT 1`, [sourcePath]);
|
|
873
|
+
ORDER BY created_at DESC LIMIT 1`, [sourcePath, tenantId]);
|
|
1073
874
|
const exactRow = exactResult[0];
|
|
1074
875
|
if (exactRow) {
|
|
1075
876
|
return { targetPath: String(exactRow['target_path']), redirectType: Number(exactRow['redirect_type']) };
|
|
1076
877
|
}
|
|
1077
878
|
// Prefix match: find longest matching prefix (source_path ends with *)
|
|
1078
879
|
const prefixResult = await sql.unsafe(`SELECT source_path, target_path, redirect_type FROM url_redirects
|
|
1079
|
-
WHERE tenant_id =
|
|
880
|
+
WHERE tenant_id = $1
|
|
1080
881
|
AND is_prefix = true
|
|
1081
|
-
ORDER BY length(source_path) DESC
|
|
882
|
+
ORDER BY length(source_path) DESC`, [tenantId]);
|
|
1082
883
|
for (const row of prefixResult) {
|
|
1083
884
|
const source = String(row['source_path']);
|
|
1084
885
|
const prefix = source.replace(/\*$/, ''); // remove trailing *
|
|
@@ -1094,21 +895,16 @@ export function createContentLookup() {
|
|
|
1094
895
|
},
|
|
1095
896
|
};
|
|
1096
897
|
}
|
|
1097
|
-
export function createRouter(themesRoot, activeTheme) {
|
|
1098
|
-
const
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
const sdk = await import('@oktis-works/theme-sdk');
|
|
1107
|
-
sdk.setThemeHooks({
|
|
1108
|
-
applyFilters: (filter, value, ...args) => getHookRegistry().applyFilters(filter, value, ...args),
|
|
1109
|
-
applyFiltersAsync: (filter, value, ...args) => getHookRegistry().applyFiltersAsync(filter, value, ...args),
|
|
898
|
+
export function createRouter(themesRoot, activeTheme, tenantId) {
|
|
899
|
+
const catalog = loadThemeCatalog(themesRoot, activeTheme);
|
|
900
|
+
const active = catalog.entries[0];
|
|
901
|
+
if (!active)
|
|
902
|
+
throw new Error(`Active theme "${activeTheme}" was not found`);
|
|
903
|
+
const resolver = new ThemeTemplateResolver({
|
|
904
|
+
has: (key) => catalog.entries.some((entry) => entry.engine === active.engine &&
|
|
905
|
+
entry.problems.length === 0 &&
|
|
906
|
+
entry.build?.templates.includes(key)),
|
|
1110
907
|
});
|
|
1111
|
-
|
|
1112
|
-
void HOOK_POINTS;
|
|
908
|
+
return new RuntimeRouter(createContentLookup(tenantId), resolver);
|
|
1113
909
|
}
|
|
1114
910
|
//# sourceMappingURL=rendering.js.map
|