mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 19:12:27 +08:00
Merge branch 'develop' of https://github.com/TriliumNext/Notes into develop
This commit is contained in:
commit
16cc4fadd7
@ -0,0 +1,13 @@
|
|||||||
|
import { describe, it, expect } from "vitest";
|
||||||
|
import { processMindmapContent } from "./note_content_fulltext.js";
|
||||||
|
|
||||||
|
describe("processMindmapContent", () => {
|
||||||
|
it("supports empty JSON", () => {
|
||||||
|
expect(processMindmapContent("{}")).toEqual("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports blank text / invalid JSON", () => {
|
||||||
|
expect(processMindmapContent("")).toEqual("");
|
||||||
|
expect(processMindmapContent(`{ "node": " }`)).toEqual("");
|
||||||
|
});
|
||||||
|
});
|
@ -131,52 +131,7 @@ class NoteContentFulltextExp extends Expression {
|
|||||||
|
|
||||||
content = content.replace(/ /g, " ");
|
content = content.replace(/ /g, " ");
|
||||||
} else if (type === "mindMap" && mime === "application/json") {
|
} else if (type === "mindMap" && mime === "application/json") {
|
||||||
let mindMapcontent = JSON.parse(content);
|
content = processMindmapContent(content);
|
||||||
|
|
||||||
// Define interfaces for the JSON structure
|
|
||||||
interface MindmapNode {
|
|
||||||
id: string;
|
|
||||||
topic: string;
|
|
||||||
children: MindmapNode[]; // Recursive structure
|
|
||||||
direction?: number;
|
|
||||||
expanded?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface MindmapData {
|
|
||||||
nodedata: MindmapNode;
|
|
||||||
arrows: any[]; // If you know the structure, replace `any` with the correct type
|
|
||||||
summaries: any[];
|
|
||||||
direction: number;
|
|
||||||
theme: {
|
|
||||||
name: string;
|
|
||||||
type: string;
|
|
||||||
palette: string[];
|
|
||||||
cssvar: Record<string, string>; // Object with string keys and string values
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recursive function to collect all topics
|
|
||||||
function collectTopics(node: MindmapNode): string[] {
|
|
||||||
// Collect the current node's topic
|
|
||||||
let topics = [node.topic];
|
|
||||||
|
|
||||||
// If the node has children, collect topics recursively
|
|
||||||
if (node.children && node.children.length > 0) {
|
|
||||||
for (const child of node.children) {
|
|
||||||
topics = topics.concat(collectTopics(child));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return topics;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start extracting from the root node
|
|
||||||
const topicsArray = collectTopics(mindMapcontent.nodedata);
|
|
||||||
|
|
||||||
// Combine topics into a single string
|
|
||||||
const topicsString = topicsArray.join(", ");
|
|
||||||
|
|
||||||
content = normalize(topicsString.toString());
|
|
||||||
} else if (type === "canvas" && mime === "application/json") {
|
} else if (type === "canvas" && mime === "application/json") {
|
||||||
interface Element {
|
interface Element {
|
||||||
type: string;
|
type: string;
|
||||||
@ -215,4 +170,63 @@ class NoteContentFulltextExp extends Expression {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function processMindmapContent(content: string) {
|
||||||
|
let mindMapcontent;
|
||||||
|
|
||||||
|
try {
|
||||||
|
mindMapcontent = JSON.parse(content);
|
||||||
|
} catch (e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define interfaces for the JSON structure
|
||||||
|
interface MindmapNode {
|
||||||
|
id: string;
|
||||||
|
topic: string;
|
||||||
|
children: MindmapNode[]; // Recursive structure
|
||||||
|
direction?: number;
|
||||||
|
expanded?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MindmapData {
|
||||||
|
nodedata: MindmapNode;
|
||||||
|
arrows: any[]; // If you know the structure, replace `any` with the correct type
|
||||||
|
summaries: any[];
|
||||||
|
direction: number;
|
||||||
|
theme: {
|
||||||
|
name: string;
|
||||||
|
type: string;
|
||||||
|
palette: string[];
|
||||||
|
cssvar: Record<string, string>; // Object with string keys and string values
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recursive function to collect all topics
|
||||||
|
function collectTopics(node?: MindmapNode): string[] {
|
||||||
|
if (!node) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect the current node's topic
|
||||||
|
let topics = [node.topic];
|
||||||
|
|
||||||
|
// If the node has children, collect topics recursively
|
||||||
|
if (node.children && node.children.length > 0) {
|
||||||
|
for (const child of node.children) {
|
||||||
|
topics = topics.concat(collectTopics(child));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return topics;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start extracting from the root node
|
||||||
|
const topicsArray = collectTopics(mindMapcontent.nodedata);
|
||||||
|
|
||||||
|
// Combine topics into a single string
|
||||||
|
const topicsString = topicsArray.join(", ");
|
||||||
|
|
||||||
|
return normalize(topicsString.toString());
|
||||||
|
}
|
||||||
|
|
||||||
export default NoteContentFulltextExp;
|
export default NoteContentFulltextExp;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user