feat(pipeline): write into wiki/<wing>/{sources,facts}/ when Config.Wing is set (#205 S2)
Sources -> wiki/<wing>/sources, concepts/entities -> wiki/<wing>/facts with kind: frontmatter; inventory, title resolution and back-references are confined to the target wing. Empty Wing keeps the retired layout unchanged. Mutation-checked: widening the inventory beyond the wing fails the cross-wing back-reference test; a non-plain wing name is rejected. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,13 @@ import (
|
||||
// (derived from the filename, not the LLM title). Pages whose title resolves to an
|
||||
// empty slug are skipped and returned as warnings instead.
|
||||
func BuildPages(rawPages []RawPage, sourceSlug, date string) ([]wiki.Page, []string) {
|
||||
return BuildPagesIn("", rawPages, sourceSlug, date)
|
||||
}
|
||||
|
||||
// BuildPagesIn is BuildPages for a wing: sources go to wiki/<wing>/sources/,
|
||||
// concepts and entities to wiki/<wing>/facts/ with `kind:` recording which.
|
||||
// An empty wing is the retired wiki/{sources,concepts,entities}/ layout.
|
||||
func BuildPagesIn(wing string, rawPages []RawPage, sourceSlug, date string) ([]wiki.Page, []string) {
|
||||
out := make([]wiki.Page, 0, len(rawPages))
|
||||
var warnings []string
|
||||
for _, rp := range rawPages {
|
||||
@@ -28,7 +35,7 @@ func BuildPages(rawPages []RawPage, sourceSlug, date string) ([]wiki.Page, []str
|
||||
warnings = append(warnings, fmt.Sprintf("skipped page with empty title (type: %s)", rp.Type))
|
||||
continue
|
||||
}
|
||||
out = append(out, buildPage(rp, sourceSlug, date))
|
||||
out = append(out, buildPage(rp, sourceSlug, date, wing))
|
||||
}
|
||||
return out, warnings
|
||||
}
|
||||
@@ -42,7 +49,7 @@ func computeSlug(rp RawPage, sourceSlug string) string {
|
||||
return wiki.Slug(rp.Title)
|
||||
}
|
||||
|
||||
func buildPage(rp RawPage, sourceSlug, date string) wiki.Page {
|
||||
func buildPage(rp RawPage, sourceSlug, date, wing string) wiki.Page {
|
||||
var slug, dir string
|
||||
switch rp.Type {
|
||||
case "source":
|
||||
@@ -59,8 +66,21 @@ func buildPage(rp RawPage, sourceSlug, date string) wiki.Page {
|
||||
dir = "wiki/" + rp.Type
|
||||
}
|
||||
|
||||
hall := ""
|
||||
if wing != "" {
|
||||
switch rp.Type {
|
||||
case "source":
|
||||
hall = "sources"
|
||||
default:
|
||||
hall = "facts"
|
||||
}
|
||||
dir = "wiki/" + wing + "/" + hall
|
||||
}
|
||||
path := dir + "/" + slug + ".md"
|
||||
fm := buildFrontmatter(rp, date)
|
||||
if wing != "" {
|
||||
fm = addWingFrontmatter(fm, wing, hall, rp.Type)
|
||||
}
|
||||
|
||||
return wiki.Page{
|
||||
Path: path,
|
||||
@@ -122,6 +142,16 @@ func buildFrontmatter(rp RawPage, date string) string {
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
// addWingFrontmatter inserts wing/hall (and kind for facts pages) right after
|
||||
// the opening fence of an already-built frontmatter block.
|
||||
func addWingFrontmatter(fm, wing, hall, rpType string) string {
|
||||
extra := "wing: " + wing + "\nhall: " + hall + "\n"
|
||||
if hall == "facts" {
|
||||
extra += "kind: " + rpType + "\n"
|
||||
}
|
||||
return strings.Replace(fm, "---\n", "---\n"+extra, 1)
|
||||
}
|
||||
|
||||
func yamlScalar(s string) string {
|
||||
// A raw newline or CR would end the scalar for every line-oriented
|
||||
// frontmatter reader and start a new key (PR #147 review: a title of
|
||||
|
||||
Reference in New Issue
Block a user