From 462f910ac381a1c5b0452fe93ae0f74248c4f0f0 Mon Sep 17 00:00:00 2001 From: Xylight Date: Sat, 3 Aug 2024 10:56:39 -0700 Subject: [PATCH] feat: add alternate link sources --- src/lib/components/lemmy/post/Post.svelte | 4 +- .../components/lemmy/post/PostActions.svelte | 17 --- .../lemmy/post/{ => link}/PostLink.svelte | 104 +++++++++++++----- .../lemmy/post/link/PostLinkSources.svelte | 71 ++++++++++++ .../lemmy/post/media/PostMedia.svelte | 4 +- src/lib/i18n/en.json | 4 + .../post/[instance]/[id=integer]/+page.svelte | 2 +- 7 files changed, 154 insertions(+), 52 deletions(-) rename src/lib/components/lemmy/post/{ => link}/PostLink.svelte (53%) create mode 100644 src/lib/components/lemmy/post/link/PostLinkSources.svelte diff --git a/src/lib/components/lemmy/post/Post.svelte b/src/lib/components/lemmy/post/Post.svelte index 5534cebb..8cc1fbcf 100644 --- a/src/lib/components/lemmy/post/Post.svelte +++ b/src/lib/components/lemmy/post/Post.svelte @@ -4,7 +4,7 @@ import { getInstance } from '$lib/lemmy.js' import PostActions from '$lib/components/lemmy/post/PostActions.svelte' import { userSettings } from '$lib/settings.js' - import PostLink from '$lib/components/lemmy/post/PostLink.svelte' + import PostLink from '$lib/components/lemmy/post/link/PostLink.svelte' import PostMeta, { parseTags, type Tag, @@ -172,7 +172,7 @@
diff --git a/src/lib/components/lemmy/post/PostActions.svelte b/src/lib/components/lemmy/post/PostActions.svelte index ad7f441c..3e3893f7 100644 --- a/src/lib/components/lemmy/post/PostActions.svelte +++ b/src/lib/components/lemmy/post/PostActions.svelte @@ -71,11 +71,6 @@ let localShare = false - let mediaBias = false - - const stripSubdomain = (url: string) => - new URL(url).hostname.split('.').slice(-2).join('.') - $: buttonHeight = view == 'compact' ? 'h-[30px]' : 'h-8' $: buttonSquare = view == 'compact' ? 'w-[30px] h-[30px]' : 'w-8 h-8' @@ -118,12 +113,6 @@ {/await} {/if} -{#if mediaBias && post.post.url} - {#await import('$lib/components/mbfc/MBFCModal.svelte') then { default: MbfcModal }} - - {/await} -{/if} -
{/if} - {#if post.post.url && type == 'embed'} - (mediaBias = !mediaBias)}> - - {$t('post.actions.more.mediaBias')} - - {/if} { navigator.share?.({ diff --git a/src/lib/components/lemmy/post/PostLink.svelte b/src/lib/components/lemmy/post/link/PostLink.svelte similarity index 53% rename from src/lib/components/lemmy/post/PostLink.svelte rename to src/lib/components/lemmy/post/link/PostLink.svelte index 68429386..6338f085 100644 --- a/src/lib/components/lemmy/post/PostLink.svelte +++ b/src/lib/components/lemmy/post/link/PostLink.svelte @@ -1,15 +1,18 @@ @@ -18,7 +21,7 @@ @component For embed-type posts. Displays embed card or a compact link. --> -{#if embed_title && !compact} +{#if embed_title && view != 'compact'} - {richURL.hostname} {/if} @@ -81,32 +83,74 @@ {/if} -{:else} - - {#if thumbnail_url && !compact} + + + + +{:else} +
+ + + + +
+ {#if thumbnail_url && view != 'compact'} + const sources: { + getLink: (url: string) => string + name: string + type: MediaType + }[] = [ + { + getLink: (url: string) => + `https://archive.ph/${encodeURIComponent(url.split('?')[0])}`, + name: 'Archive Today', + type: 'embed', + }, + { + getLink: (url: string) => + `https://ghostarchive.org/search?term=${encodeURIComponent(url.split('?')[0])}`, + name: 'Ghost Archive', + type: 'embed', + }, + { + getLink: (url: string) => + `https://12ft.io/proxy?q=${encodeURIComponent(url.split('?')[0])}`, + name: '12ft.io', + type: 'embed', + }, + { + getLink: (url: string) => + `https://ground.news/find?url=${encodeURIComponent(url.split('?')[0])}`, + name: 'Ground News', + type: 'embed', + }, + ] + + + + +{#if mediaBias} + {#await import('$lib/components/mbfc/MBFCModal.svelte') then { default: MbfcModal }} + + {/await} +{/if} + + + + + {$t('post.actions.link.title')} + {#each sources as source} + {#if source.type == type} + + {source.name} + + {/if} + {/each} + {$t('post.actions.link.actions')} + (mediaBias = !mediaBias)}> + + {$t('post.actions.more.mediaBias')} + + diff --git a/src/lib/components/lemmy/post/media/PostMedia.svelte b/src/lib/components/lemmy/post/media/PostMedia.svelte index 01d3e3bf..e8aac84a 100644 --- a/src/lib/components/lemmy/post/media/PostMedia.svelte +++ b/src/lib/components/lemmy/post/media/PostMedia.svelte @@ -1,6 +1,6 @@