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:
15
server/src/model/wiki/wiki.links.js
Normal file
15
server/src/model/wiki/wiki.links.js
Normal file
@@ -0,0 +1,15 @@
|
||||
// Extract internal wiki-link targets from a saved (already sanitized) body.
|
||||
// Internal links are anchors to /wiki/<slug> or elements carrying a
|
||||
// data-wiki-slug attribute. Returns a de-duplicated array of slugs.
|
||||
function extractTargets(html) {
|
||||
if (!html) return []
|
||||
const targets = new Set()
|
||||
const hrefRe = /href="\/wiki\/([a-z0-9-]+)"/g
|
||||
const dataRe = /data-wiki-slug="([a-z0-9-]+)"/g
|
||||
let m
|
||||
while ((m = hrefRe.exec(html))) targets.add(m[1])
|
||||
while ((m = dataRe.exec(html))) targets.add(m[1])
|
||||
return [...targets]
|
||||
}
|
||||
|
||||
module.exports = { extractTargets }
|
||||
Reference in New Issue
Block a user