2025-01-09 18:36:24 +02:00
|
|
|
import type { Request } from "express";
|
2024-04-06 21:58:32 +03:00
|
|
|
|
2024-07-18 21:35:17 +03:00
|
|
|
import becca from "../../becca/becca.js";
|
|
|
|
import markdownService from "../../services/import/markdown.js";
|
2023-03-29 22:40:50 +02:00
|
|
|
|
|
|
|
function getIconUsage() {
|
2024-04-06 21:58:32 +03:00
|
|
|
const iconClassToCountMap: Record<string, number> = {};
|
2023-03-29 22:40:50 +02:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
for (const { value: iconClass, noteId } of becca.findAttributes("label", "iconClass")) {
|
2023-03-29 22:40:50 +02:00
|
|
|
if (noteId.startsWith("_")) {
|
|
|
|
continue; // ignore icons of "system" notes since they were not set by the user
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!iconClass?.trim()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const clazz of iconClass.trim().split(/\s+/)) {
|
2025-01-09 18:07:02 +02:00
|
|
|
if (clazz === "bx") {
|
2023-03-29 22:40:50 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
iconClassToCountMap[clazz] = (iconClassToCountMap[clazz] || 0) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { iconClassToCountMap };
|
|
|
|
}
|
|
|
|
|
2024-04-06 21:58:32 +03:00
|
|
|
function renderMarkdown(req: Request) {
|
2023-07-15 10:31:50 +02:00
|
|
|
const { markdownContent } = req.body;
|
|
|
|
|
|
|
|
return {
|
2025-01-09 18:07:02 +02:00
|
|
|
htmlContent: markdownService.renderToHtml(markdownContent, "")
|
2023-07-15 10:31:50 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-07-18 21:47:30 +03:00
|
|
|
export default {
|
2023-07-15 10:31:50 +02:00
|
|
|
getIconUsage,
|
|
|
|
renderMarkdown
|
2023-03-29 22:40:50 +02:00
|
|
|
};
|