feat: pretty post URLs /p/<code>/<title-slug> in single-community mode
The code is the post id through a reversible 32-bit mix in base36: unique, short, and not the raw sequential id. Only the code resolves the post (via the reroute hook), so the slug can change with the title. Feed links, the share button, canonical and og:url use the pretty form, and old /post/<instance>/<id> links are rewritten in the address bar. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011c5BZVwWdVLrdQi9htmuth
This commit is contained in:
1 parent
302700ef66
commit
8e7c5be4c8
6 files changed
+109
-4
No files matched your search
@@ -1,5 +1,6 @@
|
||||
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
|
||||
@@ -9,6 +10,9 @@ import { SINGLE_COMMUNITY } from '$lib/app/single'
|
||||
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\/([^/]+)\/?$/)
|
||||
|
||||
Reference in new issue
Block a user