From efae1a9f6d395a9c68661017bc29ccdfae1ab75c Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Mon, 2 Oct 2023 10:39:46 -0700 Subject: [PATCH 1/2] feat: replace content links in body --- lib/api-helpers.ts | 5 +++++ src/routes/view-news.tsx | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/api-helpers.ts b/lib/api-helpers.ts index 35fe110..781f4a9 100644 --- a/lib/api-helpers.ts +++ b/lib/api-helpers.ts @@ -46,6 +46,11 @@ export function padNumber(num: number, size = 10) { return s; } +// replaces relative /content links with /api/content links +export function replaceContentLinks(content: string) { + return content.replace(/\/content\//g, '/api/content/'); +} + ///////////////////////// // GETTERS ///////////////////////// diff --git a/src/routes/view-news.tsx b/src/routes/view-news.tsx index f81df92..3ea444a 100644 --- a/src/routes/view-news.tsx +++ b/src/routes/view-news.tsx @@ -12,6 +12,7 @@ import { } from '@chakra-ui/react'; import { useEffect, useMemo, useState } from 'react'; import { Link, useLocation } from 'react-router-dom'; +import { replaceContentLinks } from '../../lib/api-helpers'; import { InscriptionMeta, OrdinalNews } from '../../lib/api-types'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; @@ -244,7 +245,7 @@ export default function ViewNews() { /> Date: Mon, 2 Oct 2023 17:00:37 -0700 Subject: [PATCH 2/2] fix: use more specific regex --- lib/api-helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/api-helpers.ts b/lib/api-helpers.ts index 781f4a9..65a5095 100644 --- a/lib/api-helpers.ts +++ b/lib/api-helpers.ts @@ -48,7 +48,7 @@ export function padNumber(num: number, size = 10) { // replaces relative /content links with /api/content links export function replaceContentLinks(content: string) { - return content.replace(/\/content\//g, '/api/content/'); + return content.replace(/="\/content\//g, '="/api/content/'); } /////////////////////////