@dealsystem/site 0.0.0-stage → 0.2.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/README.md +145 -2
- package/agent-files/claude/skills/angebote-einbauen/SKILL.md +30 -0
- package/agent-files/claude/skills/bild-einbauen/SKILL.md +43 -0
- package/agent-files/claude/skills/domain-verbinden/SKILL.md +23 -0
- package/agent-files/claude/skills/extern-einbinden/SKILL.md +37 -0
- package/agent-files/claude/skills/formular-anbinden/SKILL.md +34 -0
- package/agent-files/claude/skills/funnel-mehrstufig/BewertungFunnel.svelte +220 -0
- package/agent-files/claude/skills/funnel-mehrstufig/SKILL.md +101 -0
- package/agent-files/claude/skills/neue-seite/SKILL.md +47 -0
- package/agent-files/claude/skills/prueffehler-beheben/SKILL.md +31 -0
- package/agent-files/claude/skills/termin-buchung/SKILL.md +51 -0
- package/agent-files/claude/skills/veroeffentlichen/SKILL.md +32 -0
- package/agent-files/cursor/rules/dealsystem.mdc +7 -0
- package/agent-files/manifest.json +93 -0
- package/contract/README.md +41 -0
- package/contract/ds-content.v1.json +2355 -0
- package/contract/external-presets.v1.json +65 -0
- package/contract/funnel-code-config.md +87 -0
- package/contract/site-api.v1.json +3916 -0
- package/dist/client/altcha-workers.d.ts +10 -0
- package/dist/client/attribution.d.ts +119 -0
- package/dist/client/attribution.js +341 -0
- package/dist/client/bookingClient.svelte.d.ts +166 -0
- package/dist/client/bookingClient.svelte.js +369 -0
- package/dist/client/bookingTime.d.ts +46 -0
- package/dist/client/bookingTime.js +109 -0
- package/dist/client/captcha.d.ts +26 -0
- package/dist/client/captcha.js +71 -0
- package/dist/client/captchaSession.d.ts +21 -0
- package/dist/client/captchaSession.js +105 -0
- package/dist/client/collections.d.ts +34 -0
- package/dist/client/collections.js +40 -0
- package/dist/client/externalScript.d.ts +20 -0
- package/dist/client/externalScript.js +36 -0
- package/dist/client/funnelState.svelte.d.ts +47 -0
- package/dist/client/funnelState.svelte.js +81 -0
- package/dist/client/leadClient.svelte.d.ts +131 -0
- package/dist/client/leadClient.svelte.js +250 -0
- package/dist/client/pageview.d.ts +7 -0
- package/dist/client/pageview.js +44 -0
- package/dist/client/siteApi.d.ts +211 -0
- package/dist/client/siteApi.js +320 -0
- package/dist/client/tracking.d.ts +18 -0
- package/dist/client/tracking.js +93 -0
- package/dist/client/validation.d.ts +10 -0
- package/dist/client/validation.js +66 -0
- package/dist/components/Booker.svelte +729 -0
- package/dist/components/Booker.svelte.d.ts +42 -0
- package/dist/components/CollectionList.svelte +122 -0
- package/dist/components/CollectionList.svelte.d.ts +65 -0
- package/dist/components/ConsentGate.svelte +68 -0
- package/dist/components/ConsentGate.svelte.d.ts +44 -0
- package/dist/components/CookieBanner.svelte +303 -0
- package/dist/components/CookieBanner.svelte.d.ts +29 -0
- package/dist/components/Datenschutz.svelte +84 -0
- package/dist/components/Datenschutz.svelte.d.ts +26 -0
- package/dist/components/Embed.svelte +263 -0
- package/dist/components/Embed.svelte.d.ts +41 -0
- package/dist/components/ExternalScript.svelte +94 -0
- package/dist/components/ExternalScript.svelte.d.ts +41 -0
- package/dist/components/Impressum.svelte +59 -0
- package/dist/components/Impressum.svelte.d.ts +25 -0
- package/dist/components/LeadForm.svelte +475 -0
- package/dist/components/LeadForm.svelte.d.ts +35 -0
- package/dist/components/LeadHoneypot.svelte +43 -0
- package/dist/components/LeadHoneypot.svelte.d.ts +18 -0
- package/dist/components/Link.svelte +48 -0
- package/dist/components/Link.svelte.d.ts +30 -0
- package/dist/components/MapEmbed.svelte +154 -0
- package/dist/components/MapEmbed.svelte.d.ts +28 -0
- package/dist/components/MediaImage.svelte +218 -0
- package/dist/components/MediaImage.svelte.d.ts +128 -0
- package/dist/components/MediaVideo.svelte +103 -0
- package/dist/components/MediaVideo.svelte.d.ts +20 -0
- package/dist/components/RichText.svelte +105 -0
- package/dist/components/RichText.svelte.d.ts +55 -0
- package/dist/components/Seo.svelte +89 -0
- package/dist/components/Seo.svelte.d.ts +45 -0
- package/dist/components/SiteFooterLegal.svelte +75 -0
- package/dist/components/SiteFooterLegal.svelte.d.ts +22 -0
- package/dist/components/SiteHead.svelte +79 -0
- package/dist/components/SiteHead.svelte.d.ts +32 -0
- package/dist/components/Text.svelte +100 -0
- package/dist/components/Text.svelte.d.ts +55 -0
- package/dist/components/Tracking.svelte +30 -0
- package/dist/components/Tracking.svelte.d.ts +14 -0
- package/dist/components/Zeitfenster.svelte +92 -0
- package/dist/components/Zeitfenster.svelte.d.ts +34 -0
- package/dist/components/legal.d.ts +12 -0
- package/dist/components/legal.js +27 -0
- package/dist/config/index.d.ts +121 -0
- package/dist/config/index.js +602 -0
- package/dist/config/static/index.d.ts +3 -0
- package/dist/config/static/index.js +5 -0
- package/dist/config/static/lines.d.ts +9 -0
- package/dist/config/static/lines.js +22 -0
- package/dist/config/static/literal.d.ts +45 -0
- package/dist/config/static/literal.js +175 -0
- package/dist/config/static/siteConfig.d.ts +39 -0
- package/dist/config/static/siteConfig.js +150 -0
- package/dist/consent/consent.svelte.d.ts +91 -0
- package/dist/consent/consent.svelte.js +221 -0
- package/dist/content/index.d.ts +123 -0
- package/dist/content/index.js +247 -0
- package/dist/contentBlock.d.ts +45 -0
- package/dist/contentBlock.js +78 -0
- package/dist/csp/index.d.ts +27 -0
- package/dist/csp/index.js +74 -0
- package/dist/external/csp.d.ts +25 -0
- package/dist/external/csp.js +104 -0
- package/dist/external/hosts.d.ts +30 -0
- package/dist/external/hosts.js +128 -0
- package/dist/external/presets.d.ts +54 -0
- package/dist/external/presets.js +212 -0
- package/dist/external/resolve.d.ts +39 -0
- package/dist/external/resolve.js +254 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +32 -0
- package/dist/internal/consentNeed.d.ts +21 -0
- package/dist/internal/consentNeed.js +50 -0
- package/dist/internal/dealsystem-legal-imprint.d.ts +2 -0
- package/dist/internal/dealsystem-legal-imprint.js +5 -0
- package/dist/internal/dealsystem-legal-privacy.d.ts +2 -0
- package/dist/internal/dealsystem-legal-privacy.js +5 -0
- package/dist/internal/dealsystem-site-data.d.ts +3 -0
- package/dist/internal/dealsystem-site-data.js +2 -0
- package/dist/internal/imprint.d.ts +4 -0
- package/dist/internal/imprint.js +10 -0
- package/dist/internal/mediaImage.d.ts +15 -0
- package/dist/internal/mediaImage.js +22 -0
- package/dist/internal/privacy.d.ts +4 -0
- package/dist/internal/privacy.js +10 -0
- package/dist/internal/providers.d.ts +9 -0
- package/dist/internal/providers.js +44 -0
- package/dist/internal/reload.d.ts +2 -0
- package/dist/internal/reload.js +5 -0
- package/dist/internal/seo.d.ts +41 -0
- package/dist/internal/seo.js +79 -0
- package/dist/internal/siteData.d.ts +7 -0
- package/dist/internal/siteData.js +39 -0
- package/dist/internal/usage.d.ts +7 -0
- package/dist/internal/usage.js +13 -0
- package/dist/keys.d.ts +20 -0
- package/dist/keys.js +58 -0
- package/dist/leadmagnet.d.ts +16 -0
- package/dist/leadmagnet.js +28 -0
- package/dist/paths.d.ts +8 -0
- package/dist/paths.js +9 -0
- package/dist/richtext/escape.d.ts +4 -0
- package/dist/richtext/escape.js +18 -0
- package/dist/richtext/server.d.ts +16 -0
- package/dist/richtext/server.js +123 -0
- package/dist/schedule.d.ts +23 -0
- package/dist/schedule.js +67 -0
- package/dist/slots.d.ts +9 -0
- package/dist/slots.js +38 -0
- package/dist/snapshot.d.ts +14 -0
- package/dist/snapshot.js +214 -0
- package/dist/types.d.ts +550 -0
- package/dist/types.js +4 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/dist/vite/index.d.ts +85 -0
- package/dist/vite/index.js +641 -0
- package/dist/vite/scan.d.ts +47 -0
- package/dist/vite/scan.js +355 -0
- package/dist/vite/zeitfenster.d.ts +18 -0
- package/dist/vite/zeitfenster.js +76 -0
- package/docs/ablauf.md +167 -0
- package/docs/agents-block.md +100 -0
- package/docs/befehle.md +103 -0
- package/docs/extern.md +143 -0
- package/docs/gestaltung.md +139 -0
- package/docs/inhalte.md +224 -0
- package/docs/komponenten.md +1273 -0
- package/docs/konfiguration.md +310 -0
- package/docs/llms.txt +19 -0
- package/docs/rechtstexte.md +84 -0
- package/docs/regeln.md +108 -0
- package/docs/seo.md +55 -0
- package/docs/termine.md +73 -0
- package/package.json +115 -5
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
// Vite-Plugin von @dealsystem/site. Es
|
|
2
|
+
// - bettet die öffentlichen Daten der Seite ein (Texte aus dem CRM,
|
|
3
|
+
// Firmendaten, Formulare, Zugang zur Site-API),
|
|
4
|
+
// - sammelt die Content-Slots aus dem Quelltext,
|
|
5
|
+
// - schreibt das Manifest, das der Build ans CRM meldet,
|
|
6
|
+
// - legt `manifest.webmanifest` an, wenn im CRM ein Favicon hochgeladen ist,
|
|
7
|
+
// - beantwortet in der Entwicklung die Site-API aus der lokalen Kopie.
|
|
8
|
+
import { existsSync } from 'node:fs';
|
|
9
|
+
import { mkdir, readdir, readFile, writeFile } from 'node:fs/promises';
|
|
10
|
+
import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
11
|
+
import { validateSiteConfig } from '../config/index.js';
|
|
12
|
+
import { resolveExternal } from '../external/resolve.js';
|
|
13
|
+
import { normalizeLeadmagnet } from '../leadmagnet.js';
|
|
14
|
+
import { readSnapshot } from '../content/index.js';
|
|
15
|
+
import { CONTENT_FILE_ENV, LOCAL_CONTENT_FILE, LOCAL_MANIFEST_FILE, MANIFEST_FILE_ENV } from '../paths.js';
|
|
16
|
+
import { defaultRichtextToHtml, sanitizeRichtextHtml } from '../richtext/server.js';
|
|
17
|
+
import { resolveTextSlot } from '../slots.js';
|
|
18
|
+
import { WEB_MANIFEST_PATH, webManifest } from '../internal/seo.js';
|
|
19
|
+
import { SDK_VERSION } from '../version.js';
|
|
20
|
+
import { CONTENT_BLOCK_VERSION, CONTENT_PATCH_LIMITS } from '../contentBlock.js';
|
|
21
|
+
import { mergeSlots, routeOfFile, scanSlots } from './scan.js';
|
|
22
|
+
import { scheduleFrom } from '../schedule.js';
|
|
23
|
+
import { scanZeitfenster } from './zeitfenster.js';
|
|
24
|
+
export { scanSlots, mergeSlots, SlotScanError } from './scan.js';
|
|
25
|
+
export { scanZeitfenster } from './zeitfenster.js';
|
|
26
|
+
export { parseZeitpunkt, scheduleFrom, SCHEDULE_MAX, zeitpunktFehlerText } from '../schedule.js';
|
|
27
|
+
export { LOCAL_MANIFEST_FILE, MANIFEST_FILE_ENV } from '../paths.js';
|
|
28
|
+
/** Publishable Key in der Entwicklung. Der Dev-Server beantwortet ihn selbst. */
|
|
29
|
+
export const DEV_SITE_KEY = 'dev';
|
|
30
|
+
// Platzhalter-Dateien des Pakets, deren Inhalt das Plugin beim Laden ersetzt.
|
|
31
|
+
const EMBEDDED_MODULE = /[\\/]dealsystem-(site-data|legal-imprint|legal-privacy)\.(?:js|ts)(?:\?.*)?$/;
|
|
32
|
+
const PACKAGE = '@dealsystem/site';
|
|
33
|
+
async function svelteFiles(dir) {
|
|
34
|
+
const files = [];
|
|
35
|
+
let entries;
|
|
36
|
+
try {
|
|
37
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return files;
|
|
41
|
+
}
|
|
42
|
+
for (const entry of entries) {
|
|
43
|
+
const path = join(dir, entry.name);
|
|
44
|
+
if (entry.isDirectory()) {
|
|
45
|
+
if (entry.name !== 'node_modules' && !entry.name.startsWith('.'))
|
|
46
|
+
files.push(...(await svelteFiles(path)));
|
|
47
|
+
}
|
|
48
|
+
else if (entry.name.endsWith('.svelte')) {
|
|
49
|
+
files.push(path);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return files.sort();
|
|
53
|
+
}
|
|
54
|
+
/** `<SiteHead>` aus dem SDK wird in dieser Datei benutzt. */
|
|
55
|
+
export function usesSiteHead(code) {
|
|
56
|
+
return (/import\s*\{[^}]*\bSiteHead\b[^}]*\}\s*from\s*['"]@dealsystem\/site['"]/.test(code) &&
|
|
57
|
+
/<SiteHead\b/.test(code));
|
|
58
|
+
}
|
|
59
|
+
/** Sammelt die Slots aller `.svelte`-Dateien unter `src/`. */
|
|
60
|
+
export async function collectSlots(root) {
|
|
61
|
+
const found = [];
|
|
62
|
+
const grenzen = [];
|
|
63
|
+
const routes = new Set();
|
|
64
|
+
let siteHeadInRootLayout = false;
|
|
65
|
+
for (const file of await svelteFiles(resolve(root, 'src'))) {
|
|
66
|
+
const shown = relative(root, file).replace(/\\/g, '/');
|
|
67
|
+
if (/\/\+page(?:@[^.]*)?\.svelte$/.test(shown)) {
|
|
68
|
+
const route = routeOfFile(shown);
|
|
69
|
+
if (route)
|
|
70
|
+
routes.add(route);
|
|
71
|
+
}
|
|
72
|
+
const code = await readFile(file, 'utf8');
|
|
73
|
+
if (shown === 'src/routes/+layout.svelte' && usesSiteHead(code))
|
|
74
|
+
siteHeadInRootLayout = true;
|
|
75
|
+
found.push(...scanSlots(code, shown));
|
|
76
|
+
for (const fenster of scanZeitfenster(code))
|
|
77
|
+
for (const grenze of fenster.grenzen)
|
|
78
|
+
if (grenze.ms !== null)
|
|
79
|
+
grenzen.push(grenze.ms);
|
|
80
|
+
}
|
|
81
|
+
const imageSources = new Map();
|
|
82
|
+
for (const slot of found) {
|
|
83
|
+
if (slot.imageSource && !imageSources.has(slot.key))
|
|
84
|
+
imageSources.set(slot.key, slot.imageSource);
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
slots: mergeSlots(found),
|
|
88
|
+
routes: [...routes].sort(),
|
|
89
|
+
imageSources,
|
|
90
|
+
siteHeadInRootLayout,
|
|
91
|
+
readsSlotsInCode: await mentionsGetSlots(resolve(root, 'src')),
|
|
92
|
+
grenzen,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Trägt bei jedem Bild-Slot `defaultImage` ein: den Pfad des Standardbilds in der fertigen Seite, oder `null`,
|
|
97
|
+
* wenn er sich nicht sicher sagen lässt. `static`: die Datei muss unter `static/` liegen. `module`: der Pfad
|
|
98
|
+
* kommt aus dem Client-Build (`assets`: Datei im Projekt → Pfad im Artefakt); ein eingebettetes Bild
|
|
99
|
+
* (Vite: unter 4 KB als `data:`) steht dort nicht und bleibt `null`.
|
|
100
|
+
*/
|
|
101
|
+
export function withDefaultImages(slots, sources, staticExists, assets) {
|
|
102
|
+
return slots.map((slot) => {
|
|
103
|
+
if (slot.type !== 'image')
|
|
104
|
+
return slot;
|
|
105
|
+
const source = sources.get(slot.key);
|
|
106
|
+
const path = source?.kind === 'static'
|
|
107
|
+
? staticExists(source.path)
|
|
108
|
+
? source.path
|
|
109
|
+
: null
|
|
110
|
+
: source?.kind === 'module'
|
|
111
|
+
? (assets.get(source.path) ?? null)
|
|
112
|
+
: null;
|
|
113
|
+
const defaultImage = path
|
|
114
|
+
? {
|
|
115
|
+
path,
|
|
116
|
+
...(source?.width ? { width: source.width } : {}),
|
|
117
|
+
...(source?.height ? { height: source.height } : {}),
|
|
118
|
+
}
|
|
119
|
+
: null;
|
|
120
|
+
return { ...slot, defaultImage };
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Irgendeine Quelldatei unter `src/` liest Slot-Werte selbst: `getSlots()`, `readSnapshot()` oder den
|
|
125
|
+
* Schnappschuss `.dealsystem/content.json`. Grob, aber auf der sicheren Seite.
|
|
126
|
+
*/
|
|
127
|
+
const READS_SLOTS = /\bgetSlots\b|\breadSnapshot\b|content\.json\b/;
|
|
128
|
+
async function mentionsGetSlots(dir) {
|
|
129
|
+
let entries;
|
|
130
|
+
try {
|
|
131
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
for (const entry of entries) {
|
|
137
|
+
const path = join(dir, entry.name);
|
|
138
|
+
if (entry.isDirectory()) {
|
|
139
|
+
if (entry.name !== 'node_modules' && !entry.name.startsWith('.') && (await mentionsGetSlots(path)))
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
else if (/\.(svelte|[cm]?[jt]s)$/.test(entry.name)) {
|
|
143
|
+
if (READS_SLOTS.test(await readFile(path, 'utf8')))
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Angaben für „Patchen statt Bauen“: Darf der Core neue Slot-Werte in die
|
|
151
|
+
* fertige Seite schreiben, statt neu zu bauen? Und was braucht er dafür?
|
|
152
|
+
*/
|
|
153
|
+
export function buildContentPatchInfo(collected, slots) {
|
|
154
|
+
const blockers = [];
|
|
155
|
+
if (!collected.siteHeadInRootLayout)
|
|
156
|
+
blockers.push('site-head-missing');
|
|
157
|
+
if (collected.readsSlotsInCode)
|
|
158
|
+
blockers.push('get-slots');
|
|
159
|
+
// Standard-HTML der Richtext-Slots: braucht der Core, wenn der Kunde einen Text zurücksetzt.
|
|
160
|
+
let richtextDefaults = {};
|
|
161
|
+
let bytes = 0;
|
|
162
|
+
let entries = 0;
|
|
163
|
+
let tooLarge = false;
|
|
164
|
+
const encoder = new TextEncoder();
|
|
165
|
+
for (const slot of slots) {
|
|
166
|
+
if (slot.type !== 'richtext' || typeof slot.default !== 'string')
|
|
167
|
+
continue;
|
|
168
|
+
const html = defaultRichtextToHtml(slot.default);
|
|
169
|
+
entries += 1;
|
|
170
|
+
bytes += encoder.encode(slot.key).length + encoder.encode(html).length;
|
|
171
|
+
if (html.length > CONTENT_PATCH_LIMITS.richtextDefaultMaxLength ||
|
|
172
|
+
entries > CONTENT_PATCH_LIMITS.richtextDefaultsMaxEntries ||
|
|
173
|
+
bytes > CONTENT_PATCH_LIMITS.richtextDefaultsTotalBytes) {
|
|
174
|
+
tooLarge = true;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
richtextDefaults[slot.key] = html;
|
|
178
|
+
}
|
|
179
|
+
// Zu groß für den Build-Bericht: Die Seite baut weiter, nur gepatcht wird sie nicht.
|
|
180
|
+
if (tooLarge) {
|
|
181
|
+
blockers.push('richtext-defaults-too-large');
|
|
182
|
+
richtextDefaults = {};
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
format: CONTENT_BLOCK_VERSION,
|
|
186
|
+
delivery: blockers.includes('site-head-missing') ? 'embedded' : 'dom',
|
|
187
|
+
blockers,
|
|
188
|
+
richtextDefaults,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/** Baut das Manifest aus Konfiguration, Slots und Routen. */
|
|
192
|
+
export function buildManifest(config, slots, routes, extras = {}) {
|
|
193
|
+
return {
|
|
194
|
+
manifestVersion: 1,
|
|
195
|
+
sdkVersion: SDK_VERSION,
|
|
196
|
+
siteId: config.siteId,
|
|
197
|
+
routes,
|
|
198
|
+
slots,
|
|
199
|
+
collections: Object.entries(config.collections ?? {}).map(([key, collection]) => ({
|
|
200
|
+
...collection,
|
|
201
|
+
key,
|
|
202
|
+
source: 'cms',
|
|
203
|
+
})),
|
|
204
|
+
funnels: Object.entries(config.funnels ?? {}).map(([key, funnel]) => ({
|
|
205
|
+
...funnel,
|
|
206
|
+
key,
|
|
207
|
+
// Vertrag mit dem Core (C4): immer gesetzt, `{ label }` getrimmt oder `null`.
|
|
208
|
+
leadmagnet: normalizeLeadmagnet(funnel.leadmagnet),
|
|
209
|
+
})),
|
|
210
|
+
...(extras.contentPatch ? { contentPatch: extras.contentPatch } : {}),
|
|
211
|
+
schedule: extras.schedule ?? [],
|
|
212
|
+
external: resolveExternal(config.external),
|
|
213
|
+
bookings: Object.entries(config.booking ?? {}).map(([key, booking]) => ({ ...booking, key })),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Quelltext des Moduls `dealsystem-site-data` für den Browser, wenn die Seite
|
|
218
|
+
* den Inhaltsblock trägt: alles außer Slots und Richtext steht im Bundle, die
|
|
219
|
+
* Texte liest der Browser aus `<script id="ds-content">`. Fehlt der Block,
|
|
220
|
+
* gelten die Standardwerte aus dem Code.
|
|
221
|
+
*/
|
|
222
|
+
export function clientSiteDataModule(data) {
|
|
223
|
+
const base = { ...data, slots: {}, richtext: {} };
|
|
224
|
+
return [
|
|
225
|
+
"import { CONTENT_BLOCK_ID, parseContentBlock } from '../contentBlock.js';",
|
|
226
|
+
`const base = ${JSON.stringify(base)};`,
|
|
227
|
+
"const block = typeof document === 'undefined' ? null : parseContentBlock(document.getElementById(CONTENT_BLOCK_ID)?.textContent);",
|
|
228
|
+
'export default block ? { ...base, slots: block.slots, richtext: block.richtext } : base;',
|
|
229
|
+
].join('\n');
|
|
230
|
+
}
|
|
231
|
+
/** Baut die Daten, die in die Seite eingebettet werden. Nur Öffentliches. */
|
|
232
|
+
export function buildSiteData(config, snapshot, slots, env, builtAt = Date.now()) {
|
|
233
|
+
const active = new Map(snapshot.funnels.map((funnel) => [funnel.key, funnel.active]));
|
|
234
|
+
const richtext = {};
|
|
235
|
+
for (const slot of slots) {
|
|
236
|
+
if (slot.type !== 'richtext')
|
|
237
|
+
continue;
|
|
238
|
+
// Eine Überschreibung aus dem CRM ist schon bereinigtes HTML: sie wird
|
|
239
|
+
// nie als Markdown gelesen, nur noch einmal gegen die Positiv-Liste
|
|
240
|
+
// geprüft. Als Markdown gilt allein der Standardtext aus dem Code.
|
|
241
|
+
const override = resolveTextSlot(snapshot.slots, slot.key, slot.aliases);
|
|
242
|
+
if (override !== null)
|
|
243
|
+
richtext[slot.key] = sanitizeRichtextHtml(override);
|
|
244
|
+
else if (typeof slot.default === 'string')
|
|
245
|
+
richtext[slot.key] = defaultRichtextToHtml(slot.default);
|
|
246
|
+
}
|
|
247
|
+
const siteUrl = env.PUBLIC_DEALSYSTEM_SITE_URL ||
|
|
248
|
+
(snapshot.site.primaryHost ? `https://${snapshot.site.primaryHost}` : '');
|
|
249
|
+
return {
|
|
250
|
+
api: {
|
|
251
|
+
baseUrl: env.PUBLIC_DEALSYSTEM_API ?? '',
|
|
252
|
+
siteKey: env.PUBLIC_DEALSYSTEM_SITE_KEY || DEV_SITE_KEY,
|
|
253
|
+
},
|
|
254
|
+
site: { ...snapshot.site, id: snapshot.site.id || config.siteId, url: siteUrl.replace(/\/+$/, '') },
|
|
255
|
+
legal: {
|
|
256
|
+
company: snapshot.legal.company,
|
|
257
|
+
address: snapshot.legal.address,
|
|
258
|
+
email: snapshot.legal.email,
|
|
259
|
+
phone: snapshot.legal.phone,
|
|
260
|
+
},
|
|
261
|
+
tracking: snapshot.tracking,
|
|
262
|
+
funnels: Object.fromEntries(Object.entries(config.funnels ?? {}).map(([key, funnel]) => [
|
|
263
|
+
key,
|
|
264
|
+
// Ein Formular, das der Core noch nicht kennt (erster Build), ist aktiv.
|
|
265
|
+
{ ...funnel, active: active.get(key) ?? true },
|
|
266
|
+
])),
|
|
267
|
+
collections: Object.fromEntries(Object.entries(config.collections ?? {}).map(([key, collection]) => [
|
|
268
|
+
key,
|
|
269
|
+
{ route: collection.route, fields: collection.fields },
|
|
270
|
+
])),
|
|
271
|
+
slots: snapshot.slots,
|
|
272
|
+
richtext,
|
|
273
|
+
seo: snapshot.seo,
|
|
274
|
+
builtAt,
|
|
275
|
+
external: Object.fromEntries(resolveExternal(config.external).map((entry) => [entry.id, entry])),
|
|
276
|
+
bookings: Object.fromEntries(Object.entries(config.booking ?? {}).map(([key, booking]) => [key, { ...booking }])),
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
const DEV_CAPTCHA_SECRET = 'dealsystem-dev';
|
|
280
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
281
|
+
/**
|
|
282
|
+
* Test-Aufgabe für `vite dev`, in derselben Form wie die des Core (ALTCHA v3,
|
|
283
|
+
* PBKDF2/SHA-256, signiert, an die Seite gebunden), damit das Formular lokal
|
|
284
|
+
* genauso läuft wie später. Der Schlüssel ist öffentlich: geprüft wird die
|
|
285
|
+
* Lösung lokal nicht.
|
|
286
|
+
*/
|
|
287
|
+
export async function createDevCaptchaChallenge(siteId) {
|
|
288
|
+
const { createChallenge, pbkdf2 } = await import('altcha/lib');
|
|
289
|
+
return createChallenge({
|
|
290
|
+
algorithm: 'PBKDF2/SHA-256',
|
|
291
|
+
cost: 2000,
|
|
292
|
+
counter: 250 + Math.floor(Math.random() * 501),
|
|
293
|
+
deriveKey: pbkdf2.deriveKey,
|
|
294
|
+
expiresAt: Math.floor(Date.now() / 1000) + 600,
|
|
295
|
+
data: { site: UUID.test(siteId) ? siteId : '00000000-0000-0000-0000-000000000000' },
|
|
296
|
+
hmacSignatureSecret: DEV_CAPTCHA_SECRET,
|
|
297
|
+
hmacKeySignatureSecret: DEV_CAPTCHA_SECRET,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Freie Probe-Zeiten für `vite dev`: werktags 9 bis 16 Uhr Berliner Zeit im Abstand von 30 Minuten, ab der
|
|
302
|
+
* nächsten vollen Stunde. Zeiten in UTC wie bei der Site-API; die Zeitumstellung erledigt `Intl`.
|
|
303
|
+
*/
|
|
304
|
+
export function devBookingSlots(from, to, durationMinutes = 30) {
|
|
305
|
+
const out = [];
|
|
306
|
+
const format = new Intl.DateTimeFormat('en-GB', {
|
|
307
|
+
timeZone: 'Europe/Berlin',
|
|
308
|
+
weekday: 'short',
|
|
309
|
+
hour: '2-digit',
|
|
310
|
+
minute: '2-digit',
|
|
311
|
+
hourCycle: 'h23',
|
|
312
|
+
});
|
|
313
|
+
const step = 30 * 60_000;
|
|
314
|
+
let t = Math.ceil(Math.max(from.getTime(), Date.now() + 3_600_000) / step) * step;
|
|
315
|
+
while (t + durationMinutes * 60_000 <= to.getTime() && out.length < 2000) {
|
|
316
|
+
const p = Object.fromEntries(format.formatToParts(new Date(t)).map((x) => [x.type, x.value]));
|
|
317
|
+
const minutes = Number(p.hour) * 60 + Number(p.minute);
|
|
318
|
+
if (p.weekday !== 'Sat' &&
|
|
319
|
+
p.weekday !== 'Sun' &&
|
|
320
|
+
minutes >= 9 * 60 &&
|
|
321
|
+
minutes + durationMinutes <= 16 * 60) {
|
|
322
|
+
out.push({
|
|
323
|
+
start: new Date(t).toISOString(),
|
|
324
|
+
end: new Date(t + durationMinutes * 60_000).toISOString(),
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
t += step;
|
|
328
|
+
}
|
|
329
|
+
return out;
|
|
330
|
+
}
|
|
331
|
+
function sendJson(res, status, body) {
|
|
332
|
+
res.statusCode = status;
|
|
333
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
334
|
+
res.end(JSON.stringify(body));
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Beantwortet in `vite dev` die Site-API für den Schlüssel `dev`: Sammlungen
|
|
338
|
+
* aus der lokalen Kopie, eine Test-Aufgabe für das Captcha, Formulare als
|
|
339
|
+
* Probelauf ohne Speichern. `dealsystem dev`
|
|
340
|
+
* darf davor eine eigene Middleware für `…/leads` setzen.
|
|
341
|
+
*/
|
|
342
|
+
function devSiteApi(server, config, root) {
|
|
343
|
+
const prefix = `/api/site/v1/s/${DEV_SITE_KEY}/`;
|
|
344
|
+
server.middlewares.use(async (req, res, next) => {
|
|
345
|
+
const url = new URL(req.url ?? '/', 'http://localhost');
|
|
346
|
+
if (!url.pathname.startsWith(prefix))
|
|
347
|
+
return next();
|
|
348
|
+
const [resource, key, slug] = url.pathname.slice(prefix.length).split('/').map(decodeURIComponent);
|
|
349
|
+
try {
|
|
350
|
+
if (resource === 'leads' && req.method === 'POST') {
|
|
351
|
+
let raw = '';
|
|
352
|
+
for await (const chunk of req)
|
|
353
|
+
raw += chunk;
|
|
354
|
+
const body = JSON.parse(raw || '{}');
|
|
355
|
+
if (!body.funnelKey || !config.funnels?.[body.funnelKey]) {
|
|
356
|
+
return sendJson(res, 404, {
|
|
357
|
+
error: 'Not Found',
|
|
358
|
+
message: 'Formular unbekannt',
|
|
359
|
+
status: 404,
|
|
360
|
+
code: 'funnel_not_found',
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
server.config.logger.info(`[dealsystem] Probe-Einsendung „${body.funnelKey}“ (nicht gespeichert)`);
|
|
364
|
+
// Wie ein Vorschau-Host: geprüft, nicht gespeichert.
|
|
365
|
+
res.setHeader('X-Captcha-Mode', 'test');
|
|
366
|
+
return sendJson(res, 200, { data: { accepted: true, dryRun: true } });
|
|
367
|
+
}
|
|
368
|
+
if (resource === 'track' && req.method === 'POST') {
|
|
369
|
+
// Seitenaufrufe zählen lokal nicht; wie eine Vorschau: geprüft, nichts gespeichert.
|
|
370
|
+
for await (const _chunk of req)
|
|
371
|
+
void _chunk;
|
|
372
|
+
return sendJson(res, 200, { data: { accepted: true, dryRun: true } });
|
|
373
|
+
}
|
|
374
|
+
if (resource === 'booking' && key) {
|
|
375
|
+
const booking = config.booking?.[key];
|
|
376
|
+
if (!booking) {
|
|
377
|
+
return sendJson(res, 404, {
|
|
378
|
+
error: 'Not Found',
|
|
379
|
+
message: 'Buchung unbekannt',
|
|
380
|
+
status: 404,
|
|
381
|
+
code: 'booking_unavailable',
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
if (!slug && req.method === 'GET') {
|
|
385
|
+
// Probe-Terminart: die echte richtet der Kunde im CRM ein.
|
|
386
|
+
return sendJson(res, 200, {
|
|
387
|
+
data: {
|
|
388
|
+
key,
|
|
389
|
+
label: booking.label ?? 'Probetermin',
|
|
390
|
+
title: booking.label ?? 'Probetermin',
|
|
391
|
+
description: 'Lokale Vorschau: Zeiten und Fragen sind Beispiele.',
|
|
392
|
+
durationMinutes: 30,
|
|
393
|
+
timezone: 'Europe/Berlin',
|
|
394
|
+
locations: [{ type: 'phone', label: 'Telefon' }],
|
|
395
|
+
questions: [
|
|
396
|
+
{
|
|
397
|
+
key: 'anliegen',
|
|
398
|
+
label: 'Worum geht es?',
|
|
399
|
+
type: 'textarea',
|
|
400
|
+
required: false,
|
|
401
|
+
options: null,
|
|
402
|
+
placeholder: null,
|
|
403
|
+
},
|
|
404
|
+
],
|
|
405
|
+
},
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
if (slug === 'slots' && req.method === 'GET') {
|
|
409
|
+
const from = new Date(url.searchParams.get('from') ?? Date.now());
|
|
410
|
+
const to = new Date(url.searchParams.get('to') ?? from.getTime() + 7 * 86_400_000);
|
|
411
|
+
return sendJson(res, 200, {
|
|
412
|
+
data: {
|
|
413
|
+
timezone: 'Europe/Berlin',
|
|
414
|
+
from: from.toISOString(),
|
|
415
|
+
to: to.toISOString(),
|
|
416
|
+
slots: devBookingSlots(from, to),
|
|
417
|
+
},
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
if (slug === 'bookings' && req.method === 'POST') {
|
|
421
|
+
let raw = '';
|
|
422
|
+
for await (const chunk of req)
|
|
423
|
+
raw += chunk;
|
|
424
|
+
const body = JSON.parse(raw || '{}');
|
|
425
|
+
server.config.logger.info(`[dealsystem] Probe-Buchung „${key}“ (nicht gebucht)`);
|
|
426
|
+
// Wie ein Vorschau-Host: geprüft, nichts gebucht, keine Mail.
|
|
427
|
+
const start = body.start ? new Date(body.start) : new Date();
|
|
428
|
+
return sendJson(res, 200, {
|
|
429
|
+
data: {
|
|
430
|
+
booked: true,
|
|
431
|
+
dryRun: true,
|
|
432
|
+
start: start.toISOString(),
|
|
433
|
+
end: new Date(start.getTime() + 30 * 60_000).toISOString(),
|
|
434
|
+
},
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
if (resource === 'captcha' && req.method === 'GET') {
|
|
439
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
440
|
+
res.setHeader('X-Captcha-Mode', 'test');
|
|
441
|
+
return sendJson(res, 200, await createDevCaptchaChallenge(config.siteId));
|
|
442
|
+
}
|
|
443
|
+
if (resource === 'collections' && req.method === 'GET' && key) {
|
|
444
|
+
const notFound = (message) => sendJson(res, 404, { error: 'Not Found', message, status: 404, code: 'not_found' });
|
|
445
|
+
if (!config.collections?.[key])
|
|
446
|
+
return notFound('Sammlung unbekannt');
|
|
447
|
+
const snapshot = await readSnapshot(root);
|
|
448
|
+
const entries = [...(snapshot.collections[key]?.entries ?? [])].sort((a, b) => b.publishedAt.localeCompare(a.publishedAt));
|
|
449
|
+
if (url.searchParams.get('sort') === 'publishedAt')
|
|
450
|
+
entries.reverse();
|
|
451
|
+
if (slug) {
|
|
452
|
+
const entry = entries.find((e) => e.slug === slug);
|
|
453
|
+
return entry ? sendJson(res, 200, { data: entry }) : notFound('Eintrag unbekannt');
|
|
454
|
+
}
|
|
455
|
+
// Wie die Site-API: ohne Angabe 20, höchstens 100, Werte werden geklemmt.
|
|
456
|
+
const clamp = (name, fallback, min, max) => {
|
|
457
|
+
const value = Number.parseInt(url.searchParams.get(name) ?? '', 10);
|
|
458
|
+
return Number.isFinite(value) ? Math.min(max, Math.max(min, value)) : fallback;
|
|
459
|
+
};
|
|
460
|
+
const limit = clamp('limit', 20, 1, 100);
|
|
461
|
+
const offset = clamp('offset', 0, 0, 10_000);
|
|
462
|
+
return sendJson(res, 200, {
|
|
463
|
+
data: entries.slice(offset, offset + limit),
|
|
464
|
+
meta: { total: entries.length, limit, offset },
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
return sendJson(res, 404, {
|
|
468
|
+
error: 'Not Found',
|
|
469
|
+
message: 'Unbekannter Pfad',
|
|
470
|
+
status: 404,
|
|
471
|
+
code: 'not_found',
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
catch (error) {
|
|
475
|
+
return sendJson(res, 500, {
|
|
476
|
+
error: 'Internal Error',
|
|
477
|
+
message: String(error),
|
|
478
|
+
status: 500,
|
|
479
|
+
code: 'dev_error',
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Das Vite-Plugin. Gehört in `vite.config.ts` **vor** `sveltekit()` und
|
|
486
|
+
* bekommt die Konfiguration aus `dealsystem.config.ts`.
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* // vite.config.ts
|
|
490
|
+
* import { sveltekit } from '@sveltejs/kit/vite';
|
|
491
|
+
* import { dealsystem } from '@dealsystem/site/vite';
|
|
492
|
+
* import { defineConfig } from 'vite';
|
|
493
|
+
* import site from './dealsystem.config';
|
|
494
|
+
*
|
|
495
|
+
* export default defineConfig({
|
|
496
|
+
* plugins: [dealsystem(site), sveltekit()],
|
|
497
|
+
* });
|
|
498
|
+
*/
|
|
499
|
+
export function dealsystem(config) {
|
|
500
|
+
const problems = validateSiteConfig(config).filter((p) => p.path !== 'siteId');
|
|
501
|
+
if (problems.length > 0) {
|
|
502
|
+
throw new Error(`[dealsystem] dealsystem.config.ts ist ungültig:\n${problems.map((p) => ` - ${p.path}: ${p.message}`).join('\n')}`);
|
|
503
|
+
}
|
|
504
|
+
let root = process.cwd();
|
|
505
|
+
let code = null;
|
|
506
|
+
let clientSiteData = null;
|
|
507
|
+
let snapshot = null;
|
|
508
|
+
let scanned = null;
|
|
509
|
+
/**
|
|
510
|
+
* Zeitpunkt des Builds: entscheidet über `<Zeitfenster>` im HTML und welche Grenzen „künftig“ sind. Einmal je
|
|
511
|
+
* Build, damit Server- und Client-Teil dieselbe Zeit sehen. In `vite dev` bleibt sie stehen (sonst lüde
|
|
512
|
+
* jede Änderung die Seite ganz neu); dort schaltet der Baustein nach dem Laden mit der Uhr des Browsers.
|
|
513
|
+
*/
|
|
514
|
+
const builtAt = Date.now();
|
|
515
|
+
/** Datei im Projekt → Pfad im Artefakt, aus dem Client-Build. Bleibt für spätere Builds desselben Laufs. */
|
|
516
|
+
const assets = new Map();
|
|
517
|
+
const loadedIds = new Set();
|
|
518
|
+
function currentManifest() {
|
|
519
|
+
const { slots, routes, imageSources } = scanned;
|
|
520
|
+
const staticExists = (path) => existsSync(resolve(root, 'static', `.${path}`));
|
|
521
|
+
return buildManifest(config, withDefaultImages(slots, imageSources, staticExists, assets), routes, {
|
|
522
|
+
contentPatch: buildContentPatchInfo(scanned, slots),
|
|
523
|
+
schedule: scheduleFrom(scanned.grenzen, builtAt),
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
async function refresh() {
|
|
527
|
+
snapshot = await readSnapshot(root);
|
|
528
|
+
scanned = await collectSlots(root);
|
|
529
|
+
const { slots } = scanned;
|
|
530
|
+
const module = (value) => `export default ${JSON.stringify(value)};`;
|
|
531
|
+
const siteData = buildSiteData(config, snapshot, slots, process.env, builtAt);
|
|
532
|
+
const contentPatch = buildContentPatchInfo(scanned, slots);
|
|
533
|
+
// Mit `<SiteHead>` im Haupt-Layout stehen die Texte nur im HTML, nicht im Bundle.
|
|
534
|
+
clientSiteData = contentPatch.delivery === 'dom' ? clientSiteDataModule(siteData) : null;
|
|
535
|
+
code = {
|
|
536
|
+
'site-data': module(siteData),
|
|
537
|
+
// Rechtstexte des Kunden: im Core bereinigt, hier noch einmal gegen die Positiv-Liste geprüft.
|
|
538
|
+
'legal-imprint': module(sanitizeRichtextHtml(snapshot.legal.imprintHtml)),
|
|
539
|
+
'legal-privacy': module(sanitizeRichtextHtml(snapshot.legal.privacyHtml)),
|
|
540
|
+
};
|
|
541
|
+
return currentManifest();
|
|
542
|
+
}
|
|
543
|
+
async function writeManifest(manifest) {
|
|
544
|
+
const file = resolve(root, process.env[MANIFEST_FILE_ENV] || LOCAL_MANIFEST_FILE);
|
|
545
|
+
await mkdir(dirname(file), { recursive: true });
|
|
546
|
+
await writeFile(file, `${JSON.stringify(manifest, null, '\t')}\n`);
|
|
547
|
+
}
|
|
548
|
+
return {
|
|
549
|
+
name: 'dealsystem-site',
|
|
550
|
+
enforce: 'pre',
|
|
551
|
+
config() {
|
|
552
|
+
// Das Paket muss durch Vite laufen, sonst greift `load` unten nicht.
|
|
553
|
+
return {
|
|
554
|
+
optimizeDeps: { exclude: [PACKAGE] },
|
|
555
|
+
ssr: { noExternal: [PACKAGE] },
|
|
556
|
+
};
|
|
557
|
+
},
|
|
558
|
+
configResolved(resolved) {
|
|
559
|
+
root = resolved.root;
|
|
560
|
+
},
|
|
561
|
+
async buildStart() {
|
|
562
|
+
await writeManifest(await refresh());
|
|
563
|
+
},
|
|
564
|
+
generateBundle(_options, bundle) {
|
|
565
|
+
// Nur in den Teil, der ausgeliefert wird; adapter-static kopiert ihn nach `build/`.
|
|
566
|
+
if (this.environment?.name !== 'client' || !snapshot)
|
|
567
|
+
return;
|
|
568
|
+
const source = webManifest(snapshot.seo, snapshot.site.name);
|
|
569
|
+
if (source)
|
|
570
|
+
this.emitFile({ type: 'asset', fileName: WEB_MANIFEST_PATH.slice(1), source });
|
|
571
|
+
// Wo die importierten Bilder im Artefakt liegen. Eingebettete Bilder (data:) erscheinen hier nicht.
|
|
572
|
+
for (const output of Object.values(bundle)) {
|
|
573
|
+
if (output.type !== 'asset')
|
|
574
|
+
continue;
|
|
575
|
+
const originals = output.originalFileNames ?? [];
|
|
576
|
+
for (const original of originals) {
|
|
577
|
+
const shown = (isAbsolute(original) ? relative(root, original) : original).replace(/\\/g, '/');
|
|
578
|
+
assets.set(shown, `/${output.fileName}`);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
},
|
|
582
|
+
async writeBundle() {
|
|
583
|
+
// Erst jetzt sind die Pfade der Bilder bekannt: Manifest mit `defaultImage` noch einmal schreiben.
|
|
584
|
+
if (this.environment?.name !== 'client' || !scanned)
|
|
585
|
+
return;
|
|
586
|
+
await writeManifest(currentManifest());
|
|
587
|
+
},
|
|
588
|
+
async load(id, options) {
|
|
589
|
+
const match = EMBEDDED_MODULE.exec(id);
|
|
590
|
+
if (!match)
|
|
591
|
+
return null;
|
|
592
|
+
loadedIds.add(id);
|
|
593
|
+
if (code === null)
|
|
594
|
+
await refresh();
|
|
595
|
+
const ssr = options?.ssr ?? this.environment?.name === 'ssr';
|
|
596
|
+
if (match[1] === 'site-data' && !ssr && clientSiteData !== null)
|
|
597
|
+
return clientSiteData;
|
|
598
|
+
return code[match[1]] ?? null;
|
|
599
|
+
},
|
|
600
|
+
configureServer(server) {
|
|
601
|
+
devSiteApi(server, config, root);
|
|
602
|
+
server.middlewares.use(WEB_MANIFEST_PATH, async (_req, res, next) => {
|
|
603
|
+
const current = await readSnapshot(root);
|
|
604
|
+
const source = webManifest(current.seo, current.site.name);
|
|
605
|
+
if (!source)
|
|
606
|
+
return next();
|
|
607
|
+
res.setHeader('Content-Type', 'application/manifest+json; charset=utf-8');
|
|
608
|
+
res.end(source);
|
|
609
|
+
});
|
|
610
|
+
const contentFile = resolve(root, process.env[CONTENT_FILE_ENV] || LOCAL_CONTENT_FILE);
|
|
611
|
+
server.watcher.add(contentFile);
|
|
612
|
+
const onChange = async (file) => {
|
|
613
|
+
const isContent = resolve(file) === contentFile;
|
|
614
|
+
const isSource = file.endsWith('.svelte') && !file.includes('node_modules');
|
|
615
|
+
if (!isContent && !isSource)
|
|
616
|
+
return;
|
|
617
|
+
const before = JSON.stringify(code) + String(clientSiteData);
|
|
618
|
+
try {
|
|
619
|
+
await writeManifest(await refresh());
|
|
620
|
+
}
|
|
621
|
+
catch (error) {
|
|
622
|
+
server.config.logger.error(error instanceof Error ? error.message : String(error));
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
if (JSON.stringify(code) + String(clientSiteData) === before)
|
|
626
|
+
return;
|
|
627
|
+
for (const environment of Object.values(server.environments)) {
|
|
628
|
+
for (const id of loadedIds) {
|
|
629
|
+
const module = environment.moduleGraph.getModuleById(id);
|
|
630
|
+
if (module)
|
|
631
|
+
environment.moduleGraph.invalidateModule(module);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
server.hot.send({ type: 'full-reload' });
|
|
635
|
+
};
|
|
636
|
+
server.watcher.on('change', onChange);
|
|
637
|
+
server.watcher.on('add', onChange);
|
|
638
|
+
server.watcher.on('unlink', onChange);
|
|
639
|
+
},
|
|
640
|
+
};
|
|
641
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ContentSlotDef } from '../types.js';
|
|
2
|
+
/** Ein Fehler im Quelltext, mit Fundstelle und Korrektur. */
|
|
3
|
+
export declare class SlotScanError extends Error {
|
|
4
|
+
readonly file: string;
|
|
5
|
+
readonly line: number;
|
|
6
|
+
constructor(file: string, line: number, detail: string);
|
|
7
|
+
}
|
|
8
|
+
/** Ein gefundener Slot mit Fundstelle. */
|
|
9
|
+
export interface FoundSlot extends ContentSlotDef {
|
|
10
|
+
file: string;
|
|
11
|
+
line: number;
|
|
12
|
+
/**
|
|
13
|
+
* Bild-Slots: woher das Standardbild kommt, wenn der Quelltext es sicher sagt. `static`: Pfad unter
|
|
14
|
+
* `static/` (`default="/bilder/haus.jpg"`); `module`: Datei im Projekt, relativ zur Wurzel
|
|
15
|
+
* (`import bild from '$lib/bilder/haus.jpg'`). Den Pfad im Artefakt löst das Vite-Plugin beim Build auf.
|
|
16
|
+
*/
|
|
17
|
+
imageSource?: {
|
|
18
|
+
kind: 'static' | 'module';
|
|
19
|
+
path: string;
|
|
20
|
+
width?: number;
|
|
21
|
+
height?: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export type Node = Record<string, unknown> & {
|
|
25
|
+
type: string;
|
|
26
|
+
start?: number;
|
|
27
|
+
};
|
|
28
|
+
declare const DYNAMIC: unique symbol;
|
|
29
|
+
type Static = string | number | boolean | string[] | {
|
|
30
|
+
[key: string]: Static;
|
|
31
|
+
} | typeof DYNAMIC;
|
|
32
|
+
/** Wert eines Attributs, wenn er fest im Quelltext steht. */
|
|
33
|
+
/** @internal */
|
|
34
|
+
export declare function staticAttribute(attribute: Node): Static;
|
|
35
|
+
/** Route einer Datei unter `src/routes`, in SvelteKit-Schreibweise. */
|
|
36
|
+
export declare function routeOfFile(file: string): string | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Liest die Slots einer `.svelte`-Datei. Wirft `SlotScanError`, wenn ein
|
|
39
|
+
* Schlüssel nicht fest im Quelltext steht oder das Format nicht passt.
|
|
40
|
+
*/
|
|
41
|
+
export declare function scanSlots(code: string, file: string): FoundSlot[];
|
|
42
|
+
/**
|
|
43
|
+
* Führt die Slots aller Dateien zusammen. Derselbe Schlüssel darf mehrfach
|
|
44
|
+
* vorkommen, aber nur mit demselben Typ und demselben Standardwert.
|
|
45
|
+
*/
|
|
46
|
+
export declare function mergeSlots(found: readonly FoundSlot[]): ContentSlotDef[];
|
|
47
|
+
export {};
|