Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2429eb9ec | ||
|
|
8e7c5be4c8 | ||
|
|
302700ef66 | ||
|
|
a9bf3497fe |
No files matched your search
@@ -154,3 +154,21 @@ Want your instance added here? Make a GitHub issue or make a PR. (this is for ge
|
|||||||
I've put my best effort into developing and maintaining this open source app. If you'd like to support ongoing development, you can donate, or just recommend this client to others! [Buy me a Coffee](https://buymeacoffee.com/xylight)
|
I've put my best effort into developing and maintaining this open source app. If you'd like to support ongoing development, you can donate, or just recommend this client to others! [Buy me a Coffee](https://buymeacoffee.com/xylight)
|
||||||
|
|
||||||
<a href="https://www.buymeacoffee.com/xylight"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=xylight&button_colour=FFDD00&font_colour=000000&font_family=Poppins&outline_colour=000000&coffee_colour=ffffff" /></a>
|
<a href="https://www.buymeacoffee.com/xylight"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=xylight&button_colour=FFDD00&font_colour=000000&font_family=Poppins&outline_colour=000000&coffee_colour=ffffff" /></a>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## thebitcoin.win fork
|
||||||
|
|
||||||
|
This fork adds a **single-community mode** for sites where the whole instance is one community
|
||||||
|
(thebitcoin.win). Set `PUBLIC_SINGLE_COMMUNITY=<community name>` and:
|
||||||
|
|
||||||
|
- `/` shows that community's feed (address stays `/`), and `/communities`, `/explore/*` and
|
||||||
|
other `/c/<name>` pages lead back to it (`src/hooks.ts`, SvelteKit `reroute`)
|
||||||
|
- the Explore nav item, community browser entries in the command palette and the
|
||||||
|
"communities" buttons on empty feeds are hidden
|
||||||
|
- community names, handles and links are not shown on posts or in the community header
|
||||||
|
- creating a post preselects the community
|
||||||
|
|
||||||
|
Unset, the client behaves exactly like upstream Photon. All changes are guarded by
|
||||||
|
`SINGLE_COMMUNITY` from `src/lib/app/single.ts`. Licensed AGPL-3.0 like upstream; source of the
|
||||||
|
running site: https://gitea.ihler.tech/larsi/photon-tbw
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import type { Reroute } from '@sveltejs/kit'
|
||||||
|
import { SINGLE_COMMUNITY } from '$lib/app/single'
|
||||||
|
import { resolvePrettyPath } from '$lib/app/slug'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Single-community mode: serve the community page for "/" and for every route that would
|
||||||
|
* otherwise list or browse communities. The address bar keeps the original path, so the home
|
||||||
|
* page stays "/". The community's own sub-pages (e.g. /c/<name>/settings) are left alone.
|
||||||
|
*/
|
||||||
|
export const reroute: Reroute = ({ url }) => {
|
||||||
|
if (!SINGLE_COMMUNITY) return
|
||||||
|
const path = url.pathname
|
||||||
|
// Pretty post URLs: /p/<code>/<slug> -> /post/<instance>/<id>.
|
||||||
|
const post = resolvePrettyPath(path)
|
||||||
|
if (post) return post
|
||||||
|
const home = `/c/${SINGLE_COMMUNITY}`
|
||||||
|
if (path === '/' || path === '/communities' || path.startsWith('/explore')) return home
|
||||||
|
const other = path.match(/^\/c\/([^/]+)\/?$/)
|
||||||
|
if (other && other[1] !== SINGLE_COMMUNITY) return home
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { env } from '$env/dynamic/public'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Single-community mode (thebitcoin.win fork).
|
||||||
|
*
|
||||||
|
* When PUBLIC_SINGLE_COMMUNITY is set, the site IS that one local community: "/" shows its
|
||||||
|
* feed, the community browser and explore pages lead back to it, and the UI stops showing
|
||||||
|
* community names and handles. Unset, Photon behaves exactly like upstream.
|
||||||
|
*/
|
||||||
|
export const SINGLE_COMMUNITY: string | undefined =
|
||||||
|
env.PUBLIC_SINGLE_COMMUNITY?.trim() || undefined
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
import { env } from '$env/dynamic/public'
|
||||||
|
import { SINGLE_COMMUNITY } from '$lib/app/single'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pretty post URLs for single-community mode: /p/<code>/<title-slug>.
|
||||||
|
*
|
||||||
|
* <code> is the post id run through a reversible 32-bit mix and written in base36, so it is
|
||||||
|
* unique per post, short, and does not expose the raw sequential id. Only the code is used to
|
||||||
|
* find the post; the slug is decoration, so a renamed post keeps working links.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const MASK = 0xffffffff
|
||||||
|
const MUL = 0x2c1b3c6d // odd, so it has an inverse mod 2^32
|
||||||
|
const MUL_INV = inverse(MUL)
|
||||||
|
const XOR = 0x5bd1e995
|
||||||
|
const MIN = 36 ** 5 // pad codes to at least 6 characters
|
||||||
|
|
||||||
|
function inverse(a: number): number {
|
||||||
|
// Newton's iteration for the multiplicative inverse mod 2^32.
|
||||||
|
let x = a
|
||||||
|
for (let i = 0; i < 5; i++) x = Math.imul(x, 2 - Math.imul(a, x)) >>> 0
|
||||||
|
return x >>> 0
|
||||||
|
}
|
||||||
|
|
||||||
|
export function encodeId(id: number): string {
|
||||||
|
const mixed = Math.imul((id ^ XOR) >>> 0, MUL) >>> 0
|
||||||
|
return (mixed + MIN).toString(36)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function decodeId(code: string): number | undefined {
|
||||||
|
if (!/^[0-9a-z]{6,8}$/.test(code)) return undefined
|
||||||
|
const n = parseInt(code, 36) - MIN
|
||||||
|
if (n < 0 || n > MASK) return undefined
|
||||||
|
const id = ((Math.imul(n >>> 0, MUL_INV) >>> 0) ^ XOR) >>> 0
|
||||||
|
return id > 0 && id < 2 ** 31 ? id : undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
export function slugify(title: string, max = 60): string {
|
||||||
|
const slug = title
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[æ]/g, 'ae')
|
||||||
|
.replace(/[øœ]/g, 'oe')
|
||||||
|
.replace(/ß/g, 'ss')
|
||||||
|
.replace(/[đð]/g, 'd')
|
||||||
|
.replace(/þ/g, 'th')
|
||||||
|
.replace(/ł/g, 'l')
|
||||||
|
.normalize('NFKD')
|
||||||
|
.replace(/[\u0300-\u036f]/g, '')
|
||||||
|
.replace(/&/g, ' and ')
|
||||||
|
.replace(/[^a-z0-9]+/g, '-')
|
||||||
|
.replace(/^-+|-+$/g, '')
|
||||||
|
if (slug.length <= max) return slug || 'post'
|
||||||
|
const cut = slug.slice(0, max)
|
||||||
|
return cut.slice(0, cut.lastIndexOf('-') > 20 ? cut.lastIndexOf('-') : max)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const prettyPostUrls = Boolean(SINGLE_COMMUNITY)
|
||||||
|
|
||||||
|
export function prettyPostPath(id: number, title?: string): string {
|
||||||
|
return `/p/${encodeId(id)}/${slugify(title ?? '')}`
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Internal route for a pretty path, or undefined when the path is not one. */
|
||||||
|
export function resolvePrettyPath(path: string): string | undefined {
|
||||||
|
const m = path.match(/^\/p\/([0-9a-z]+)(?:\/[^/]*)?\/?$/)
|
||||||
|
if (!m) return undefined
|
||||||
|
const id = decodeId(m[1])
|
||||||
|
if (!id) return undefined
|
||||||
|
const instance = (env.PUBLIC_INSTANCE_URL || '').toLowerCase()
|
||||||
|
return `/post/${encodeURIComponent(instance)}/${id}`
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts" module>
|
<script lang="ts" module>
|
||||||
|
import { SINGLE_COMMUNITY } from '$lib/app/single'
|
||||||
import { client, getClient } from '$lib/api/client.svelte'
|
import { client, getClient } from '$lib/api/client.svelte'
|
||||||
import type { CommunityModeratorView, CommunityView } from '$lib/api/types'
|
import type { CommunityModeratorView, CommunityView } from '$lib/api/types'
|
||||||
import { profile } from '$lib/app/auth'
|
import { profile } from '$lib/app/auth'
|
||||||
@@ -177,10 +178,12 @@
|
|||||||
avatarCircle={false}
|
avatarCircle={false}
|
||||||
>
|
>
|
||||||
{#snippet nameDetail()}
|
{#snippet nameDetail()}
|
||||||
|
{#if !SINGLE_COMMUNITY}
|
||||||
!{fullCommunityName(
|
!{fullCommunityName(
|
||||||
community_view.community.name,
|
community_view.community.name,
|
||||||
community_view.community.actor_id,
|
community_view.community.actor_id,
|
||||||
)}
|
)}
|
||||||
|
{/if}
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</EntityHeader>
|
</EntityHeader>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { SINGLE_COMMUNITY } from '$lib/app/single'
|
||||||
import { client } from '$lib/api/client.svelte'
|
import { client } from '$lib/api/client.svelte'
|
||||||
import type {
|
import type {
|
||||||
Community,
|
Community,
|
||||||
@@ -109,6 +110,7 @@
|
|||||||
class={['tracking-normal', clazz]}
|
class={['tracking-normal', clazz]}
|
||||||
>
|
>
|
||||||
{#snippet nameDetail()}
|
{#snippet nameDetail()}
|
||||||
|
{#if !SINGLE_COMMUNITY}
|
||||||
<button
|
<button
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
navigator?.clipboard?.writeText?.(
|
navigator?.clipboard?.writeText?.(
|
||||||
@@ -120,6 +122,7 @@
|
|||||||
>
|
>
|
||||||
!{fullCommunityName(community.name, community.actor_id)}
|
!{fullCommunityName(community.name, community.actor_id)}
|
||||||
</button>
|
</button>
|
||||||
|
{/if}
|
||||||
{/snippet}
|
{/snippet}
|
||||||
{#if moderators.length > 0}
|
{#if moderators.length > 0}
|
||||||
<Expandable class={[compact == 'lg' && 'lg:hidden']}>
|
<Expandable class={[compact == 'lg' && 'lg:hidden']}>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<script lang="ts" module>
|
<script lang="ts" module>
|
||||||
|
import { SINGLE_COMMUNITY } from '$lib/app/single'
|
||||||
|
import { prettyPostPath, prettyPostUrls } from '$lib/app/slug'
|
||||||
import type { Community, Person, SubscribedType } from '$lib/api/types'
|
import type { Community, Person, SubscribedType } from '$lib/api/types'
|
||||||
import { profile } from '$lib/app/auth'
|
import { profile } from '$lib/app/auth'
|
||||||
import { t } from '$lib/app/i18n'
|
import { t } from '$lib/app/i18n'
|
||||||
@@ -197,13 +199,13 @@
|
|||||||
<header
|
<header
|
||||||
class={[
|
class={[
|
||||||
'grid w-full meta',
|
'grid w-full meta',
|
||||||
community ? 'grid-rows-2' : 'grid-rows-1 minimal',
|
community && !SINGLE_COMMUNITY ? 'grid-rows-2' : 'grid-rows-1 minimal',
|
||||||
'text-xs min-w-0 max-w-full text-slate-600 dark:text-zinc-400',
|
'text-xs min-w-0 max-w-full text-slate-600 dark:text-zinc-400',
|
||||||
]}
|
]}
|
||||||
class:compact={view == 'compact'}
|
class:compact={view == 'compact'}
|
||||||
{style}
|
{style}
|
||||||
>
|
>
|
||||||
{#if showCommunity && community}
|
{#if showCommunity && community && !SINGLE_COMMUNITY}
|
||||||
<Popover>
|
<Popover>
|
||||||
{#snippet target(attachment)}
|
{#snippet target(attachment)}
|
||||||
<button
|
<button
|
||||||
@@ -249,7 +251,7 @@
|
|||||||
{/snippet}
|
{/snippet}
|
||||||
</Popover>
|
</Popover>
|
||||||
{/if}
|
{/if}
|
||||||
{#if showCommunity && community}
|
{#if showCommunity && community && !SINGLE_COMMUNITY}
|
||||||
<CommunityLink
|
<CommunityLink
|
||||||
{community}
|
{community}
|
||||||
style="grid-area: community;"
|
style="grid-area: community;"
|
||||||
@@ -370,6 +372,8 @@
|
|||||||
<a
|
<a
|
||||||
href={useAttachedUrl
|
href={useAttachedUrl
|
||||||
? postUrl
|
? postUrl
|
||||||
|
: prettyPostUrls
|
||||||
|
? prettyPostPath(id, title)
|
||||||
: `/post/${encodeURIComponent(profile.current.instance)}/${id}`}
|
: `/post/${encodeURIComponent(profile.current.instance)}/${id}`}
|
||||||
target={useAttachedUrl ? '_blank' : undefined}
|
target={useAttachedUrl ? '_blank' : undefined}
|
||||||
rel={useAttachedUrl ? 'noopener noreferrer' : undefined}
|
rel={useAttachedUrl ? 'noopener noreferrer' : undefined}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from '$app/state'
|
import { page } from '$app/state'
|
||||||
|
import { prettyPostPath, prettyPostUrls } from '$lib/app/slug'
|
||||||
import type { PostView } from '$lib/api/types'
|
import type { PostView } from '$lib/api/types'
|
||||||
import { profile } from '$lib/app/auth'
|
import { profile } from '$lib/app/auth'
|
||||||
import { t } from '$lib/app/i18n'
|
import { t } from '$lib/app/i18n'
|
||||||
@@ -62,7 +63,9 @@
|
|||||||
function share(global: boolean = true, url?: string) {
|
function share(global: boolean = true, url?: string) {
|
||||||
const link =
|
const link =
|
||||||
url ??
|
url ??
|
||||||
(global
|
(prettyPostUrls
|
||||||
|
? `${page.url.origin}${prettyPostPath(post.post.id, post.post.name)}`
|
||||||
|
: global
|
||||||
? post.post.ap_id
|
? post.post.ap_id
|
||||||
: `${instanceToURL(profile.current.instance)}/post/${post.post.id}`)
|
: `${instanceToURL(profile.current.instance)}/post/${post.post.id}`)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { SINGLE_COMMUNITY } from '$lib/app/single'
|
||||||
import type { PostView } from '$lib/api/types'
|
import type { PostView } from '$lib/api/types'
|
||||||
import { settings } from '$lib/app/settings.svelte'
|
import { settings } from '$lib/app/settings.svelte'
|
||||||
import Placeholder from '$lib/ui/info/Placeholder.svelte'
|
import Placeholder from '$lib/ui/info/Placeholder.svelte'
|
||||||
@@ -41,9 +42,11 @@
|
|||||||
title="No posts"
|
title="No posts"
|
||||||
description="There are no posts that match this filter."
|
description="There are no posts that match this filter."
|
||||||
>
|
>
|
||||||
|
{#if !SINGLE_COMMUNITY}
|
||||||
<Button href="/communities" icon={Plus}>
|
<Button href="/communities" icon={Plus}>
|
||||||
<span>Follow some communities</span>
|
<span>Follow some communities</span>
|
||||||
</Button>
|
</Button>
|
||||||
|
{/if}
|
||||||
</Placeholder>
|
</Placeholder>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { SINGLE_COMMUNITY } from '$lib/app/single'
|
||||||
import { browser } from '$app/environment'
|
import { browser } from '$app/environment'
|
||||||
import { client } from '$lib/api/client.svelte'
|
import { client } from '$lib/api/client.svelte'
|
||||||
import type { GetPosts, PostView } from '$lib/api/types'
|
import type { GetPosts, PostView } from '$lib/api/types'
|
||||||
@@ -163,6 +164,7 @@
|
|||||||
title={$t('routes.frontpage.empty.title')}
|
title={$t('routes.frontpage.empty.title')}
|
||||||
description={$t('routes.frontpage.empty.description')}
|
description={$t('routes.frontpage.empty.description')}
|
||||||
>
|
>
|
||||||
|
{#if !SINGLE_COMMUNITY}
|
||||||
<Button
|
<Button
|
||||||
href="/communities"
|
href="/communities"
|
||||||
rounding="pill"
|
rounding="pill"
|
||||||
@@ -171,6 +173,7 @@
|
|||||||
>
|
>
|
||||||
{$t('nav.communities')}
|
{$t('nav.communities')}
|
||||||
</Button>
|
</Button>
|
||||||
|
{/if}
|
||||||
</Placeholder>
|
</Placeholder>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { env } from '$env/dynamic/public'
|
import { env } from '$env/dynamic/public'
|
||||||
|
import { prettyPostPath, prettyPostUrls } from '$lib/app/slug'
|
||||||
import { client } from '$lib/api/client.svelte'
|
import { client } from '$lib/api/client.svelte'
|
||||||
import type { CommentView, PersonView, Post } from '$lib/api/types'
|
import type { CommentView, PersonView, Post } from '$lib/api/types'
|
||||||
import { profile } from '$lib/app/auth'
|
import { profile } from '$lib/app/auth'
|
||||||
@@ -74,6 +75,7 @@ export const isYoutubeLink = (url?: string): RegExpMatchArray | null => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function postLink(post: Post) {
|
export function postLink(post: Post) {
|
||||||
|
if (prettyPostUrls) return prettyPostPath(post.id, post.name)
|
||||||
return `/post/${encodeURIComponent(profile.current.instance)}/${post.id}`
|
return `/post/${encodeURIComponent(profile.current.instance)}/${post.id}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { SINGLE_COMMUNITY } from '$lib/app/single'
|
||||||
import { site } from '$lib/api/client.svelte'
|
import { site } from '$lib/api/client.svelte'
|
||||||
import { profile } from '$lib/app/auth'
|
import { profile } from '$lib/app/auth'
|
||||||
import { t } from '$lib/app/i18n'
|
import { t } from '$lib/app/i18n'
|
||||||
@@ -89,6 +90,7 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
{#if !SINGLE_COMMUNITY}
|
||||||
<NavButton
|
<NavButton
|
||||||
href="/explore/communities"
|
href="/explore/communities"
|
||||||
label={$t('routes.explore.title')}
|
label={$t('routes.explore.title')}
|
||||||
@@ -96,6 +98,7 @@
|
|||||||
isSelectedFilter={(path) => path.startsWith('/explore')}
|
isSelectedFilter={(path) => path.startsWith('/explore')}
|
||||||
class="order-1"
|
class="order-1"
|
||||||
/>
|
/>
|
||||||
|
{/if}
|
||||||
<NavButton
|
<NavButton
|
||||||
href="/search"
|
href="/search"
|
||||||
label={$t('nav.search')}
|
label={$t('nav.search')}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { SINGLE_COMMUNITY } from '$lib/app/single'
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { page } from '$app/state'
|
import { page } from '$app/state'
|
||||||
import { profile as currentProfile, type ProfileInfo } from '$lib/app/auth'
|
import { profile as currentProfile, type ProfileInfo } from '$lib/app/auth'
|
||||||
@@ -85,11 +86,15 @@ export function getGroups(
|
|||||||
name: t.get('nav.commands.main'),
|
name: t.get('nav.commands.main'),
|
||||||
actions: [
|
actions: [
|
||||||
{ href: '/', name: t.get('nav.home'), icon: Home, shortcut: 'h' },
|
{ href: '/', name: t.get('nav.home'), icon: Home, shortcut: 'h' },
|
||||||
|
...(SINGLE_COMMUNITY
|
||||||
|
? []
|
||||||
|
: [
|
||||||
{
|
{
|
||||||
href: '/communities',
|
href: '/communities',
|
||||||
name: t.get('nav.communities'),
|
name: t.get('nav.communities'),
|
||||||
icon: GlobeAlt,
|
icon: GlobeAlt,
|
||||||
},
|
},
|
||||||
|
]),
|
||||||
...(currentProfile.isMod()
|
...(currentProfile.isMod()
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
@@ -420,11 +425,15 @@ export function dynamicActions(query: string): Group {
|
|||||||
icon: MagnifyingGlass,
|
icon: MagnifyingGlass,
|
||||||
href: `/search?q=${query}`,
|
href: `/search?q=${query}`,
|
||||||
},
|
},
|
||||||
|
...(SINGLE_COMMUNITY
|
||||||
|
? []
|
||||||
|
: [
|
||||||
{
|
{
|
||||||
name: t.get('nav.commands.communities', { default: query.trim() }),
|
name: t.get('nav.commands.communities', { default: query.trim() }),
|
||||||
icon: Newspaper,
|
icon: Newspaper,
|
||||||
href: `/explore/communities?q=${query}`,
|
href: `/explore/communities?q=${query}`,
|
||||||
},
|
},
|
||||||
|
]),
|
||||||
]
|
]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -12,9 +12,10 @@
|
|||||||
import { postLink } from '$lib/feature/post/helpers.js'
|
import { postLink } from '$lib/feature/post/helpers.js'
|
||||||
import { onDestroy } from 'svelte'
|
import { onDestroy } from 'svelte'
|
||||||
|
|
||||||
let community = getSessionStorage('lastSeenCommunity') as
|
let { data } = $props()
|
||||||
| CommunityView
|
|
||||||
| undefined
|
let community = (data.singleCommunity ??
|
||||||
|
getSessionStorage('lastSeenCommunity')) as CommunityView | undefined
|
||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
setSessionStorage('lastSeenCommunity', undefined)
|
setSessionStorage('lastSeenCommunity', undefined)
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
|
import { client } from '$lib/api/client.svelte'
|
||||||
import { profile } from '$lib/app/auth'
|
import { profile } from '$lib/app/auth'
|
||||||
|
import { SINGLE_COMMUNITY } from '$lib/app/single'
|
||||||
import { redirect } from '@sveltejs/kit'
|
import { redirect } from '@sveltejs/kit'
|
||||||
|
|
||||||
export const load = () => {
|
export const load = async ({ fetch }) => {
|
||||||
if (!profile.current.jwt) redirect(302, '/login')
|
if (!profile.current.jwt) redirect(302, '/login')
|
||||||
|
// Single-community mode: every post goes to the one community, so preselect it.
|
||||||
|
if (SINGLE_COMMUNITY) {
|
||||||
|
const res = await client({ func: fetch }).getCommunity({
|
||||||
|
name: SINGLE_COMMUNITY,
|
||||||
|
})
|
||||||
|
return { singleCommunity: res.community_view }
|
||||||
|
}
|
||||||
|
return { singleCommunity: undefined }
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { resolve } from '$app/paths'
|
import { resolve } from '$app/paths'
|
||||||
|
import { env } from '$env/dynamic/public'
|
||||||
import { profile } from '$lib/app/auth'
|
import { profile } from '$lib/app/auth'
|
||||||
import { error, redirect } from '@sveltejs/kit'
|
import { error, redirect } from '@sveltejs/kit'
|
||||||
|
|
||||||
@@ -7,7 +8,9 @@ export function load({ params }) {
|
|||||||
redirect(
|
redirect(
|
||||||
302,
|
302,
|
||||||
resolve(`/post/[instance]/[id=integer]`, {
|
resolve(`/post/[instance]/[id=integer]`, {
|
||||||
instance: encodeURIComponent(profile.current.instance.toLowerCase()),
|
instance: encodeURIComponent(
|
||||||
|
(env.PUBLIC_INSTANCE_URL || profile.current.instance).toLowerCase(),
|
||||||
|
),
|
||||||
id: params.instance,
|
id: params.instance,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from '$app/state'
|
import { page } from '$app/state'
|
||||||
|
import { replaceState } from '$app/navigation'
|
||||||
|
import { prettyPostPath, prettyPostUrls } from '$lib/app/slug'
|
||||||
import { client } from '$lib/api/client.svelte'
|
import { client } from '$lib/api/client.svelte'
|
||||||
import { profile } from '$lib/app/auth'
|
import { profile } from '$lib/app/auth'
|
||||||
import { t } from '$lib/app/i18n'
|
import { t } from '$lib/app/i18n'
|
||||||
@@ -28,6 +30,18 @@
|
|||||||
|
|
||||||
let { data } = $props()
|
let { data } = $props()
|
||||||
|
|
||||||
|
// Single-community mode: show the pretty /p/<code>/<slug> address for this post, also when
|
||||||
|
// the reader arrived through an old /post/... link.
|
||||||
|
let prettyPath = $derived(
|
||||||
|
prettyPostUrls
|
||||||
|
? prettyPostPath(data.data.value.post.post.id, data.data.value.post.post.name)
|
||||||
|
: undefined,
|
||||||
|
)
|
||||||
|
$effect(() => {
|
||||||
|
if (prettyPath && page.url.pathname != prettyPath)
|
||||||
|
replaceState(prettyPath + page.url.search + page.url.hash, page.state)
|
||||||
|
})
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
data.data.value.meta.then((i) => data.data.value.post == i.post_view)
|
data.data.value.meta.then((i) => data.data.value.post == i.post_view)
|
||||||
|
|
||||||
@@ -92,7 +106,12 @@
|
|||||||
{#if !data.data.value.post.post.local}
|
{#if !data.data.value.post.post.local}
|
||||||
<meta name="robots" content="noindex, follow" />
|
<meta name="robots" content="noindex, follow" />
|
||||||
{/if}
|
{/if}
|
||||||
<link rel="canonical" href={data.data.value.post.post.ap_id} />
|
<link
|
||||||
|
rel="canonical"
|
||||||
|
href={prettyPath
|
||||||
|
? `${page.url.origin}${prettyPath}`
|
||||||
|
: data.data.value.post.post.ap_id}
|
||||||
|
/>
|
||||||
{#if data.data.value.post.post.body}
|
{#if data.data.value.post.post.body}
|
||||||
<meta
|
<meta
|
||||||
property="description"
|
property="description"
|
||||||
@@ -107,7 +126,10 @@
|
|||||||
content={data.data.value.post.post.body.slice(0, 500)}
|
content={data.data.value.post.post.body.slice(0, 500)}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
<meta property="og:url" content={page.url.toString()} />
|
<meta
|
||||||
|
property="og:url"
|
||||||
|
content={prettyPath ? `${page.url.origin}${prettyPath}` : page.url.toString()}
|
||||||
|
/>
|
||||||
{#if mediaType(data.data.value.post.post.url) == 'image'}
|
{#if mediaType(data.data.value.post.post.url) == 'image'}
|
||||||
<meta property="og:image" content={data.data.value.post.post.url} />
|
<meta property="og:image" content={data.data.value.post.post.url} />
|
||||||
<meta property="twitter:card" content={data.data.value.post.post.url} />
|
<meta property="twitter:card" content={data.data.value.post.post.url} />
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
import { browser } from '$app/environment'
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
|
import { env } from '$env/dynamic/public'
|
||||||
import { resolve } from '$app/paths'
|
import { resolve } from '$app/paths'
|
||||||
import { client } from '$lib/api/client.svelte'
|
import { client } from '$lib/api/client.svelte'
|
||||||
import { PiefedClient } from '$lib/api/piefed/adapter.js'
|
import { PiefedClient } from '$lib/api/piefed/adapter.js'
|
||||||
@@ -51,7 +53,11 @@ async function findInFeed(id: '/' | '/c/[name]' | '/f/[id]', postId: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function load({ params, url, route }) {
|
export async function load({ params, url, route }) {
|
||||||
if (profile.current.instance != params.instance) {
|
// On the server profile.current.instance is the internal API address (PUBLIC_INTERNAL_INSTANCE),
|
||||||
|
// and goto() cannot run there; compare against the public instance and only redirect in the
|
||||||
|
// browser.
|
||||||
|
const here = env.PUBLIC_INSTANCE_URL?.toLowerCase() || profile.current.instance
|
||||||
|
if (browser && here != params.instance && profile.current.instance != params.instance) {
|
||||||
goto(resolve('/post/[instance]/[id=integer]/confirm', params), {
|
goto(resolve('/post/[instance]/[id=integer]/confirm', params), {
|
||||||
replaceState: true,
|
replaceState: true,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user