verstak/frontend/src/lib/markdown/internalLinks.ts

52 lines
1.3 KiB
TypeScript

import { parseVerstakUrl } from './markdown';
export type InternalLinkType = 'case' | 'note' | 'file' | 'secret' | 'unknown';
export interface InternalLinkInfo {
type: InternalLinkType;
id: string;
label: string;
icon: string;
}
/**
* Parse a verstak:// href into structured info.
*/
export function getInternalLinkInfo(href: string): InternalLinkInfo | null {
const parsed = parseVerstakUrl(href);
if (!parsed) return null;
const map: Record<string, { type: InternalLinkType; icon: string }> = {
case: { type: 'case', icon: '📁' },
note: { type: 'note', icon: '📄' },
file: { type: 'file', icon: '📎' },
secret: { type: 'secret', icon: '🔐' },
};
const entry = map[parsed.type];
if (!entry) {
return { type: 'unknown', id: parsed.id, label: parsed.id, icon: '🔗' };
}
return {
type: entry.type,
id: parsed.id,
label: parsed.id,
icon: entry.icon,
};
}
/**
* Get a human-readable label for an internal link type.
* These should be overridden via i18n in the UI layer.
*/
export function getDefaultLabel(type: InternalLinkType, id: string): string {
switch (type) {
case 'secret': return 'Секрет';
case 'case': return 'Дело';
case 'note': return 'Заметка';
case 'file': return 'Файл';
default: return id;
}
}