Skip to content

Build your personal knowledge base with Trilium Notes

feat(badges/content): basic support for backend scripts

Elian Dorana68e82c1c894
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 48f5707563..8717ecac23 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2291,6 +2291,7 @@
},
"active_content_badges": {
"type_icon_pack": "Icon pack",
+ "type_backend_script": "Backend script",
"toggle_tooltip_enable_tooltip": "Click to enable this {{type}}.",
"toggle_tooltip_disable_tooltip": "Click to disable this {{type}}."
}
diff --git a/apps/client/src/widgets/layout/ActiveContentBadges.tsx b/apps/client/src/widgets/layout/ActiveContentBadges.tsx
index 6f93ada5cb..dc867d8828 100644
--- a/apps/client/src/widgets/layout/ActiveContentBadges.tsx
+++ b/apps/client/src/widgets/layout/ActiveContentBadges.tsx
@@ -11,34 +11,50 @@ import { useNoteContext, useTriliumEvent } from "../react/hooks";
const DANGEROUS_ATTRIBUTES = BUILTIN_ATTRIBUTES.filter(a => a.isDangerous);
const activeContentLabels = [ "iconPack" ] as const;
+const typeIconMappings: Record<ActiveContentInfo["type"], string> = {
+ iconPack: "bx bx-package",
+ backendScript: "bx bx-server"
+};
+
export function ActiveContentBadges() {
const { note } = useNoteContext();
const info = useActiveContentInfo(note);
return (note && info &&
<>
- {info.type === "iconPack" && <IconPackBadge />}
+ <ActiveContentBadge info={info} note={note} />
<ActiveContentToggle info={info} note={note} />
</>
);
}
-function IconPackBadge() {
+function ActiveContentBadge({ info }: { note: FNote, info: ActiveContentInfo }) {
return (
<Badge
className="icon-pack-badge"
- icon="bx bx-package"
- text={t("active_content_badges.type_icon_pack")}
+ icon={typeIconMappings[info.type]}
+ text={getTranslationForType(info.type)}
/>
);
}
+function getTranslationForType(type: ActiveContentInfo["type"]) {
+ switch (type) {
+ case "iconPack":
+ return t("active_content_badges.type_icon_pack");
+ case "backendScript":
+ return t("active_content_badges.type_backend_script");
+ }
+}
+
function ActiveContentToggle({ note, info }: { note: FNote, info: ActiveContentInfo }) {
+ const typeTranslation = getTranslationForType(info.type);
+
return info && <FormToggle
switchOnName="" switchOffName=""
currentValue={info.isEnabled}
- switchOnTooltip={t("active_content_badges.toggle_tooltip_disable_tooltip", { type: t("active_content_badges.type_icon_pack") })}
- switchOffTooltip={t("active_content_badges.toggle_tooltip_enable_tooltip", { type: t("active_content_badges.type_icon_pack") })}
+ switchOnTooltip={t("active_content_badges.toggle_tooltip_disable_tooltip", { type: typeTranslation })}
+ switchOffTooltip={t("active_content_badges.toggle_tooltip_enable_tooltip", { type: typeTranslation })}
onChange={async (willEnable) => {
const attrs = note.getOwnedAttributes()
.filter(attr => {
@@ -65,7 +81,7 @@ function getNameWithoutPrefix(name: string) {
}
interface ActiveContentInfo {
- type: "iconPack";
+ type: "iconPack" | "backendScript";
isEnabled: boolean;
}
@@ -81,6 +97,10 @@ function useActiveContentInfo(note: FNote | null | undefined) {
return;
}
+ if (note.type === "code" && note.mime === "application/javascript;env=backend") {
+ type = "backendScript";
+ }
+
for (const labelToCheck of activeContentLabels ) {
if (note.hasLabel(labelToCheck)) {
type = labelToCheck;