qarpeo 0.1.18 → 0.1.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/README.md +96 -96
- package/dist/chunks/auth-schema.mjs +3 -1
- package/dist/chunks/wrangler.mjs +22 -3
- package/dist/cli/index.mjs +448 -221
- package/dist/fate/index.d.ts +29 -22
- package/dist/fate/index.mjs +1 -3
- package/dist/module.d.ts +1 -1
- package/dist/module.mjs +103 -82
- package/dist/runtime/ai.d.ts +2 -2
- package/dist/runtime/app/components/BlobImage.vue +119 -107
- package/dist/runtime/app/components/CMSBlocks.vue +104 -93
- package/dist/runtime/app/components/CMSContent.vue +24 -23
- package/dist/runtime/app/components/CMSImage.vue +49 -49
- package/dist/runtime/app/components/CMSLocaleSwitcher.vue +110 -110
- package/dist/runtime/app/components/CMSPreviewBanner.vue +83 -79
- package/dist/runtime/app/components/CMSVersionBanner.vue +53 -49
- package/dist/runtime/app/components/CMSVersionSwitcher.vue +140 -140
- package/dist/runtime/app/components/ContentRenderer.vue +83 -80
- package/dist/runtime/app/components/FileUpload.vue +200 -196
- package/dist/runtime/app/components/ImpersonationBanner.vue +61 -57
- package/dist/runtime/app/components/QarpeoWelcome.vue +84 -84
- package/dist/runtime/app/components/SignedIn.vue +13 -13
- package/dist/runtime/app/components/SignedOut.vue +13 -13
- package/dist/runtime/app/components/shiki.css +34 -34
- package/dist/runtime/app/composables/ai.d.ts +22 -22
- package/dist/runtime/app/composables/ai.mjs +3 -7
- package/dist/runtime/app/composables/analytics.mjs +1 -1
- package/dist/runtime/app/composables/api-tokens.mjs +1 -1
- package/dist/runtime/app/composables/auth.d.ts +6 -7
- package/dist/runtime/app/composables/auth.mjs +6 -3
- package/dist/runtime/app/composables/chat.mjs +3 -7
- package/dist/runtime/app/composables/cms-preview.d.ts +3 -3
- package/dist/runtime/app/composables/cms-preview.mjs +1 -1
- package/dist/runtime/app/composables/cms.d.ts +3 -5
- package/dist/runtime/app/composables/cms.mjs +2 -2
- package/dist/runtime/app/composables/docs-version.d.ts +8 -7
- package/dist/runtime/app/composables/docs-version.mjs +3 -3
- package/dist/runtime/app/composables/impersonation.mjs +1 -1
- package/dist/runtime/app/composables/notifications.d.ts +5 -5
- package/dist/runtime/app/composables/notifications.mjs +4 -5
- package/dist/runtime/app/composables/organization.mjs +1 -1
- package/dist/runtime/app/composables/passkey.mjs +1 -1
- package/dist/runtime/app/composables/passwordless.mjs +1 -1
- package/dist/runtime/app/composables/payments.d.ts +2 -1
- package/dist/runtime/app/composables/payments.mjs +1 -1
- package/dist/runtime/app/composables/realtime.d.ts +13 -13
- package/dist/runtime/app/composables/realtime.mjs +2 -2
- package/dist/runtime/app/composables/resumable-upload.d.ts +11 -11
- package/dist/runtime/app/composables/resumable-upload.mjs +1 -1
- package/dist/runtime/app/composables/site.mjs +1 -1
- package/dist/runtime/app/composables/storage.d.ts +151 -11
- package/dist/runtime/app/composables/storage.mjs +291 -33
- package/dist/runtime/app/composables/turnstile.mjs +1 -1
- package/dist/runtime/app/composables/two-factor.mjs +1 -1
- package/dist/runtime/app/pages/devtools/agents.vue +716 -716
- package/dist/runtime/app/pages/devtools/analytics.vue +616 -616
- package/dist/runtime/app/pages/devtools/auth.vue +381 -350
- package/dist/runtime/app/pages/devtools/blob.vue +743 -744
- package/dist/runtime/app/pages/devtools/db.vue +545 -545
- package/dist/runtime/app/pages/devtools/domains.vue +771 -771
- package/dist/runtime/app/pages/devtools/kv.vue +827 -828
- package/dist/runtime/app/pages/devtools/logs.vue +649 -653
- package/dist/runtime/app/pages/devtools/mail.vue +388 -388
- package/dist/runtime/app/pages/devtools/overview.vue +391 -389
- package/dist/runtime/app/pages/devtools/realtime.vue +89 -27
- package/dist/runtime/app/pages/devtools/security.vue +20 -5
- package/dist/runtime/app/pages/devtools/settings.vue +559 -559
- package/dist/runtime/app/pages/devtools/tasks.vue +26 -10
- package/dist/runtime/app/pages/devtools.vue +176 -176
- package/dist/runtime/app/plugins/seo.mjs +1 -1
- package/dist/runtime/app/plugins/shortcuts.client.d.ts +1 -4
- package/dist/runtime/app/public/sw-notifications.mjs +47 -52
- package/dist/runtime/blob.mjs +11 -4
- package/dist/runtime/browser.d.ts +1 -1
- package/dist/runtime/browser.mjs +12 -2
- package/dist/runtime/cache.d.ts +2 -1
- package/dist/runtime/kv.mjs +4 -1
- package/dist/runtime/providers/qarpeo.d.ts +3 -3
- package/dist/runtime/server/durable-objects/agent.mjs +1 -1
- package/dist/runtime/server/durable-objects/room.d.ts +2 -2
- package/dist/runtime/server/durable-objects/room.mjs +5 -5
- package/dist/runtime/server/middleware/devtools.mjs +6 -2
- package/dist/runtime/server/plugins/cms.d.ts +4 -2
- package/dist/runtime/server/plugins/dev-proxy.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/agents/chat.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/agents/chat.post.mjs +4 -1
- package/dist/runtime/server/routes/__qarpeo/analytics/events.get.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.mjs +5 -1
- package/dist/runtime/server/routes/__qarpeo/db/tables.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/db/tables.get.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/logs.get.d.ts +4 -1
- package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/mail/track/open/[id].get.mjs +2 -2
- package/dist/runtime/server/routes/__qarpeo/overview.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/realtime/room.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/realtime/rooms.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/security/analytics.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/security/ban.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/security/clear.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/security/unban.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/settings.get.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/tasks/run.post.mjs +3 -1
- package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +8 -2
- package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +8 -2
- package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +8 -2
- package/dist/runtime/server/routes/ai/embed.post.d.ts +1 -4
- package/dist/runtime/server/routes/ai/search.post.d.ts +2 -2
- package/dist/runtime/server/routes/auth/account.delete.mjs +1 -1
- package/dist/runtime/server/routes/auth/handler.mjs +6 -1
- package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +1 -1
- package/dist/runtime/server/routes/auth/organization/members/[id].delete.mjs +7 -1
- package/dist/runtime/server/routes/auth/otp/verify.post.mjs +1 -1
- package/dist/runtime/server/routes/auth/sso/login.get.mjs +7 -1
- package/dist/runtime/server/routes/auth/sso/oidc/callback.get.mjs +8 -2
- package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +7 -2
- package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +1 -1
- package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +7 -2
- package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +6 -1
- package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +6 -1
- package/dist/runtime/server/routes/browser/crawl.post.d.ts +1 -2
- package/dist/runtime/server/routes/browser/invoice.post.d.ts +1 -2
- package/dist/runtime/server/routes/browser/og-image.post.d.ts +2 -2
- package/dist/runtime/server/routes/browser/pdf.post.d.ts +1 -2
- package/dist/runtime/server/routes/browser/pdf.post.mjs +6 -1
- package/dist/runtime/server/routes/browser/screenshot.post.d.ts +2 -2
- package/dist/runtime/server/routes/browser/screenshot.post.mjs +5 -1
- package/dist/runtime/server/routes/cms/components/index.get.d.ts +2 -2
- package/dist/runtime/server/routes/cms/preview/disable.get.d.ts +4 -3
- package/dist/runtime/server/routes/cms/preview/enable.get.d.ts +8 -8
- package/dist/runtime/server/routes/cms/search.get.mjs +1 -1
- package/dist/runtime/server/routes/cms/webhooks/[provider].post.d.ts +7 -7
- package/dist/runtime/server/routes/cms/webhooks/[provider].post.mjs +9 -2
- package/dist/runtime/server/routes/docs/search.get.d.ts +9 -9
- package/dist/runtime/server/routes/fate.mjs +5 -8
- package/dist/runtime/server/routes/mail/bounce.post.d.ts +2 -2
- package/dist/runtime/server/routes/mail/unsubscribe.d.ts +2 -2
- package/dist/runtime/server/routes/mail/webhooks.post.d.ts +2 -2
- package/dist/runtime/server/routes/mail/webhooks.post.mjs +7 -1
- package/dist/runtime/server/routes/payments/usage.get.d.ts +8 -8
- package/dist/runtime/server/routes/payments/usage.post.d.ts +2 -2
- package/dist/runtime/server/routes/realtime/history.delete.d.ts +4 -3
- package/dist/runtime/server/routes/realtime/history.get.d.ts +7 -6
- package/dist/runtime/server/routes/realtime/ws.get.mjs +6 -1
- package/dist/runtime/server/routes/robots.txt.get.mjs +1 -1
- package/dist/runtime/server/routes/sitemap.xml.get.mjs +2 -1
- package/dist/runtime/server/routes/storage/multipart/abort.post.d.ts +2 -2
- package/dist/runtime/server/routes/storage/multipart/complete.post.d.ts +2 -2
- package/dist/runtime/server/routes/storage/multipart/complete.post.mjs +2 -2
- package/dist/runtime/server/routes/storage/multipart/create.post.d.ts +2 -2
- package/dist/runtime/server/routes/storage/multipart/create.post.mjs +7 -3
- package/dist/runtime/server/routes/storage/multipart/part.put.d.ts +2 -2
- package/dist/runtime/server/routes/storage/multipart/part.put.mjs +1 -1
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +2 -4
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +2 -4
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.get.mjs +1 -1
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.post.mjs +2 -4
- package/dist/runtime/server/tasks/cms/publish.mjs +1 -1
- package/dist/runtime/server/utils/ai.d.ts +9 -9
- package/dist/runtime/server/utils/ai.mjs +3 -3
- package/dist/runtime/server/utils/auth.d.ts +12 -16
- package/dist/runtime/server/utils/auth.mjs +15 -9
- package/dist/runtime/server/utils/bots.mjs +21 -7
- package/dist/runtime/server/utils/browser-utils.d.ts +44 -41
- package/dist/runtime/server/utils/browser-utils.mjs +14 -4
- package/dist/runtime/server/utils/cache.d.ts +5 -5
- package/dist/runtime/server/utils/cms/common.d.ts +26 -0
- package/dist/runtime/server/utils/cms/common.mjs +68 -0
- package/dist/runtime/server/utils/cms/git.d.ts +24 -0
- package/dist/runtime/server/utils/cms/git.mjs +240 -0
- package/dist/runtime/server/utils/cms/markdown.d.ts +22 -0
- package/dist/runtime/server/utils/cms/markdown.mjs +92 -0
- package/dist/runtime/server/utils/cms/path.d.ts +51 -0
- package/dist/runtime/server/utils/cms/path.mjs +127 -0
- package/dist/runtime/server/utils/cms/search.d.ts +22 -0
- package/dist/runtime/server/utils/cms/search.mjs +221 -0
- package/dist/runtime/server/utils/cms-events.d.ts +1 -1
- package/dist/runtime/server/utils/cms-events.mjs +2 -2
- package/dist/runtime/server/utils/cms-filter.mjs +2 -2
- package/dist/runtime/server/utils/cms.d.ts +17 -149
- package/dist/runtime/server/utils/cms.mjs +52 -761
- package/dist/runtime/server/utils/config.d.ts +5 -4
- package/dist/runtime/server/utils/domains.mjs +7 -4
- package/dist/runtime/server/utils/email-templates.d.ts +10 -7
- package/dist/runtime/server/utils/email-templates.mjs +20 -5
- package/dist/runtime/server/utils/feed.d.ts +2 -2
- package/dist/runtime/server/utils/feed.mjs +3 -1
- package/dist/runtime/server/utils/mail-suppression.d.ts +8 -24
- package/dist/runtime/server/utils/mail-suppression.mjs +2 -2
- package/dist/runtime/server/utils/mail.d.ts +7 -8
- package/dist/runtime/server/utils/mail.mjs +17 -12
- package/dist/runtime/server/utils/multipart-store.d.ts +2 -2
- package/dist/runtime/server/utils/notifications.d.ts +9 -23
- package/dist/runtime/server/utils/organization.mjs +4 -12
- package/dist/runtime/server/utils/passwordless.mjs +1 -1
- package/dist/runtime/server/utils/payments.d.ts +2 -6
- package/dist/runtime/server/utils/payments.mjs +1 -1
- package/dist/runtime/server/utils/queue.d.ts +21 -31
- package/dist/runtime/server/utils/rag.d.ts +4 -4
- package/dist/runtime/server/utils/rag.mjs +8 -8
- package/dist/runtime/server/utils/realtime-store.d.ts +2 -2
- package/dist/runtime/server/utils/realtime.d.ts +26 -28
- package/dist/runtime/server/utils/scheduled-task.d.ts +1 -3
- package/dist/runtime/server/utils/security-store.d.ts +2 -2
- package/dist/runtime/server/utils/session.d.ts +9 -11
- package/dist/runtime/server/utils/sso.d.ts +9 -15
- package/dist/runtime/server/utils/sso.mjs +4 -8
- package/dist/runtime/server/utils/storage.d.ts +19 -2
- package/dist/runtime/server/utils/storage.mjs +36 -7
- package/dist/runtime/server/utils/tenant.mjs +3 -1
- package/dist/runtime/server/utils/turnstile.d.ts +3 -5
- package/dist/runtime/server/utils/vapid.d.ts +5 -8
- package/dist/runtime/server/utils/vapid.mjs +26 -13
- package/dist/runtime/service.d.ts +13 -13
- package/dist/runtime/service.mjs +4 -2
- package/dist/runtime/test-utils.d.ts +20 -30
- package/dist/runtime/test-utils.mjs +5 -4
- package/dist/runtime/types/auth-globals.d.ts +14 -14
- package/dist/runtime/types/imports.d.ts +82 -82
- package/dist/runtime/types/index.d.ts +2 -2
- package/dist/runtime/types/r2.d.ts +5 -0
- package/dist/runtime/types/service.d.ts +11 -18
- package/dist/types.d.ts +100 -107
- package/dist/utils/auth-schema.d.ts +2 -2
- package/dist/utils/cms-sources.d.ts +3 -3
- package/dist/utils/local-db.d.ts +3 -3
- package/dist/utils/notifications-schema.d.ts +1 -3
- package/dist/utils/pkg.d.ts +7 -0
- package/dist/utils/queue.d.ts +3 -3
- package/dist/utils/tasks.d.ts +3 -2
- package/package.json +11 -8
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { computeContentHash, getCMSConfig, getCMSDb } from "./common.mjs";
|
|
2
|
+
function toBase64(str) {
|
|
3
|
+
if (typeof Buffer !== "undefined") {
|
|
4
|
+
return Buffer.from(str, "utf8").toString("base64");
|
|
5
|
+
}
|
|
6
|
+
const bytes = new TextEncoder().encode(str);
|
|
7
|
+
let binary = "";
|
|
8
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
9
|
+
binary += String.fromCharCode(bytes[i]);
|
|
10
|
+
}
|
|
11
|
+
return btoa(binary);
|
|
12
|
+
}
|
|
13
|
+
let _formatEntryAsMarkdown = null;
|
|
14
|
+
export function registerEntryFormatter(fn) {
|
|
15
|
+
_formatEntryAsMarkdown = fn;
|
|
16
|
+
}
|
|
17
|
+
export async function syncEntryToGit(event, collectionId, entry, action) {
|
|
18
|
+
const config = getCMSConfig(event);
|
|
19
|
+
const colConfig = config.collections[collectionId] || {};
|
|
20
|
+
const mode = colConfig.mode || config.mode || "db";
|
|
21
|
+
if (mode !== "hybrid") {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const result = {};
|
|
25
|
+
const e = entry;
|
|
26
|
+
let rawFilePath = e.filePath || e.file_path;
|
|
27
|
+
if (!rawFilePath) {
|
|
28
|
+
const targetDir = colConfig.directory || `${config.contentDir}/${collectionId}`;
|
|
29
|
+
rawFilePath = `${targetDir}/${e.slug}.md`;
|
|
30
|
+
}
|
|
31
|
+
let resolvedFsPath = rawFilePath;
|
|
32
|
+
let fileContent = "";
|
|
33
|
+
try {
|
|
34
|
+
const fs = await import("node:fs/promises");
|
|
35
|
+
const pathMod = await import("node:path");
|
|
36
|
+
resolvedFsPath = pathMod.isAbsolute(rawFilePath) ? rawFilePath : pathMod.resolve(process.cwd(), rawFilePath);
|
|
37
|
+
if (action === "delete") {
|
|
38
|
+
const exists = await fs.stat(resolvedFsPath).catch(() => null);
|
|
39
|
+
if (exists) {
|
|
40
|
+
await fs.unlink(resolvedFsPath);
|
|
41
|
+
result.localFs = true;
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
fileContent = _formatEntryAsMarkdown ? _formatEntryAsMarkdown(entry) : "";
|
|
45
|
+
await fs.mkdir(pathMod.dirname(resolvedFsPath), { recursive: true });
|
|
46
|
+
await fs.writeFile(resolvedFsPath, fileContent, "utf8");
|
|
47
|
+
result.localFs = true;
|
|
48
|
+
const contentHash = await computeContentHash(fileContent);
|
|
49
|
+
result.filePath = resolvedFsPath;
|
|
50
|
+
result.contentHash = contentHash;
|
|
51
|
+
if (e.id) {
|
|
52
|
+
const db = getCMSDb(event);
|
|
53
|
+
await db.prepare(
|
|
54
|
+
"UPDATE _qarpeo_cms_entries SET file_path = ?, content_hash = ?, source = 'file' WHERE id = ?"
|
|
55
|
+
).bind(resolvedFsPath, contentHash, e.id).run();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} catch {
|
|
59
|
+
}
|
|
60
|
+
const ghConfig = {
|
|
61
|
+
...config.github,
|
|
62
|
+
...colConfig.github
|
|
63
|
+
};
|
|
64
|
+
const repo = ghConfig.repo || (typeof process !== "undefined" ? process.env.GITHUB_REPOSITORY : void 0);
|
|
65
|
+
const token = ghConfig.token || (typeof process !== "undefined" ? process.env.GITHUB_TOKEN || process.env.GH_TOKEN : void 0);
|
|
66
|
+
if (repo && token) {
|
|
67
|
+
try {
|
|
68
|
+
const [owner, repoName] = repo.split("/");
|
|
69
|
+
if (!owner || !repoName) {
|
|
70
|
+
console.warn(`[qarpeo:cms] Invalid GitHub repo format: "${repo}". Expected "owner/repo".`);
|
|
71
|
+
} else {
|
|
72
|
+
let gitPath = resolvedFsPath.replace(/\\/g, "/");
|
|
73
|
+
const match = gitPath.match(/(?:^|[\\/])((?:content|docs)[\\/].*)$/i);
|
|
74
|
+
if (match) {
|
|
75
|
+
gitPath = match[1];
|
|
76
|
+
} else if (colConfig.directory) {
|
|
77
|
+
gitPath = `${colConfig.directory}/${entry.slug}.md`;
|
|
78
|
+
} else {
|
|
79
|
+
gitPath = `${config.contentDir}/${collectionId}/${entry.slug}.md`;
|
|
80
|
+
}
|
|
81
|
+
gitPath = gitPath.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
82
|
+
const baseBranch = ghConfig.branch || "main";
|
|
83
|
+
const actionVerb = action === "create" ? "create" : action === "delete" ? "delete" : "update";
|
|
84
|
+
const template = ghConfig.commitMessage || "content({collection}): {action} {slug}";
|
|
85
|
+
const commitMsg = template.replace("{collection}", collectionId).replace("{slug}", entry.slug).replace("{action}", actionVerb);
|
|
86
|
+
const headers = {
|
|
87
|
+
Accept: "application/vnd.github.v3+json",
|
|
88
|
+
Authorization: `Bearer ${token}`,
|
|
89
|
+
"User-Agent": "qarpeo-cms",
|
|
90
|
+
"Content-Type": "application/json"
|
|
91
|
+
};
|
|
92
|
+
let existingSha;
|
|
93
|
+
try {
|
|
94
|
+
const checkRes = await fetch(
|
|
95
|
+
`https://api.github.com/repos/${owner}/${repoName}/contents/${gitPath}?ref=${baseBranch}`,
|
|
96
|
+
{ headers }
|
|
97
|
+
);
|
|
98
|
+
if (checkRes.ok) {
|
|
99
|
+
const checkData = await checkRes.json();
|
|
100
|
+
existingSha = checkData.sha;
|
|
101
|
+
}
|
|
102
|
+
} catch {
|
|
103
|
+
}
|
|
104
|
+
let targetBranch = baseBranch;
|
|
105
|
+
let prUrl;
|
|
106
|
+
if (ghConfig.pr) {
|
|
107
|
+
try {
|
|
108
|
+
const refRes = await fetch(
|
|
109
|
+
`https://api.github.com/repos/${owner}/${repoName}/git/ref/heads/${ghConfig.prBase || baseBranch}`,
|
|
110
|
+
{ headers }
|
|
111
|
+
);
|
|
112
|
+
if (refRes.ok) {
|
|
113
|
+
const refData = await refRes.json();
|
|
114
|
+
const baseSha = refData.object?.sha;
|
|
115
|
+
const newBranch = `${ghConfig.branchPrefix || "content/"}${collectionId}-${entry.slug}-${Date.now().toString(36)}`;
|
|
116
|
+
const createBranchRes = await fetch(
|
|
117
|
+
`https://api.github.com/repos/${owner}/${repoName}/git/refs`,
|
|
118
|
+
{
|
|
119
|
+
method: "POST",
|
|
120
|
+
headers,
|
|
121
|
+
body: JSON.stringify({
|
|
122
|
+
ref: `refs/heads/${newBranch}`,
|
|
123
|
+
sha: baseSha
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
if (createBranchRes.ok) {
|
|
128
|
+
targetBranch = newBranch;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
} catch {
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
let commitSha;
|
|
135
|
+
if (action === "delete") {
|
|
136
|
+
if (existingSha) {
|
|
137
|
+
const delRes = await fetch(
|
|
138
|
+
`https://api.github.com/repos/${owner}/${repoName}/contents/${gitPath}`,
|
|
139
|
+
{
|
|
140
|
+
method: "DELETE",
|
|
141
|
+
headers,
|
|
142
|
+
body: JSON.stringify({
|
|
143
|
+
message: commitMsg,
|
|
144
|
+
sha: existingSha,
|
|
145
|
+
branch: targetBranch
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
if (delRes.ok) {
|
|
150
|
+
const delData = await delRes.json();
|
|
151
|
+
commitSha = delData.commit?.sha;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
if (!fileContent && _formatEntryAsMarkdown) {
|
|
156
|
+
fileContent = _formatEntryAsMarkdown(entry);
|
|
157
|
+
}
|
|
158
|
+
const base64Content = toBase64(fileContent);
|
|
159
|
+
const putRes = await fetch(
|
|
160
|
+
`https://api.github.com/repos/${owner}/${repoName}/contents/${gitPath}`,
|
|
161
|
+
{
|
|
162
|
+
method: "PUT",
|
|
163
|
+
headers,
|
|
164
|
+
body: JSON.stringify({
|
|
165
|
+
message: commitMsg,
|
|
166
|
+
content: base64Content,
|
|
167
|
+
branch: targetBranch,
|
|
168
|
+
...existingSha ? { sha: existingSha } : {}
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
if (putRes.ok) {
|
|
173
|
+
const putData = await putRes.json();
|
|
174
|
+
commitSha = putData.commit?.sha;
|
|
175
|
+
} else {
|
|
176
|
+
const errData = await putRes.json().catch(() => ({}));
|
|
177
|
+
console.warn(
|
|
178
|
+
`[qarpeo:cms] GitHub commit failed (${putRes.status}):`,
|
|
179
|
+
errData?.message || putRes.statusText
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (ghConfig.pr && targetBranch !== baseBranch) {
|
|
184
|
+
try {
|
|
185
|
+
const prRes = await fetch(`https://api.github.com/repos/${owner}/${repoName}/pulls`, {
|
|
186
|
+
method: "POST",
|
|
187
|
+
headers,
|
|
188
|
+
body: JSON.stringify({
|
|
189
|
+
title: commitMsg,
|
|
190
|
+
head: targetBranch,
|
|
191
|
+
base: ghConfig.prBase || baseBranch,
|
|
192
|
+
body: `Automated content change from Qarpeo CMS for \`${collectionId}/${entry.slug}\`.`
|
|
193
|
+
})
|
|
194
|
+
});
|
|
195
|
+
if (prRes.ok) {
|
|
196
|
+
const prData = await prRes.json();
|
|
197
|
+
prUrl = prData.html_url;
|
|
198
|
+
}
|
|
199
|
+
} catch {
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
result.github = {
|
|
203
|
+
ok: true,
|
|
204
|
+
commitSha,
|
|
205
|
+
prUrl
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
} catch (err) {
|
|
209
|
+
console.warn(`[qarpeo:cms] GitHub sync error:`, err?.message || err);
|
|
210
|
+
result.github = {
|
|
211
|
+
ok: false,
|
|
212
|
+
error: err?.message || String(err)
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
export async function verifyGitHubSignature(rawBody, signatureHeader, secret) {
|
|
219
|
+
if (!signatureHeader || !secret) return false;
|
|
220
|
+
const cleanSig = signatureHeader.replace(/^sha256=/, "").trim();
|
|
221
|
+
try {
|
|
222
|
+
const key = await crypto.subtle.importKey(
|
|
223
|
+
"raw",
|
|
224
|
+
new TextEncoder().encode(secret),
|
|
225
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
226
|
+
false,
|
|
227
|
+
["sign"]
|
|
228
|
+
);
|
|
229
|
+
const sig = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(rawBody));
|
|
230
|
+
const expected = Array.from(new Uint8Array(sig)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
231
|
+
if (expected.length !== cleanSig.length) return false;
|
|
232
|
+
let diff = 0;
|
|
233
|
+
for (let i = 0; i < expected.length; i++) {
|
|
234
|
+
diff |= expected.charCodeAt(i) ^ cleanSig.charCodeAt(i);
|
|
235
|
+
}
|
|
236
|
+
return diff === 0;
|
|
237
|
+
} catch {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type RequestEvent } from "nuxt/server";
|
|
2
|
+
/** Parses markdown to Comark AST document ({ nodes, frontmatter, meta }). */
|
|
3
|
+
export declare function parseMarkdownAST(md: string, event?: RequestEvent): Promise<any>;
|
|
4
|
+
/** Parses markdown and renders to both AST and HTML in a single pass. */
|
|
5
|
+
export declare function processMarkdown(md: string, event?: RequestEvent): Promise<{
|
|
6
|
+
ast: any;
|
|
7
|
+
html: string;
|
|
8
|
+
}>;
|
|
9
|
+
/** Renders markdown with Comark to HTML string. */
|
|
10
|
+
export declare function renderMarkdown(md: string, event?: RequestEvent): Promise<string>;
|
|
11
|
+
/** Renders page markdown with Comark to HTML string. */
|
|
12
|
+
export declare function renderPageMarkdown(md: string): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Parses a raw markdown file string with YAML frontmatter. Returns `{ data, content }` where `data`
|
|
15
|
+
* is the frontmatter key-value map and `content` is the body markdown text.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseFrontmatter(raw: string): {
|
|
18
|
+
data: Record<string, unknown>;
|
|
19
|
+
content: string;
|
|
20
|
+
};
|
|
21
|
+
/** Serialises entry data back to a markdown file with YAML frontmatter. */
|
|
22
|
+
export declare function formatFrontmatter(data: Record<string, unknown>, body: string): string;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { parseMarkdown as comarkParseMarkdown } from "comark";
|
|
2
|
+
import { render as comarkRender } from "comark/render";
|
|
3
|
+
import { useRuntimeConfig } from "nuxt/server";
|
|
4
|
+
import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
|
|
5
|
+
import { getQarpeoConfig } from "../config.mjs";
|
|
6
|
+
const _cachedPluginsMap = /* @__PURE__ */ new Map();
|
|
7
|
+
async function _resolveMarkdownPlugins(event) {
|
|
8
|
+
const rc = useRuntimeConfig(event);
|
|
9
|
+
const pluginCfg = getQarpeoConfig(event).cms?.plugins || rc?.public?.qarpeo?.cms?.plugins || {};
|
|
10
|
+
const cacheKey = JSON.stringify(pluginCfg);
|
|
11
|
+
if (_cachedPluginsMap.has(cacheKey)) return _cachedPluginsMap.get(cacheKey);
|
|
12
|
+
const plugins = [];
|
|
13
|
+
if (pluginCfg.shiki !== false) {
|
|
14
|
+
try {
|
|
15
|
+
const shikiMod = await import("comark/plugins/shiki");
|
|
16
|
+
const shikiPlugin = shikiMod.default;
|
|
17
|
+
const shikiOptions = typeof pluginCfg.shiki === "object" ? pluginCfg.shiki : {};
|
|
18
|
+
plugins.push(shikiPlugin(shikiOptions));
|
|
19
|
+
} catch {
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
_cachedPluginsMap.set(cacheKey, plugins);
|
|
23
|
+
return plugins;
|
|
24
|
+
}
|
|
25
|
+
export async function parseMarkdownAST(md, event) {
|
|
26
|
+
if (!md) return { nodes: [], frontmatter: {}, meta: {} };
|
|
27
|
+
try {
|
|
28
|
+
const plugins = await _resolveMarkdownPlugins(event);
|
|
29
|
+
return await comarkParseMarkdown(md, { plugins });
|
|
30
|
+
} catch (err) {
|
|
31
|
+
console.error("[qarpeo:cms] parseMarkdownAST failed:", err);
|
|
32
|
+
return { nodes: [], frontmatter: {}, meta: {} };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export async function processMarkdown(md, event) {
|
|
36
|
+
if (!md) return { ast: { nodes: [], frontmatter: {}, meta: {} }, html: "" };
|
|
37
|
+
try {
|
|
38
|
+
const plugins = await _resolveMarkdownPlugins(event);
|
|
39
|
+
const ast = await comarkParseMarkdown(md, { plugins });
|
|
40
|
+
const html = (await comarkRender(ast, { format: "text/html" })).trim();
|
|
41
|
+
return { ast, html };
|
|
42
|
+
} catch {
|
|
43
|
+
return { ast: { nodes: [], frontmatter: {}, meta: {} }, html: md };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export async function renderMarkdown(md, event) {
|
|
47
|
+
if (!md) return "";
|
|
48
|
+
try {
|
|
49
|
+
const res = await processMarkdown(md, event);
|
|
50
|
+
return res.html;
|
|
51
|
+
} catch {
|
|
52
|
+
return md;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export async function renderPageMarkdown(md) {
|
|
56
|
+
return renderMarkdown(md);
|
|
57
|
+
}
|
|
58
|
+
export function parseFrontmatter(raw) {
|
|
59
|
+
const clean = raw ? raw.replace(/^\uFEFF/, "") : "";
|
|
60
|
+
const fmMatch = clean.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)/);
|
|
61
|
+
if (!fmMatch) {
|
|
62
|
+
return { data: {}, content: clean };
|
|
63
|
+
}
|
|
64
|
+
const yamlBlock = fmMatch[1] || "";
|
|
65
|
+
const body = fmMatch[2] || "";
|
|
66
|
+
let data = {};
|
|
67
|
+
try {
|
|
68
|
+
const parsed = parseYaml(yamlBlock);
|
|
69
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
70
|
+
data = parsed;
|
|
71
|
+
}
|
|
72
|
+
} catch (err) {
|
|
73
|
+
console.warn("[qarpeo:cms] Warning: failed to parse YAML frontmatter:", err);
|
|
74
|
+
}
|
|
75
|
+
return { data, content: body };
|
|
76
|
+
}
|
|
77
|
+
export function formatFrontmatter(data, body) {
|
|
78
|
+
const cleanData = {};
|
|
79
|
+
for (const [k, v] of Object.entries(data)) {
|
|
80
|
+
if (v === void 0 || v === null || k.startsWith("_")) continue;
|
|
81
|
+
cleanData[k] = v;
|
|
82
|
+
}
|
|
83
|
+
const yamlStr = Object.keys(cleanData).length > 0 ? stringifyYaml(cleanData).trim() : "";
|
|
84
|
+
if (!yamlStr) {
|
|
85
|
+
return body;
|
|
86
|
+
}
|
|
87
|
+
return `---
|
|
88
|
+
${yamlStr}
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
${body}`;
|
|
92
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { CMSHeadingLink } from "../../../../types";
|
|
2
|
+
/** Converts a heading text to a URL-safe slug ID. e.g. "Getting Started" → "getting-started" */
|
|
3
|
+
export declare function slugifyHeading(text: string): string;
|
|
4
|
+
/**
|
|
5
|
+
* Strips number-sort prefixes from path segments used for ordering. e.g. "1.docs" → "docs",
|
|
6
|
+
* "01.index" → "index", "2.getting-started" → "getting-started"
|
|
7
|
+
*/
|
|
8
|
+
export declare function stripOrderPrefix(segment: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Checks whether a path segment is a route group enclosed in parentheses. e.g. "(overview)" → true,
|
|
11
|
+
* "1.(overview)" → true, "01.(setup)" → true, "guide" → false
|
|
12
|
+
*/
|
|
13
|
+
export declare function isGroupSegment(segment: string): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Extracts a clean human-readable title from a group segment. e.g. "(overview)" → "Overview",
|
|
16
|
+
* "1.(quick-start)" → "Quick Start", "02.(faq)" → "FAQ"
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractGroupTitle(segment: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Extracts the numeric order prefix from a directory/file name. e.g. "1.docs" → 1,
|
|
21
|
+
* "01.getting-started" → 1, "docs" → undefined
|
|
22
|
+
*/
|
|
23
|
+
export declare function extractOrderPrefix(segment: string): number | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Computes a clean URL path from a file path relative to contentDir. Strips numeric order prefixes
|
|
26
|
+
* and route groups like `(overview)`. e.g. "1.docs/1.getting-started/(overview)/01.index.md" →
|
|
27
|
+
* "/docs/getting-started" "1.docs/1.getting-started/(overview)/02.intro.md" →
|
|
28
|
+
* "/docs/getting-started/intro" "1.docs/2.installation.md" → "/docs/installation"
|
|
29
|
+
* "blog/hello-world.md" → "/blog/hello-world"
|
|
30
|
+
*/
|
|
31
|
+
export declare function computeEntryPath(filePathRelative: string, collectionId?: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Tests whether an entry path matches one or more glob patterns. Supports:
|
|
34
|
+
*
|
|
35
|
+
* - Glob paths: `"/docs/**"`, `"/blog/*"`
|
|
36
|
+
* - Arrays: `["/docs/**", "/guides/**"]`
|
|
37
|
+
* - Negative excludes: `"!/docs/internal/**"`
|
|
38
|
+
*/
|
|
39
|
+
export declare function matchPathPatterns(entryPath: string, patterns?: string | string[]): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Resolves which collection an entryPath belongs to, checking configured collections' `path`
|
|
42
|
+
* patterns first, then falling back to fallbackId.
|
|
43
|
+
*/
|
|
44
|
+
export declare function resolveCollectionForPath(entryPath: string, collectionsConfig?: Record<string, any>, fallbackId?: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Extracts a table-of-contents array from raw markdown. Only processes ATX headings (## Foo, ###
|
|
47
|
+
* Bar — not h1).
|
|
48
|
+
*/
|
|
49
|
+
export declare function extractTOC(md: string): CMSHeadingLink[];
|
|
50
|
+
/** Pre-processes MDC (Markdown Components) syntax to HTML before passing to micromark. */
|
|
51
|
+
export declare function preprocessMDC(md: string): string;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
export function slugifyHeading(text) {
|
|
2
|
+
return text.toLowerCase().replace(/[^\w\s-]/g, "").replace(/[\s_]+/g, "-").replace(/^-+|-+$/g, "");
|
|
3
|
+
}
|
|
4
|
+
export function stripOrderPrefix(segment) {
|
|
5
|
+
return segment.replace(/^\d+\./, "");
|
|
6
|
+
}
|
|
7
|
+
export function isGroupSegment(segment) {
|
|
8
|
+
const stripped = stripOrderPrefix(segment);
|
|
9
|
+
return /^\([^)]+\)$/.test(stripped);
|
|
10
|
+
}
|
|
11
|
+
export function extractGroupTitle(segment) {
|
|
12
|
+
const stripped = stripOrderPrefix(segment);
|
|
13
|
+
const inner = stripped.replace(/^\(|\)$/g, "");
|
|
14
|
+
return inner.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
15
|
+
}
|
|
16
|
+
export function extractOrderPrefix(segment) {
|
|
17
|
+
const m = segment.match(/^(\d+)\./);
|
|
18
|
+
return m ? parseInt(m[1], 10) : void 0;
|
|
19
|
+
}
|
|
20
|
+
export function computeEntryPath(filePathRelative, collectionId) {
|
|
21
|
+
const normalized = filePathRelative.replace(/\\/g, "/").replace(/\.md$/, "");
|
|
22
|
+
const segments = normalized.split("/").filter(Boolean);
|
|
23
|
+
const cleaned = segments.filter((seg) => !isGroupSegment(seg)).map(stripOrderPrefix).filter(Boolean);
|
|
24
|
+
if (cleaned[cleaned.length - 1] === "index") {
|
|
25
|
+
cleaned.pop();
|
|
26
|
+
}
|
|
27
|
+
if (collectionId && collectionId !== "content" && cleaned[0] !== collectionId) {
|
|
28
|
+
cleaned.unshift(collectionId);
|
|
29
|
+
}
|
|
30
|
+
if (cleaned.length === 0) return "/";
|
|
31
|
+
return "/" + cleaned.join("/");
|
|
32
|
+
}
|
|
33
|
+
export function matchPathPatterns(entryPath, patterns) {
|
|
34
|
+
if (!patterns) return false;
|
|
35
|
+
const list = Array.isArray(patterns) ? patterns : [patterns];
|
|
36
|
+
if (!list.length) return false;
|
|
37
|
+
const path = ("/" + entryPath.replace(/\\/g, "/").replace(/^\/+/, "")).replace(/\/+$/, "") || "/";
|
|
38
|
+
let matched = false;
|
|
39
|
+
for (const raw of list) {
|
|
40
|
+
const isNeg = raw.startsWith("!");
|
|
41
|
+
const rawPattern = isNeg ? raw.slice(1) : raw;
|
|
42
|
+
const pattern = ("/" + rawPattern.replace(/\\/g, "/").replace(/^\/+/, "")).replace(/\/+$/, "") || "/";
|
|
43
|
+
let isMatch = false;
|
|
44
|
+
if (pattern.endsWith("/**")) {
|
|
45
|
+
const base = pattern.slice(0, -3) || "/";
|
|
46
|
+
isMatch = path === base || path.startsWith(base + "/");
|
|
47
|
+
} else if (pattern.includes("*") || pattern.includes("?")) {
|
|
48
|
+
const regexStr = "^" + pattern.replace(/[.+^${}()|[\]\\]/g, (m) => "\\" + m).replace(/\*\*/g, ".*").replace(/(?<!\.)\*/g, "[^/]*").replace(/\?/g, "[^/]") + "$";
|
|
49
|
+
isMatch = new RegExp(regexStr).test(path);
|
|
50
|
+
} else {
|
|
51
|
+
isMatch = path === pattern;
|
|
52
|
+
}
|
|
53
|
+
if (isMatch) {
|
|
54
|
+
if (isNeg) return false;
|
|
55
|
+
matched = true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return matched;
|
|
59
|
+
}
|
|
60
|
+
export function resolveCollectionForPath(entryPath, collectionsConfig, fallbackId = "content") {
|
|
61
|
+
if (collectionsConfig) {
|
|
62
|
+
for (const [colId, colConfig] of Object.entries(collectionsConfig)) {
|
|
63
|
+
if (colConfig.path && matchPathPatterns(entryPath, colConfig.path)) {
|
|
64
|
+
return colId;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return fallbackId;
|
|
69
|
+
}
|
|
70
|
+
export function extractTOC(md) {
|
|
71
|
+
const lines = md.split("\n");
|
|
72
|
+
const flat = [];
|
|
73
|
+
for (const line of lines) {
|
|
74
|
+
const m = line.match(/^(#{2,6})\s+(.+)/);
|
|
75
|
+
if (!m) continue;
|
|
76
|
+
const depth = m[1].length;
|
|
77
|
+
const rawText = m[2].trim().replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").replace(/[`*_~]/g, "");
|
|
78
|
+
flat.push({ id: slugifyHeading(rawText), text: rawText, depth });
|
|
79
|
+
}
|
|
80
|
+
const result = [];
|
|
81
|
+
let current2 = null;
|
|
82
|
+
for (const item of flat) {
|
|
83
|
+
if (item.depth === 2) {
|
|
84
|
+
current2 = { ...item, children: [] };
|
|
85
|
+
result.push(current2);
|
|
86
|
+
} else if (current2 && item.depth >= 3) {
|
|
87
|
+
current2.children = current2.children || [];
|
|
88
|
+
current2.children.push(item);
|
|
89
|
+
} else {
|
|
90
|
+
result.push(item);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
function parseInlineProps(propsStr) {
|
|
96
|
+
const inner = propsStr.replace(/^\{|\}$/g, "");
|
|
97
|
+
const result = {};
|
|
98
|
+
const re = /(\w+)="([^"]*)"/g;
|
|
99
|
+
let m;
|
|
100
|
+
while ((m = re.exec(inner)) !== null) {
|
|
101
|
+
result[m[1]] = m[2];
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
function escapeAttr(val) {
|
|
106
|
+
return val.replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
107
|
+
}
|
|
108
|
+
export function preprocessMDC(md) {
|
|
109
|
+
let out = md;
|
|
110
|
+
out = out.replace(
|
|
111
|
+
/:::(\w[\w-]*)(\{[^}]*\})?\s*\n([\s\S]*?):::/g,
|
|
112
|
+
(_match, type, propsStr, body) => {
|
|
113
|
+
const attrs = parseInlineProps(propsStr || "");
|
|
114
|
+
const cls = `mdc-${type}`;
|
|
115
|
+
const attrStr = Object.entries(attrs).map(([k, v]) => ` data-${k}="${escapeAttr(v)}"`).join("");
|
|
116
|
+
return `<div class="${cls}"${attrStr}>
|
|
117
|
+
${body.trim()}
|
|
118
|
+
</div>`;
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
out = out.replace(/::(\w[\w-]*)\s*\n([\s\S]*?)::/g, (_match, type, body) => {
|
|
122
|
+
return `<div class="mdc-${type}">
|
|
123
|
+
${body.trim()}
|
|
124
|
+
</div>`;
|
|
125
|
+
});
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { RequestEvent } from "nuxt/server";
|
|
2
|
+
import type { DocsSearchOptions, DocsSearchResponse } from "../../../../types";
|
|
3
|
+
export declare function registerEnsureCMSSynced(fn: (event: RequestEvent) => Promise<void>): void;
|
|
4
|
+
/**
|
|
5
|
+
* Sanitizes and formats an input search query for SQLite FTS5 MATCH expressions. Strips special
|
|
6
|
+
* operator characters that would otherwise trigger FTS5 syntax errors, cleans whitespace, and
|
|
7
|
+
* formats tokens with prefix matching ("token"*).
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildFtsQuery(query: string, operator?: "AND" | "OR"): string;
|
|
10
|
+
/**
|
|
11
|
+
* Rebuilds the FTS5 virtual table from current `_qarpeo_cms_entries` records. Can be used after
|
|
12
|
+
* schema migrations or to re-index all content.
|
|
13
|
+
*/
|
|
14
|
+
export declare function rebuildCMSFTS(event?: RequestEvent): Promise<{
|
|
15
|
+
total: number;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* High-performance edge search engine for documentation content. Queries the SQLite FTS5 full-text
|
|
19
|
+
* index with automatic fallback to LIKE search, splits markdown documents into heading-anchored
|
|
20
|
+
* sections, scores matches, and extracts highlighted context excerpts.
|
|
21
|
+
*/
|
|
22
|
+
export declare function searchDocs(event: RequestEvent, options?: DocsSearchOptions): Promise<DocsSearchResponse>;
|