feat: add public wiki embeds and ES query routing
This commit is contained in:
1 parent
e818c24769
commit
bc49df4561
16 files changed
+704
-52
No files matched your search
@@ -114,6 +114,24 @@ export function buildWeKnoraWikiPagePath(
|
||||
return `/page/workspace/knowledge/${encodeURIComponent(knowledgeBaseId)}/wiki/view?${params.toString()}`;
|
||||
}
|
||||
|
||||
/** Public, chrome-free Wiki reader intended for third-party iframe embedding. */
|
||||
export function buildPublicKnowledgeWikiPath(
|
||||
knowledgeBaseId: string,
|
||||
wikiSlug?: string,
|
||||
): string {
|
||||
const params = new URLSearchParams();
|
||||
if (wikiSlug) params.set("wikiSlug", wikiSlug);
|
||||
const query = params.toString();
|
||||
return `/embed/knowledge/${encodeURIComponent(knowledgeBaseId)}${query ? `?${query}` : ""}`;
|
||||
}
|
||||
|
||||
export function buildPublicKnowledgeWikiUrl(
|
||||
knowledgeBaseId: string,
|
||||
wikiSlug?: string,
|
||||
): string {
|
||||
return `/#${buildPublicKnowledgeWikiPath(knowledgeBaseId, wikiSlug)}`;
|
||||
}
|
||||
|
||||
export function buildLegacyKnowledgeSourceUrl(source: KnowledgeSourceLike): string {
|
||||
const recUuid = source.recUuid || source.rec_uuid || source.url || "";
|
||||
if (!recUuid) return "";
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { buildWeKnoraWikiPageUrl } from "@/core/llmwiki/source-links";
|
||||
|
||||
export type WikiPageUrlBuilder = (
|
||||
knowledgeBaseId: string,
|
||||
wikiSlug: string,
|
||||
) => string;
|
||||
|
||||
export function stripWikiFrontmatter(value: string) {
|
||||
return value.replace(/^\s*---\s*\n[\s\S]*?\n---\s*(?:\n|$)/, "").trim();
|
||||
}
|
||||
@@ -16,12 +21,16 @@ export function exportableWikiMarkdown(title: string, summary: string, content:
|
||||
.join("\n\n");
|
||||
}
|
||||
|
||||
export function wikiLinkMarkdown(markdown: string, knowledgeBaseId: string) {
|
||||
export function wikiLinkMarkdown(
|
||||
markdown: string,
|
||||
knowledgeBaseId: string,
|
||||
buildPageUrl: WikiPageUrlBuilder = buildWeKnoraWikiPageUrl,
|
||||
) {
|
||||
const link = (slugValue: string, labelValue?: string) => {
|
||||
const slug = slugValue.trim();
|
||||
const fallbackLabel = slug.split("/").filter(Boolean).at(-1) || slug;
|
||||
const label = (labelValue || fallbackLabel).trim().replace(/\]/g, "\\]");
|
||||
return `[${label}](${buildWeKnoraWikiPageUrl(knowledgeBaseId, slug)})`;
|
||||
return `[${label}](${buildPageUrl(knowledgeBaseId, slug)})`;
|
||||
};
|
||||
return markdown
|
||||
.replace(/\[\[([^\]|]+)\|([^\]]+)\]\]/g, (_match, slug, label) => link(slug, label))
|
||||
@@ -33,6 +42,7 @@ export function renderableWikiMarkdown(
|
||||
title: string,
|
||||
content: string,
|
||||
knowledgeBaseId: string,
|
||||
buildPageUrl?: WikiPageUrlBuilder,
|
||||
) {
|
||||
const lines = content.trim().split("\n");
|
||||
if (lines[0]?.replace(/^#+\s*/, "").trim() === title.trim()) {
|
||||
@@ -41,5 +51,6 @@ export function renderableWikiMarkdown(
|
||||
return wikiLinkMarkdown(
|
||||
exportableWikiMarkdown(title, "", lines.join("\n")),
|
||||
knowledgeBaseId,
|
||||
buildPageUrl,
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user