Files
tolaria/src/utils/wikilink.ts
lucaronin b8c3a7302c refactor: extract wikilink utils to src/utils/wikilink.ts, fix NoteList useMemo deps
- Move wikilinkTarget/wikilinkDisplay from InspectorPanels.tsx to src/utils/wikilink.ts
  (fixes react-refresh/only-export-components lint error — non-component exports
  must live in utility files, not component files)
- Remove unused modifiedFiles from useNoteListData deps array and interface
  (fixes react-hooks/exhaustive-deps warning — was in dep array but not used)
2026-02-23 21:55:57 +01:00

18 lines
778 B
TypeScript

/** Utility functions for parsing wikilink syntax: [[target|display]] */
/** Extracts the target path from a wikilink reference (strips [[ ]] and display text). */
export function wikilinkTarget(ref: string): string {
const inner = ref.replace(/^\[\[|\]\]$/g, '')
const pipeIdx = inner.indexOf('|')
return pipeIdx !== -1 ? inner.slice(0, pipeIdx) : inner
}
/** Extracts the display label from a wikilink reference. Falls back to humanised path stem. */
export function wikilinkDisplay(ref: string): string {
const inner = ref.replace(/^\[\[|\]\]$/g, '')
const pipeIdx = inner.indexOf('|')
if (pipeIdx !== -1) return inner.slice(pipeIdx + 1)
const last = inner.split('/').pop() ?? inner
return last.replace(/-/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase())
}