Wiki Phase 3: internal links, backlinks, and tags
Connectivity phase of the wiki upgrade (see WIKI_UPGRADE.md). Schema (additive new tables): wiki_tags, wiki_page_tags, wiki_links. Internal links & backlinks: - new wiki.links.js parses a saved body for /wiki/<slug> (and data-wiki-slug) targets; wiki_links is rebuilt on every save - article shows a "Linked from" section (published backlinks) and renders links to non-existent pages as red links (server returns missing_links) - editor gains an internal-link picker listing existing pages Tags: - pages accept a tags[] array; tags upsert on save, page tag-set is replaced, and orphaned tags are auto-pruned (on save and delete) - public/admin list filter by ?tag=; /wiki/tags lists tags with published counts - article shows tag chips; the index has a flat tag-filtered view; editor has a comma-separated tags field Verified end-to-end: A->B backlink appears, red link detected, link index rebuilds on edit, tag filtering + chips + pruning all work. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -38,17 +38,22 @@ function PageCard({ page }) {
|
||||
export default function Wiki() {
|
||||
const [searchParams] = useSearchParams()
|
||||
const activeCategory = searchParams.get('category')
|
||||
const { loading, error, data } = useAsync(() =>
|
||||
Promise.all([api.wikiCategories(), api.wiki()]).then(([categories, pages]) => ({
|
||||
categories,
|
||||
pages,
|
||||
})),
|
||||
const activeTag = searchParams.get('tag')
|
||||
// Tag view fetches a tag-filtered page list; otherwise all pages (grouped here).
|
||||
const { loading, error, data } = useAsync(
|
||||
() =>
|
||||
Promise.all([api.wikiCategories(), api.wiki(activeTag ? { tag: activeTag } : {})]).then(
|
||||
([categories, pages]) => ({ categories, pages }),
|
||||
),
|
||||
[activeTag],
|
||||
)
|
||||
|
||||
const allSections = data ? groupByCategory(data.categories, data.pages) : []
|
||||
const sections = activeCategory
|
||||
? allSections.filter((s) => s.slug === activeCategory)
|
||||
: allSections
|
||||
const hasPages = data && data.pages.length > 0
|
||||
const filtered = Boolean(activeCategory || activeTag)
|
||||
|
||||
return (
|
||||
<PublicLayout section="wiki">
|
||||
@@ -61,39 +66,54 @@ export default function Wiki() {
|
||||
/>
|
||||
{loading && <Loading />}
|
||||
{error && <ErrorState message="Could not load the wiki right now." />}
|
||||
{!loading && !error && !hasPages && <EmptyState>No wiki pages yet.</EmptyState>}
|
||||
{!loading && !error && !hasPages && !filtered && <EmptyState>No wiki pages yet.</EmptyState>}
|
||||
|
||||
{!loading && !error && activeCategory && (
|
||||
{!loading && !error && filtered && (
|
||||
<p className="sans" style={{ margin: '0 0 8px', fontSize: '0.85rem' }}>
|
||||
<Link to="/wiki" style={{ color: 'var(--accent)', textDecoration: 'none' }}>
|
||||
← All sections
|
||||
</Link>
|
||||
{activeTag && <span className="muted"> · Tagged #{activeTag}</span>}
|
||||
</p>
|
||||
)}
|
||||
{!loading && !error && hasPages && activeCategory && sections.length === 0 && (
|
||||
<EmptyState>No pages in this section yet.</EmptyState>
|
||||
)}
|
||||
|
||||
{sections.map((section) => (
|
||||
<section key={section.id} style={{ marginTop: 36 }}>
|
||||
<h2
|
||||
className="display"
|
||||
style={{ margin: '0 0 4px', fontSize: '1.5rem', color: 'var(--accent)' }}
|
||||
>
|
||||
{section.title}
|
||||
</h2>
|
||||
{section.description && (
|
||||
<p className="muted" style={{ margin: '0 0 16px', fontSize: '0.95rem' }}>
|
||||
{section.description}
|
||||
</p>
|
||||
)}
|
||||
<div className="grid-4" style={{ marginTop: section.description ? 0 : 12 }}>
|
||||
{section.pages.map((p) => (
|
||||
{/* Tag view: a flat list of matching pages (tags cross categories). */}
|
||||
{!loading && !error && activeTag &&
|
||||
(data.pages.length === 0 ? (
|
||||
<EmptyState>No pages with this tag.</EmptyState>
|
||||
) : (
|
||||
<div className="grid-4" style={{ marginTop: 12 }}>
|
||||
{data.pages.map((p) => (
|
||||
<PageCard key={p.slug} page={p} />
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
))}
|
||||
))}
|
||||
|
||||
{/* Category / full view: grouped sections. */}
|
||||
{!loading && !error && !activeTag && hasPages && activeCategory && sections.length === 0 && (
|
||||
<EmptyState>No pages in this section yet.</EmptyState>
|
||||
)}
|
||||
{!activeTag &&
|
||||
sections.map((section) => (
|
||||
<section key={section.id} style={{ marginTop: 36 }}>
|
||||
<h2
|
||||
className="display"
|
||||
style={{ margin: '0 0 4px', fontSize: '1.5rem', color: 'var(--accent)' }}
|
||||
>
|
||||
{section.title}
|
||||
</h2>
|
||||
{section.description && (
|
||||
<p className="muted" style={{ margin: '0 0 16px', fontSize: '0.95rem' }}>
|
||||
{section.description}
|
||||
</p>
|
||||
)}
|
||||
<div className="grid-4" style={{ marginTop: section.description ? 0 : 12 }}>
|
||||
{section.pages.map((p) => (
|
||||
<PageCard key={p.slug} page={p} />
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
))}
|
||||
</div>
|
||||
</PublicLayout>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user