From 6b81bab02bc1cf4abef1cd462c0148fac6f3c185 Mon Sep 17 00:00:00 2001 From: Silberengel Date: Mon, 10 Nov 2025 09:26:27 +0100 Subject: [PATCH] article redirect --- .../Note/MarkdownArticle/MarkdownArticle.tsx | 13 ++++++++++++- src/services/content-parser.service.ts | 12 +++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/components/Note/MarkdownArticle/MarkdownArticle.tsx b/src/components/Note/MarkdownArticle/MarkdownArticle.tsx index 4890699..d4d0312 100644 --- a/src/components/Note/MarkdownArticle/MarkdownArticle.tsx +++ b/src/components/Note/MarkdownArticle/MarkdownArticle.tsx @@ -42,8 +42,19 @@ export default function MarkdownArticle({ const contentRef = useRef(null) // Preprocess content to convert plain media URLs to markdown syntax + // Also convert "Read naddr... instead." patterns to hyperlinks const processedContent = useMemo(() => { - return preprocessMediaLinks(event.content) + let content = preprocessMediaLinks(event.content) + + // Convert "Read naddr... instead." patterns to markdown links for replaceable events + // This is a standard format for forwarding readers to referred events (e.g., in wikis) + const redirectRegex = /Read (naddr1[a-z0-9]+) instead\./gi + content = content.replace(redirectRegex, (match, naddr) => { + const href = toNote(naddr) + return `Read [${naddr}](${href}) instead.` + }) + + return content }, [event.content]) // Use unified media extraction service diff --git a/src/services/content-parser.service.ts b/src/services/content-parser.service.ts index d645b83..cd1af4e 100644 --- a/src/services/content-parser.service.ts +++ b/src/services/content-parser.service.ts @@ -85,11 +85,21 @@ class ContentParserService { // Check for LaTeX math const hasMath = enableMath && this.hasMathContent(content) + // Preprocess content: Convert "Read naddr... instead." patterns to hyperlinks + // This is a standard format for forwarding readers to referred events (e.g., in wikis) + let preprocessedContent = content + const redirectRegex = /Read (naddr1[a-z0-9]+) instead\./gi + preprocessedContent = preprocessedContent.replace(redirectRegex, (_match, naddr) => { + // Convert to AsciiDoc link format pointing to the note page + // Use a regular HTTP link format that will be processed as a normal link + return `Read link:/notes/${naddr}[${naddr}] instead.` + }) + let html = '' try { // Convert everything to AsciiDoc format and process as AsciiDoc - const asciidocContent = this.convertToAsciidoc(content, markupType) + const asciidocContent = this.convertToAsciidoc(preprocessedContent, markupType) html = await this.parseAsciidoc(asciidocContent, { enableMath, enableSyntaxHighlighting }) } catch (error) { logger.error('Content parsing error', { error })