π The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
feat(tags): color tags by name instead of a single accent (#654)
Stiven Gjekaj74ad5ad00f8e
diff --git a/frontend/app/components/AppTagInput.vue b/frontend/app/components/AppTagInput.vueindex 18a4f29b..df44b805 100644--- a/frontend/app/components/AppTagInput.vue+++ b/frontend/app/components/AppTagInput.vue@@ -33,7 +33,7 @@</div></div><div v-if="selectedTags?.length" :class="`selected-tags `">- <span v-for="tag in selectedTags" :key="tag" class="tag-chip">+ <span v-for="tag in selectedTags" :key="tag" class="tag-chip" :class="resolveTagColor(tag)">{{ tag }}<button class="remove-tag" @click.stop="removeTag(tag)">Γ</button></span>@@ -42,6 +42,8 @@</template><script setup lang="ts">+import { resolveTagColor } from '~/helpers/node';+const props = defineProps<{display?: 'column' | 'row';minimal?: boolean;@@ -244,7 +246,6 @@ input {padding: 3px 6px;border-radius: var(--radius-lg);font-size: 12px;- background: var(--border);.remove-tag {display: flex;diff --git a/frontend/app/components/Node/TagList.vue b/frontend/app/components/Node/TagList.vueindex d6397c1f..0b9cd7c2 100644--- a/frontend/app/components/Node/TagList.vue+++ b/frontend/app/components/Node/TagList.vue@@ -1,11 +1,11 @@<template><div v-if="parsedTags.length" class="tags">- <tag v-for="tag in parsedTags" :key="tag" class="primary" :class="{ clickable }" @click="onClick($event, tag)">{{ tag }}</tag>+ <tag v-for="tag in parsedTags" :key="tag" :class="[resolveTagColor(tag), { clickable }]" @click="onClick($event, tag)">{{ tag }}</tag></div></template><script setup lang="ts">-import { parseTags } from '~/helpers/node';+import { parseTags, resolveTagColor } from '~/helpers/node';const props = withDefaults(defineProps<{ tags?: string; clickable?: boolean }>(), { tags: '', clickable: true });diff --git a/frontend/app/helpers/markdown/anchor.ts b/frontend/app/helpers/markdown/anchor.tsindex cafb9ffb..8bf9bdea 100644--- a/frontend/app/helpers/markdown/anchor.ts+++ b/frontend/app/helpers/markdown/anchor.ts@@ -1,4 +1,4 @@-import type MarkdownIt from 'markdown-it';+import type { MarkdownIt } from 'markdown-it';import anchor from 'markdown-it-anchor';export const anchorPlugin = (md: MarkdownIt) => {diff --git a/frontend/app/helpers/markdown/cards.ts b/frontend/app/helpers/markdown/cards.tsindex 1fd9294d..c3e98aea 100644--- a/frontend/app/helpers/markdown/cards.ts+++ b/frontend/app/helpers/markdown/cards.ts@@ -1,6 +1,5 @@-import type MarkdownIt from 'markdown-it';+import type { MarkdownIt, Token } from 'markdown-it';import container from 'markdown-it-container';-import type Token from 'markdown-it/lib/token.mjs';interface BlockDef {name: string;diff --git a/frontend/app/helpers/markdown/checkbox.ts b/frontend/app/helpers/markdown/checkbox.tsindex da5d4eff..77a90897 100644--- a/frontend/app/helpers/markdown/checkbox.ts+++ b/frontend/app/helpers/markdown/checkbox.ts@@ -1,5 +1,4 @@-import type MarkdownIt from 'markdown-it';-import type { StateCore } from 'markdown-it/dist/index.cjs.js';+import type { MarkdownIt, StateCore } from 'markdown-it';function markdownItCheckbox(md: MarkdownIt) {// Add a core rule to process checkboxesdiff --git a/frontend/app/helpers/markdown/code-block.ts b/frontend/app/helpers/markdown/code-block.tsindex 6f4ddd19..b231e019 100644--- a/frontend/app/helpers/markdown/code-block.ts+++ b/frontend/app/helpers/markdown/code-block.ts@@ -1,4 +1,4 @@-import type MarkdownIt from 'markdown-it';+import type { MarkdownIt } from 'markdown-it';/*** Markdown-it plugin to add a "copy to clipboard" button to code blocks.diff --git a/frontend/app/helpers/markdown/colors.ts b/frontend/app/helpers/markdown/colors.tsindex 3c6dfde9..21962a9c 100644--- a/frontend/app/helpers/markdown/colors.ts+++ b/frontend/app/helpers/markdown/colors.ts@@ -1,5 +1,4 @@-import type MarkdownIt from 'markdown-it';-import type { StateInline } from 'markdown-it/dist/index.cjs.js';+import type { MarkdownIt, StateInline } from 'markdown-it';export type ColorPluginOptions = {/** Also enable the bracket style: [text]{color=value} */diff --git a/frontend/app/helpers/markdown/container.ts b/frontend/app/helpers/markdown/container.tsindex 2a6b84eb..de76069f 100644--- a/frontend/app/helpers/markdown/container.ts+++ b/frontend/app/helpers/markdown/container.ts@@ -1,6 +1,5 @@-import type MarkdownIt from 'markdown-it';+import type { MarkdownIt, RendererRule } from 'markdown-it';import container from 'markdown-it-container';-import type { RenderRule } from 'markdown-it/lib/renderer.mjs';// eslint-disable-next-line @typescript-eslint/no-explicit-anyconst containerPlugin_ = container as any;@@ -19,7 +18,7 @@ export const containerPlugin = (md: MarkdownIt) => {.use(...createInvisibleContainer('column'));};-type ContainerArgs = [typeof containerPlugin_, string, { render: RenderRule }];+type ContainerArgs = [typeof containerPlugin_, string, { render: RendererRule }];function createContainer(klass: string, defaultTitle: string, md: MarkdownIt): ContainerArgs {return [diff --git a/frontend/app/helpers/markdown/containers-svg.ts b/frontend/app/helpers/markdown/containers-svg.tsindex d3ba3837..2c5da524 100644--- a/frontend/app/helpers/markdown/containers-svg.ts+++ b/frontend/app/helpers/markdown/containers-svg.ts@@ -1,5 +1,5 @@/* eslint-disable @typescript-eslint/no-explicit-any */-import type MarkdownIt from 'markdown-it';+import type { MarkdownIt } from 'markdown-it';import container from 'markdown-it-container';import { svg_info, svg_warning, containerOpen } from './constants';diff --git a/frontend/app/helpers/markdown/internal-links.ts b/frontend/app/helpers/markdown/internal-links.tsindex f649e16b..2b50152f 100644--- a/frontend/app/helpers/markdown/internal-links.ts+++ b/frontend/app/helpers/markdown/internal-links.ts@@ -1,5 +1,4 @@-import type MarkdownIt from 'markdown-it';-import type { StateInline } from 'markdown-it/dist/index.cjs.js';+import type { MarkdownIt, StateInline } from 'markdown-it';// Internal links: #726782907684193440 => link to the document, displayed as "#<document name>"export const INTERNAL_LINK_REGEX = /#(\d{15,20})(?!\d)/g;@@ -35,7 +34,7 @@ export function internalLinkPlugin(md: MarkdownIt) {});md.renderer.rules.internal_link = (tokens, idx, options, env) => {- const id: string = tokens[idx]?.meta?.id || '';+ const id = String(tokens[idx]?.meta?.id ?? '');const name = (env as InternalLinkEnv)?.resolveNode?.(id);const label = md.utils.escapeHtml(name ? `#${name}` : `#${id}`);return `<a href="/dashboard/docs/${id}" class="internal-link" data-internal-link="${id}">${label}</a>`;diff --git a/frontend/app/helpers/markdown/katex.ts b/frontend/app/helpers/markdown/katex.tsindex 54de3461..f728d8c6 100644--- a/frontend/app/helpers/markdown/katex.ts+++ b/frontend/app/helpers/markdown/katex.ts@@ -1,6 +1,5 @@import { renderToString } from 'katex';-import type MarkdownIt from 'markdown-it';-import type { StateInline } from 'markdown-it/dist/index.cjs.js';+import type { MarkdownIt, StateInline } from 'markdown-it';function markdownItKatexPlugin(md: MarkdownIt) {md.inline.ruler.after('escape', 'katex', (state: StateInline, silent: boolean) => {diff --git a/frontend/app/helpers/markdown/mermaid.ts b/frontend/app/helpers/markdown/mermaid.tsindex 945b6356..e18379bd 100644--- a/frontend/app/helpers/markdown/mermaid.ts+++ b/frontend/app/helpers/markdown/mermaid.ts@@ -1,4 +1,4 @@-import type MarkdownIt from 'markdown-it';+import type { MarkdownIt } from 'markdown-it';export const MERMAID_OPEN_RE = /^:{3,}mermaid\s*$/;export const MERMAID_CLOSE_RE = /^:{3,}\s*$/;diff --git a/frontend/app/helpers/markdown/other.ts b/frontend/app/helpers/markdown/other.tsindex 8a43c923..b16d0795 100644--- a/frontend/app/helpers/markdown/other.ts+++ b/frontend/app/helpers/markdown/other.ts@@ -1,5 +1,4 @@-import type MarkdownIt from 'markdown-it';-import type { StateInline } from 'markdown-it/dist/index.cjs.js';+import type { Env, MarkdownIt, StateInline } from 'markdown-it';function superscriptPlugin(md: MarkdownIt) {md.inline.ruler.after('emphasis', 'superscript', (state: StateInline, silent: boolean) => {@@ -104,14 +103,14 @@ function footNotePlugin(md: MarkdownIt) {});md.renderer.rules.footnote_ref = (tokens, idx) => {- const id = tokens[idx]?.meta.id;+ const id = String(tokens[idx]?.meta?.id ?? '');const content = footnotes.get(id) || '';return `<sup class="footnote-ref"><a href="#fn-${id}" id="fnref-${id}" title="${md.utils.escapeHtml(content)}">[${id}]</a></sup>`;};// Add footnotes section at the endconst originalRender = md.render.bind(md);- md.render = (src: string, env?: object) => {+ md.render = (src: string, env?: Env) => {footnotes.clear();let result = originalRender(src, env);@@ -141,7 +140,7 @@ function html5MediaPlugin(md: MarkdownIt) {const token = tokens[idx];if (!token) return '';- const src = token.attrGet('src') || '';+ const src = String(token.attrGet('src') ?? '');let alt = token.content || '';// Parse: "Alt text | 100x200", "Alt | 100x", "Alt | x200", "Alt | 100"@@ -189,9 +188,9 @@ function svgObjectPlugin(md: MarkdownIt) {const token = tokens[idx];if (!token) return '';- const src = token.attrGet('src') || '';+ const src = String(token.attrGet('src') ?? '');const alt = token.content || '';- const title = token.attrGet('title') || '';+ const title = String(token.attrGet('title') ?? '');if (SVG_REGEX.test(src)) {const escapedSrc = md.utils.escapeHtml(src);diff --git a/frontend/app/helpers/markdown/source-map.ts b/frontend/app/helpers/markdown/source-map.tsindex 9616c62d..b5a4c3c2 100644--- a/frontend/app/helpers/markdown/source-map.ts+++ b/frontend/app/helpers/markdown/source-map.ts@@ -1,5 +1,4 @@-import type MarkdownIt from 'markdown-it';-import type Token from 'markdown-it/lib/token.mjs';+import type { MarkdownIt, Token } from 'markdown-it';/*** markdown-it plugin that injects `data-source-line` attributes on block-leveldiff --git a/frontend/app/helpers/markdown/tooltip.ts b/frontend/app/helpers/markdown/tooltip.tsindex 134f49fd..1dcdba16 100644--- a/frontend/app/helpers/markdown/tooltip.ts+++ b/frontend/app/helpers/markdown/tooltip.ts@@ -1,5 +1,4 @@-import type MarkdownIt from 'markdown-it';-import type { StateInline } from 'markdown-it/dist/index.cjs.js';+import type { MarkdownIt, StateInline } from 'markdown-it';/*** Tooltips β reuses the application's `.hint-tooltip` CSS (#618).@@ -95,7 +94,7 @@ export function tooltipPlugin(md: MarkdownIt) {});md.renderer.rules.tooltip_marker = (tokens, idx) => {- const hint: string = tokens[idx]?.meta?.hint || '';+ const hint = String(tokens[idx]?.meta?.hint ?? '');return (`<span class="md-tooltip md-tooltip-marker" tabindex="0">` +`<span class="md-tooltip-icon">i</span>` +@@ -105,7 +104,7 @@ export function tooltipPlugin(md: MarkdownIt) {};md.renderer.rules.tooltip_hint = (tokens, idx) => {- const hint: string = tokens[idx]?.meta?.hint || '';+ const hint = String(tokens[idx]?.meta?.hint ?? '');return `<span class="hint-tooltip">${md.utils.escapeHtml(hint)}</span>`;};}diff --git a/frontend/app/helpers/markdown/underline.ts b/frontend/app/helpers/markdown/underline.tsindex 3a3f6106..a0fc452f 100644--- a/frontend/app/helpers/markdown/underline.ts+++ b/frontend/app/helpers/markdown/underline.ts@@ -1,10 +1,7 @@-import type { Options } from 'markdown-it';-import type MarkdownIt from 'markdown-it';-import type Renderer from 'markdown-it/lib/renderer.mjs';-import type Token from 'markdown-it/lib/token.mjs';+import type { MarkdownIt, MarkdownItOptions, Renderer, Token } from 'markdown-it';export default function markdownItUnderline(md: MarkdownIt) {- function renderEm(tokens: Token[], idx: number, opts: Options, _: unknown, slf: Renderer) {+ function renderEm(tokens: Token[], idx: number, opts: Required<MarkdownItOptions>, _: unknown, slf: Renderer) {const token = tokens[idx];if (token?.markup === '__') {token.tag = 'u';diff --git a/frontend/app/helpers/node.ts b/frontend/app/helpers/node.tsindex 80f729bc..5ce17bef 100644--- a/frontend/app/helpers/node.ts+++ b/frontend/app/helpers/node.ts@@ -2,6 +2,7 @@* Node utilities - centralized helpers for working with nodes (documents, categories, workspaces, teams, resources)* Roles: 0 = Team, 1 = Workspace, 2 = Category, 3 = Document, 4 = Resource*/+import { appColors } from '~/helpers/constants';import type { DB_Node, Node, NodeSearchResult } from '~/stores';/** Resolve the appropriate icon for a node based on its role and properties */@@ -97,6 +98,20 @@ export function parseTags(tags: string): string[] {return [];}+/**+ * Resolve a palette color for a tag from its name, so tags on a note are visually+ * distinct instead of all sharing one color. The mapping is a hash of the name, so a+ * given tag always keeps the same color everywhere without storing anything.+ */+export function resolveTagColor(tag: string): string {+ const name = tag.trim().toLowerCase();+ let hash = 0;+ for (let i = 0; i < name.length; i++) {+ hash = (Math.imul(hash, 31) + name.charCodeAt(i)) | 0;+ }+ return appColors[Math.abs(hash) % appColors.length] || 'blue';+}+export function mergeNode(node: Node, full_node: Node): Node {const result: Node = { ...node };diff --git a/frontend/app/styles/themes/dark.scss b/frontend/app/styles/themes/dark.scssindex a1222d2e..a2e939c3 100644--- a/frontend/app/styles/themes/dark.scss+++ b/frontend/app/styles/themes/dark.scss@@ -100,7 +100,7 @@--purple-bg-light: rgb(142 95 255 / 5%);--purple-border: rgb(142 95 255 / 25%);// PINKS- --pink: #fe3938;+ --pink: #ff4da6;--pink-dark: #e00b58;--pink-bg: rgb(255 77 166 / 12%);--pink-bg-light: rgb(255 77 166 / 5%);