From 29c390709d07c67368e80993d10da2e2517c4054 Mon Sep 17 00:00:00 2001 From: Christopher Gurnee Date: Wed, 30 Mar 2022 01:05:45 +0000 Subject: [PATCH] Fix some post link issues * Only redirect Reddit post links to Unddit if it's likely to work. * Use React s instead of s if the post link matches the post itself. This avoids an unnecessary page reload if clicked. * Relative links in comments still don't work well... --- TODO | 3 --- src/pages/common/Post.js | 29 ++++++++++++++++++++--------- 2 files changed, 20 insertions(+), 12 deletions(-) delete mode 100644 TODO diff --git a/TODO b/TODO deleted file mode 100644 index a7c3715..0000000 --- a/TODO +++ /dev/null @@ -1,3 +0,0 @@ -old.removeddit.com - -take utc from thread and limit pushshift comments diff --git a/src/pages/common/Post.js b/src/pages/common/Post.js index 89b864d..3857463 100644 --- a/src/pages/common/Post.js +++ b/src/pages/common/Post.js @@ -13,9 +13,9 @@ export default (props) => {
?
-
+
- [removed too quickly to be archived] + [removed too quickly to be archived]
reddit  reveddit @@ -27,7 +27,17 @@ export default (props) => { return
} - const url = props.url.replace('https://www.reddit.com', '') + let url = new URL(props.url, 'https://www.reddit.com') + if ((url.hostname.endsWith('.reddit.com') || url.hostname == 'reddit.com') && + url.pathname.match(/^\/(?:r|user)\/[^/]+\/comments\/./)) { + url.protocol = document.location.protocol + url.host = document.location.host + } + const isSameUrl = url.origin == document.location.origin && + (new RegExp(`/(?:r|user)/[^/]+/comments/${props.id}\\b`)).test(url.pathname) + if (isSameUrl) + url = url.href.substring(url.origin.length) + const userLink = isDeleted(props.author) ? undefined : `https://www.reddit.com/user/${props.author}` let thumbnail @@ -35,12 +45,13 @@ export default (props) => { const thumbnailHeight = props.thumbnail_height ? props.thumbnail_height * 0.5 : 70 if (redditThumbnails.includes(props.thumbnail)) { - thumbnail = + thumbnail = React.createElement(isSameUrl ? Link : 'a', { + [isSameUrl ? 'to' : 'href']: url, + className: `thumbnail thumbnail-${props.thumbnail}` + }) } else if (props.thumbnail !== '') { - thumbnail = ( - - Thumbnail - + thumbnail = React.createElement(isSameUrl ? Link : 'a', { [isSameUrl ? 'to' : 'href']: url }, + Thumbnail ) } @@ -85,7 +96,7 @@ export default (props) => {
{thumbnail}
- {props.title} + { React.createElement(isSameUrl ? Link : 'a', { [isSameUrl ? 'to' : 'href']: url, className:'thread-title' }, props.title) } {props.link_flair_text && {props.link_flair_text} }