feat: add alternate link sources
This commit is contained in:
1 parent
db9c6e6fa8
commit
462f910ac3
7 files changed
+154
-52
No files matched your search
@@ -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 @@
|
||||
<div
|
||||
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
|
||||
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"
|
||||
/>
|
||||
</Material>
|
||||
|
||||
@@ -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'
|
||||
</script>
|
||||
@@ -118,12 +113,6 @@
|
||||
{/await}
|
||||
{/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
|
||||
class="flex flex-row gap-2 items-center flex-shrink-0 {buttonHeight}"
|
||||
style={$$props.style ?? ''}
|
||||
@@ -282,12 +271,6 @@
|
||||
: $t('post.actions.more.markRead')}
|
||||
</MenuButton>
|
||||
{/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
|
||||
on:click={() => {
|
||||
navigator.share?.({
|
||||
|
||||
+74
-30
@@ -1,15 +1,18 @@
|
||||
<script lang="ts">
|
||||
import Link, { parseURL } from '$lib/components/input/Link.svelte'
|
||||
import { Button, Material } from 'mono-svelte'
|
||||
import { Icon, Link as LinkIcon } from 'svelte-hero-icons'
|
||||
import { optimizeImageURL } from './helpers'
|
||||
import { ChevronDown, Icon, Link as LinkIcon } from 'svelte-hero-icons'
|
||||
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 thumbnail_url: string | undefined = undefined
|
||||
export let nsfw: boolean = false
|
||||
export let embed_title: string | undefined = undefined
|
||||
export let embed_description: string | undefined = undefined
|
||||
export let compact: boolean = false
|
||||
export let view: View = 'cozy'
|
||||
|
||||
$: richURL = parseURL(url)
|
||||
</script>
|
||||
@@ -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'}
|
||||
<Material
|
||||
color="distinct"
|
||||
class="flex flex-col-reverse sm:flex-row overflow-hidden gap-4"
|
||||
@@ -31,7 +34,6 @@
|
||||
target="_blank"
|
||||
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}
|
||||
</Link>
|
||||
{/if}
|
||||
@@ -81,32 +83,74 @@
|
||||
</a>
|
||||
{/if}
|
||||
</Material>
|
||||
{:else}
|
||||
<Button
|
||||
href={url}
|
||||
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"
|
||||
size="sm"
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
<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"
|
||||
>
|
||||
<Icon src={LinkIcon} size="14" mini slot="prefix" class="flex-shrink-0" />
|
||||
{#if richURL}
|
||||
<div class="flex max-w-full overflow-hidden font-medium">
|
||||
{richURL.hostname}
|
||||
{#if richURL.pathname != '/'}
|
||||
<span
|
||||
class="text-slate-500 dark:text-zinc-500 whitespace-nowrap font-normal"
|
||||
>
|
||||
{richURL.pathname}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
{url}
|
||||
{/if}
|
||||
</Button>
|
||||
{#if thumbnail_url && !compact}
|
||||
<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}
|
||||
<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
|
||||
href={url}
|
||||
target="_blank"
|
||||
class="text-slate-900 dark:text-zinc-300 items-center
|
||||
text-xs overflow-hidden max-w-full block"
|
||||
size="sm"
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
>
|
||||
{#if richURL}
|
||||
<div class="flex max-w-full overflow-hidden font-medium">
|
||||
{richURL.hostname}
|
||||
{#if richURL.pathname != '/'}
|
||||
<span
|
||||
class="text-slate-500 dark:text-zinc-500 whitespace-nowrap font-normal"
|
||||
>
|
||||
{richURL.pathname}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
{url}
|
||||
{/if}
|
||||
</Button>
|
||||
</div>
|
||||
{#if thumbnail_url && view != 'compact'}
|
||||
<a href={url} target="_blank">
|
||||
<img
|
||||
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">
|
||||
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 {
|
||||
bestImageURL,
|
||||
postLink,
|
||||
@@ -113,6 +113,6 @@
|
||||
nsfw={post.nsfw}
|
||||
embed_description={post.embed_description}
|
||||
embed_title={post.embed_title}
|
||||
compact={view == 'compact' || (view == 'list' && !post.embed_title)}
|
||||
{view}
|
||||
/>
|
||||
{/if}
|
||||
@@ -451,6 +451,10 @@
|
||||
},
|
||||
"downloading": "Downloading dataset",
|
||||
"loading": "Loading source"
|
||||
},
|
||||
"link": {
|
||||
"title": "Alternative Links",
|
||||
"actions": "Link Actions"
|
||||
}
|
||||
},
|
||||
"badges": {
|
||||
|
||||
Reference in new issue
Block a user