feat: add alternate link sources
This commit is contained in:
1 parent
db9c6e6fa8
commit
462f910ac3
7 files changed
+132
-30
No files matched your search
@@ -4,7 +4,7 @@
|
|||||||
import { getInstance } from '$lib/lemmy.js'
|
import { getInstance } from '$lib/lemmy.js'
|
||||||
import PostActions from '$lib/components/lemmy/post/PostActions.svelte'
|
import PostActions from '$lib/components/lemmy/post/PostActions.svelte'
|
||||||
import { userSettings } from '$lib/settings.js'
|
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, {
|
import PostMeta, {
|
||||||
parseTags,
|
parseTags,
|
||||||
type Tag,
|
type Tag,
|
||||||
@@ -172,7 +172,7 @@
|
|||||||
<div
|
<div
|
||||||
class="absolute overflow-hidden inset-0 group-hover:inset-y-0.5 group-hover:-inset-x-4 group-hover:sm:-inset-x-5
|
class="absolute overflow-hidden inset-0 group-hover:inset-y-0.5 group-hover:-inset-x-4 group-hover:sm:-inset-x-5
|
||||||
sm:rounded-xl bg-slate-50 dark:bg-zinc-900
|
sm:rounded-xl bg-slate-50 dark:bg-zinc-900
|
||||||
opacity-0 group-hover:opacity-100 transition-all -z-10 no-list-margin
|
opacity-0 group-hover:opacity-100 transition-all -z-50 no-list-margin
|
||||||
duration-150"
|
duration-150"
|
||||||
/>
|
/>
|
||||||
</Material>
|
</Material>
|
||||||
|
|||||||
@@ -71,11 +71,6 @@
|
|||||||
|
|
||||||
let localShare = false
|
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'
|
$: buttonHeight = view == 'compact' ? 'h-[30px]' : 'h-8'
|
||||||
$: buttonSquare = view == 'compact' ? 'w-[30px] h-[30px]' : 'w-8 h-8'
|
$: buttonSquare = view == 'compact' ? 'w-[30px] h-[30px]' : 'w-8 h-8'
|
||||||
</script>
|
</script>
|
||||||
@@ -118,12 +113,6 @@
|
|||||||
{/await}
|
{/await}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if mediaBias && post.post.url}
|
|
||||||
{#await import('$lib/components/mbfc/MBFCModal.svelte') then { default: MbfcModal }}
|
|
||||||
<MbfcModal domain={stripSubdomain(post.post.url)} bind:open={mediaBias} />
|
|
||||||
{/await}
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="flex flex-row gap-2 items-center flex-shrink-0 {buttonHeight}"
|
class="flex flex-row gap-2 items-center flex-shrink-0 {buttonHeight}"
|
||||||
style={$$props.style ?? ''}
|
style={$$props.style ?? ''}
|
||||||
@@ -282,12 +271,6 @@
|
|||||||
: $t('post.actions.more.markRead')}
|
: $t('post.actions.more.markRead')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
{#if post.post.url && type == 'embed'}
|
|
||||||
<MenuButton on:click={() => (mediaBias = !mediaBias)}>
|
|
||||||
<Icon src={CheckBadge} micro size="16" slot="prefix" />
|
|
||||||
{$t('post.actions.more.mediaBias')}
|
|
||||||
</MenuButton>
|
|
||||||
{/if}
|
|
||||||
<MenuButton
|
<MenuButton
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
navigator.share?.({
|
navigator.share?.({
|
||||||
|
|||||||
+52
-8
@@ -1,15 +1,18 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Link, { parseURL } from '$lib/components/input/Link.svelte'
|
import Link, { parseURL } from '$lib/components/input/Link.svelte'
|
||||||
import { Button, Material } from 'mono-svelte'
|
import { Button, Material } from 'mono-svelte'
|
||||||
import { Icon, Link as LinkIcon } from 'svelte-hero-icons'
|
import { ChevronDown, Icon, Link as LinkIcon } from 'svelte-hero-icons'
|
||||||
import { optimizeImageURL } from './helpers'
|
import { optimizeImageURL } from '../helpers'
|
||||||
|
import PostLinkSources from './PostLinkSources.svelte'
|
||||||
|
import { t } from '$lib/translations'
|
||||||
|
import type { View } from '$lib/settings'
|
||||||
|
|
||||||
export let url: string
|
export let url: string
|
||||||
export let thumbnail_url: string | undefined = undefined
|
export let thumbnail_url: string | undefined = undefined
|
||||||
export let nsfw: boolean = false
|
export let nsfw: boolean = false
|
||||||
export let embed_title: string | undefined = undefined
|
export let embed_title: string | undefined = undefined
|
||||||
export let embed_description: string | undefined = undefined
|
export let embed_description: string | undefined = undefined
|
||||||
export let compact: boolean = false
|
export let view: View = 'cozy'
|
||||||
|
|
||||||
$: richURL = parseURL(url)
|
$: richURL = parseURL(url)
|
||||||
</script>
|
</script>
|
||||||
@@ -18,7 +21,7 @@
|
|||||||
@component
|
@component
|
||||||
For embed-type posts. Displays embed card or a compact link.
|
For embed-type posts. Displays embed card or a compact link.
|
||||||
-->
|
-->
|
||||||
{#if embed_title && !compact}
|
{#if embed_title && view != 'compact'}
|
||||||
<Material
|
<Material
|
||||||
color="distinct"
|
color="distinct"
|
||||||
class="flex flex-col-reverse sm:flex-row overflow-hidden gap-4"
|
class="flex flex-col-reverse sm:flex-row overflow-hidden gap-4"
|
||||||
@@ -31,7 +34,6 @@
|
|||||||
target="_blank"
|
target="_blank"
|
||||||
class="text-slate-600 dark:text-zinc-400 inline-flex items-center gap-1 text-xs"
|
class="text-slate-600 dark:text-zinc-400 inline-flex items-center gap-1 text-xs"
|
||||||
>
|
>
|
||||||
<Icon src={LinkIcon} size="12" mini slot="icon" />
|
|
||||||
{richURL.hostname}
|
{richURL.hostname}
|
||||||
</Link>
|
</Link>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -81,16 +83,57 @@
|
|||||||
</a>
|
</a>
|
||||||
{/if}
|
{/if}
|
||||||
</Material>
|
</Material>
|
||||||
|
<Material
|
||||||
|
color="none"
|
||||||
|
padding="none"
|
||||||
|
class="px-1 py-0 bg-slate-50 dark:bg-zinc-925 h-9 rounded-b-xl rounded-t-none
|
||||||
|
w-[calc(100%-1rem)] {view == 'list'
|
||||||
|
? ''
|
||||||
|
: '-mt-2'} mx-auto shadow-inner border border-t-0
|
||||||
|
border-slate-200 dark:border-zinc-800
|
||||||
|
flex flex-row items-center overflow-auto"
|
||||||
|
>
|
||||||
|
<PostLinkSources {url}>
|
||||||
|
<Button
|
||||||
|
color="tertiary"
|
||||||
|
slot="target"
|
||||||
|
size="sm"
|
||||||
|
class="w-max text-slate-600 dark:text-zinc-400 block
|
||||||
|
text-xs"
|
||||||
|
>
|
||||||
|
<Icon src={LinkIcon} size="16" micro slot="prefix" />
|
||||||
|
{$t('post.actions.link.actions')}
|
||||||
|
</Button>
|
||||||
|
</PostLinkSources>
|
||||||
|
</Material>
|
||||||
{:else}
|
{:else}
|
||||||
|
<div class="flex items-center gap-1">
|
||||||
|
<PostLinkSources {url}>
|
||||||
|
<Button
|
||||||
|
color="ghost"
|
||||||
|
slot="target"
|
||||||
|
size="sm"
|
||||||
|
rounding="pill"
|
||||||
|
class="p-0.5 px-1 w-max mt-auto text-slate-600 dark:text-zinc-400 block
|
||||||
|
text-xs"
|
||||||
|
>
|
||||||
|
<div class="mr-0.5" style="width: 8px;">
|
||||||
|
<Icon src={LinkIcon} size="16" micro slot="prefix" />
|
||||||
|
</div>
|
||||||
|
<div class="mr-1" style="width: 8px;">
|
||||||
|
<Icon src={ChevronDown} size="16" micro slot="suffix" />
|
||||||
|
</div>
|
||||||
|
</Button>
|
||||||
|
</PostLinkSources>
|
||||||
<Button
|
<Button
|
||||||
href={url}
|
href={url}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
class="text-slate-900 dark:text-zinc-300 inline-flex items-center gap-1 text-xs overflow-hidden w-max max-w-full"
|
class="text-slate-900 dark:text-zinc-300 items-center
|
||||||
|
text-xs overflow-hidden max-w-full block"
|
||||||
size="sm"
|
size="sm"
|
||||||
color="ghost"
|
color="ghost"
|
||||||
rounding="pill"
|
rounding="pill"
|
||||||
>
|
>
|
||||||
<Icon src={LinkIcon} size="14" mini slot="prefix" class="flex-shrink-0" />
|
|
||||||
{#if richURL}
|
{#if richURL}
|
||||||
<div class="flex max-w-full overflow-hidden font-medium">
|
<div class="flex max-w-full overflow-hidden font-medium">
|
||||||
{richURL.hostname}
|
{richURL.hostname}
|
||||||
@@ -106,7 +149,8 @@
|
|||||||
{url}
|
{url}
|
||||||
{/if}
|
{/if}
|
||||||
</Button>
|
</Button>
|
||||||
{#if thumbnail_url && !compact}
|
</div>
|
||||||
|
{#if thumbnail_url && view != 'compact'}
|
||||||
<a href={url} target="_blank">
|
<a href={url} target="_blank">
|
||||||
<img
|
<img
|
||||||
src={optimizeImageURL(thumbnail_url, 256)}
|
src={optimizeImageURL(thumbnail_url, 256)}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
<script lang="ts" context="module">
|
||||||
|
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',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { t } from '$lib/translations'
|
||||||
|
import { Menu, MenuButton, MenuDivider } from 'mono-svelte'
|
||||||
|
import type { MediaType } from '../helpers'
|
||||||
|
import { CheckBadge, Icon } from 'svelte-hero-icons'
|
||||||
|
|
||||||
|
export let url: string
|
||||||
|
export let type: MediaType = 'embed'
|
||||||
|
|
||||||
|
let mediaBias = false
|
||||||
|
|
||||||
|
const stripSubdomain = (url: string) =>
|
||||||
|
new URL(url).hostname.split('.').slice(-2).join('.')
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if mediaBias}
|
||||||
|
{#await import('$lib/components/mbfc/MBFCModal.svelte') then { default: MbfcModal }}
|
||||||
|
<MbfcModal domain={stripSubdomain(url)} bind:open={mediaBias} />
|
||||||
|
{/await}
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<Menu {...$$restProps}>
|
||||||
|
<slot name="target" slot="target" />
|
||||||
|
|
||||||
|
<MenuDivider>{$t('post.actions.link.title')}</MenuDivider>
|
||||||
|
{#each sources as source}
|
||||||
|
{#if source.type == type}
|
||||||
|
<MenuButton target="_blank" href={source.getLink(url)}>
|
||||||
|
{source.name}
|
||||||
|
</MenuButton>
|
||||||
|
{/if}
|
||||||
|
{/each}
|
||||||
|
<MenuDivider>{$t('post.actions.link.actions')}</MenuDivider>
|
||||||
|
<MenuButton on:click={() => (mediaBias = !mediaBias)}>
|
||||||
|
<Icon src={CheckBadge} size="16" micro slot="prefix" />
|
||||||
|
{$t('post.actions.more.mediaBias')}
|
||||||
|
</MenuButton>
|
||||||
|
</Menu>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Empty from '$lib/components/helper/Empty.svelte'
|
import Empty from '$lib/components/helper/Empty.svelte'
|
||||||
import PostLink from '$lib/components/lemmy/post/PostLink.svelte'
|
import PostLink from '$lib/components/lemmy/post/link/PostLink.svelte'
|
||||||
import {
|
import {
|
||||||
bestImageURL,
|
bestImageURL,
|
||||||
postLink,
|
postLink,
|
||||||
@@ -113,6 +113,6 @@
|
|||||||
nsfw={post.nsfw}
|
nsfw={post.nsfw}
|
||||||
embed_description={post.embed_description}
|
embed_description={post.embed_description}
|
||||||
embed_title={post.embed_title}
|
embed_title={post.embed_title}
|
||||||
compact={view == 'compact' || (view == 'list' && !post.embed_title)}
|
{view}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -451,6 +451,10 @@
|
|||||||
},
|
},
|
||||||
"downloading": "Downloading dataset",
|
"downloading": "Downloading dataset",
|
||||||
"loading": "Loading source"
|
"loading": "Loading source"
|
||||||
|
},
|
||||||
|
"link": {
|
||||||
|
"title": "Alternative Links",
|
||||||
|
"actions": "Link Actions"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"badges": {
|
"badges": {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
Home,
|
Home,
|
||||||
PlusCircle,
|
PlusCircle,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import PostLink from '$lib/components/lemmy/post/PostLink.svelte'
|
import PostLink from '$lib/components/lemmy/post/link/PostLink.svelte'
|
||||||
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
|
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
|
||||||
import { Material, Select, Spinner, removeToast, toast } from 'mono-svelte'
|
import { Material, Select, Spinner, removeToast, toast } from 'mono-svelte'
|
||||||
import type { CommentSortType } from 'lemmy-js-client'
|
import type { CommentSortType } from 'lemmy-js-client'
|
||||||
|
|||||||
Reference in new issue
Block a user