Compare commits

..
1 Commits
Author SHA1 Message Date
larsiandClaude Opus 5.5 a9bf3497fe feat: single-community mode (PUBLIC_SINGLE_COMMUNITY)
For instances that are one community (thebitcoin.win): "/" reroutes to the
community page, community browsing and explore lead back to it, community
names/handles are hidden on posts and in the header, and create-post
preselects the community. Unset, behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011c5BZVwWdVLrdQi9htmuth
2026-11-14 01:06:07 +01:00
11 changed files with 105 additions and 27 deletions

No files matched your search

+18
View File
@@ -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)
<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
+16
View File
@@ -0,0 +1,16 @@
import type { Reroute } from '@sveltejs/kit'
import { SINGLE_COMMUNITY } from '$lib/app/single'
/**
* 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
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
}
+11
View File
@@ -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
@@ -1,4 +1,5 @@
<script lang="ts">
import { SINGLE_COMMUNITY } from '$lib/app/single'
import { client } from '$lib/api/client.svelte'
import type {
Community,
@@ -109,6 +110,7 @@
class={['tracking-normal', clazz]}
>
{#snippet nameDetail()}
{#if !SINGLE_COMMUNITY}
<button
onclick={() => {
navigator?.clipboard?.writeText?.(
@@ -120,6 +122,7 @@
>
!{fullCommunityName(community.name, community.actor_id)}
</button>
{/if}
{/snippet}
{#if moderators.length > 0}
<Expandable class={[compact == 'lg' && 'lg:hidden']}>
+4 -3
View File
@@ -1,4 +1,5 @@
<script lang="ts" module>
import { SINGLE_COMMUNITY } from '$lib/app/single'
import type { Community, Person, SubscribedType } from '$lib/api/types'
import { profile } from '$lib/app/auth'
import { t } from '$lib/app/i18n'
@@ -197,13 +198,13 @@
<header
class={[
'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',
]}
class:compact={view == 'compact'}
{style}
>
{#if showCommunity && community}
{#if showCommunity && community && !SINGLE_COMMUNITY}
<Popover>
{#snippet target(attachment)}
<button
@@ -249,7 +250,7 @@
{/snippet}
</Popover>
{/if}
{#if showCommunity && community}
{#if showCommunity && community && !SINGLE_COMMUNITY}
<CommunityLink
{community}
style="grid-area: community;"
+6 -3
View File
@@ -1,4 +1,5 @@
<script lang="ts">
import { SINGLE_COMMUNITY } from '$lib/app/single'
import type { PostView } from '$lib/api/types'
import { settings } from '$lib/app/settings.svelte'
import Placeholder from '$lib/ui/info/Placeholder.svelte'
@@ -41,9 +42,11 @@
title="No posts"
description="There are no posts that match this filter."
>
<Button href="/communities" icon={Plus}>
<span>Follow some communities</span>
</Button>
{#if !SINGLE_COMMUNITY}
<Button href="/communities" icon={Plus}>
<span>Follow some communities</span>
</Button>
{/if}
</Placeholder>
</div>
{:else}
@@ -1,4 +1,5 @@
<script lang="ts">
import { SINGLE_COMMUNITY } from '$lib/app/single'
import { browser } from '$app/environment'
import { client } from '$lib/api/client.svelte'
import type { GetPosts, PostView } from '$lib/api/types'
@@ -163,6 +164,7 @@
title={$t('routes.frontpage.empty.title')}
description={$t('routes.frontpage.empty.description')}
>
{#if !SINGLE_COMMUNITY}
<Button
href="/communities"
rounding="pill"
@@ -171,6 +173,7 @@
>
{$t('nav.communities')}
</Button>
{/if}
</Placeholder>
</div>
{:else}
+10 -7
View File
@@ -1,4 +1,5 @@
<script lang="ts">
import { SINGLE_COMMUNITY } from '$lib/app/single'
import { site } from '$lib/api/client.svelte'
import { profile } from '$lib/app/auth'
import { t } from '$lib/app/i18n'
@@ -89,13 +90,15 @@
/>
{/if}
</div>
<NavButton
href="/explore/communities"
label={$t('routes.explore.title')}
icon={GlobeAlt}
isSelectedFilter={(path) => path.startsWith('/explore')}
class="order-1"
/>
{#if !SINGLE_COMMUNITY}
<NavButton
href="/explore/communities"
label={$t('routes.explore.title')}
icon={GlobeAlt}
isSelectedFilter={(path) => path.startsWith('/explore')}
class="order-1"
/>
{/if}
<NavButton
href="/search"
label={$t('nav.search')}
+19 -10
View File
@@ -1,3 +1,4 @@
import { SINGLE_COMMUNITY } from '$lib/app/single'
import { goto } from '$app/navigation'
import { page } from '$app/state'
import { profile as currentProfile, type ProfileInfo } from '$lib/app/auth'
@@ -85,11 +86,15 @@ export function getGroups(
name: t.get('nav.commands.main'),
actions: [
{ href: '/', name: t.get('nav.home'), icon: Home, shortcut: 'h' },
{
href: '/communities',
name: t.get('nav.communities'),
icon: GlobeAlt,
},
...(SINGLE_COMMUNITY
? []
: [
{
href: '/communities',
name: t.get('nav.communities'),
icon: GlobeAlt,
},
]),
...(currentProfile.isMod()
? [
{
@@ -420,11 +425,15 @@ export function dynamicActions(query: string): Group {
icon: MagnifyingGlass,
href: `/search?q=${query}`,
},
{
name: t.get('nav.commands.communities', { default: query.trim() }),
icon: Newspaper,
href: `/explore/communities?q=${query}`,
},
...(SINGLE_COMMUNITY
? []
: [
{
name: t.get('nav.commands.communities', { default: query.trim() }),
icon: Newspaper,
href: `/explore/communities?q=${query}`,
},
]),
]
return {
+4 -3
View File
@@ -12,9 +12,10 @@
import { postLink } from '$lib/feature/post/helpers.js'
import { onDestroy } from 'svelte'
let community = getSessionStorage('lastSeenCommunity') as
| CommunityView
| undefined
let { data } = $props()
let community = (data.singleCommunity ??
getSessionStorage('lastSeenCommunity')) as CommunityView | undefined
onDestroy(() => {
setSessionStorage('lastSeenCommunity', undefined)
+11 -1
View File
@@ -1,6 +1,16 @@
import { client } from '$lib/api/client.svelte'
import { profile } from '$lib/app/auth'
import { SINGLE_COMMUNITY } from '$lib/app/single'
import { redirect } from '@sveltejs/kit'
export const load = () => {
export const load = async ({ fetch }) => {
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 }
}