From db9b34b49d036049db7556344acdab06a26d43c5 Mon Sep 17 00:00:00 2001 From: Aprillion Date: Sat, 4 Nov 2023 17:16:41 +0100 Subject: [PATCH] make all links from the answers external #340 --- app/root.css | 13 ------------- app/routes/index.tsx | 8 -------- app/server-utils/parsing-utils.spec.ts | 10 ++++------ app/server-utils/parsing-utils.ts | 4 ++-- app/server-utils/stampy.ts | 4 ++-- public/assets/Icon_External_Link.svg | 5 ----- 6 files changed, 8 insertions(+), 36 deletions(-) delete mode 100644 public/assets/Icon_External_Link.svg diff --git a/app/root.css b/app/root.css index c6ee6237..e082d5dc 100644 --- a/app/root.css +++ b/app/root.css @@ -818,19 +818,6 @@ a.see-more.visible:after { content: 'See less'; } -a[target='_blank']:not(.icon-link, .transparent-link):after { - content: ' '; - display: inline-block; - vertical-align: top; - width: 12px; - height: 12px; - margin-left: 2px; - /* Chrome doesn't suppot non-prefix mask yet and we don't use post-css */ - -webkit-mask: url('/assets/Icon_External_Link.svg') no-repeat center center; - -webkit-mask-size: cover; - background-color: currentColor; -} - .error { color: red; } diff --git a/app/routes/index.tsx b/app/routes/index.tsx index 353c7ab2..f1b7f1d5 100644 --- a/app/routes/index.tsx +++ b/app/routes/index.tsx @@ -10,7 +10,6 @@ import {loadInitialQuestions, loadTags, QuestionState} from '~/server-utils/stam import {TOP} from '~/hooks/stateModifiers' import useQuestionStateInUrl from '~/hooks/useQuestionStateInUrl' import useDraggable from '~/hooks/useDraggable' -import {getStateEntries} from '~/hooks/stateModifiers' import Search from '~/components/search' import {Header, Footer} from '~/components/layouts' import {LINK_WITHOUT_DETAILS_CLS, Question} from '~/routes/questions/$question' @@ -172,13 +171,6 @@ export default function App() { showMore(el) return } - - const url = new URL(el.href) - if (url.hostname === window.location.hostname) { - e.preventDefault() - const state = new URLSearchParams(url.search).get('state') - if (state) selectQuestion(getStateEntries(state)[0][0], '') - } } const nextPageLinkRef = useRef(null) diff --git a/app/server-utils/parsing-utils.spec.ts b/app/server-utils/parsing-utils.spec.ts index 7771987e..1cfd13bc 100644 --- a/app/server-utils/parsing-utils.spec.ts +++ b/app/server-utils/parsing-utils.spec.ts @@ -1,4 +1,4 @@ -import {urlToIframe, uniqueFootnotes, externalLinksOnNewTab} from './parsing-utils' +import {urlToIframe, uniqueFootnotes, allLinksOnNewTab} from './parsing-utils' describe('urlToIframe', () => { describe('should not convert a markdown link', () => { @@ -79,16 +79,14 @@ describe('uniqueFootnotes', () => { describe('externalLinksOnNewTab', () => { test('no link', () => { - expect(externalLinksOnNewTab('gg')).toBe('gg') + expect(allLinksOnNewTab('gg')).toBe('gg') }) test('text with internal and external links', () => { expect( - externalLinksOnNewTab( - 'x gg and hh y' - ) + allLinksOnNewTab('x gg and hh y') ).toBe( - 'x gg and hh y' + 'x gg and hh y' ) }) }) diff --git a/app/server-utils/parsing-utils.ts b/app/server-utils/parsing-utils.ts index 6769bc5f..570e4f93 100644 --- a/app/server-utils/parsing-utils.ts +++ b/app/server-utils/parsing-utils.ts @@ -90,9 +90,9 @@ export const cleanUpDoubleBold = (html: string): string => { return html.replaceAll('**', '') } -export const externalLinksOnNewTab = (html: string): string => { +export const allLinksOnNewTab = (html: string): string => { // Open external links on new tab by using target="_blank", // pros&cons were extensively discussed in https://github.com/StampyAI/stampy-ui/issues/222 // internal links look like , so all absolute http links are treated as external - return html.replace(/( { let html = convertToHtmlAndWrapInDetails(markdown) html = uniqueFootnotes(html, pageid) html = cleanUpDoubleBold(html) - html = externalLinksOnNewTab(html) + html = allLinksOnNewTab(html) return html } diff --git a/public/assets/Icon_External_Link.svg b/public/assets/Icon_External_Link.svg deleted file mode 100644 index f727beee..00000000 --- a/public/assets/Icon_External_Link.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file