Page generation to use title instead of key

This commit is contained in:
2026-05-22 13:21:08 +02:00
parent 835d1153f0
commit a17477cff1
4 changed files with 104 additions and 20 deletions
+16 -13
View File
@@ -44,7 +44,7 @@ func TestBuildNativeGeneratesAndSkipsWikiPages(t *testing.T) {
if result.WikiPages != generatedHTMLCount {
t.Fatalf("expected wiki page count to match generated HTML files, got result=%d files=%d", result.WikiPages, generatedHTMLCount)
}
pagePath := filepath.Join(root, ".cache", "wiki", "pages", "skills", "athletics.html")
pagePath := filepath.Join(root, ".cache", "wiki", "pages", "skills", "Athletics.html")
got, err := os.ReadFile(pagePath)
if err != nil {
t.Fatalf("read generated page: %v", err)
@@ -85,7 +85,7 @@ func TestBuildNativeGeneratesAndSkipsWikiPages(t *testing.T) {
t.Fatalf("expected page-index entries to match generated HTML files, got index=%d files=%d", len(pageIndex.Pages), generatedHTMLCount)
}
indexText := string(indexRaw)
if !strings.Contains(indexText, `"page_id": "skills:athletics"`) || !strings.Contains(indexText, `"public_path": "Skills/Athletics"`) || strings.Contains(indexText, `"public_slug"`) || !strings.Contains(indexText, `"output_path": "pages/skills/athletics.html"`) || !strings.Contains(indexText, `"edit_policy": "preserve_manual_sections"`) {
if !strings.Contains(indexText, `"page_id": "skills:athletics"`) || !strings.Contains(indexText, `"public_path": "Skills/Athletics"`) || strings.Contains(indexText, `"public_slug"`) || !strings.Contains(indexText, `"output_path": "pages/skills/Athletics.html"`) || !strings.Contains(indexText, `"edit_policy": "preserve_manual_sections"`) {
t.Fatalf("expected deterministic page-index metadata, got:\n%s", indexText)
}
if !strings.Contains(indexText, `"page_id": "meta:wikistatus"`) || !strings.Contains(indexText, `"output_path": "pages/meta/wikistatus.html"`) || !strings.Contains(indexText, `"edit_policy": "generated_only"`) {
@@ -160,7 +160,7 @@ func TestBuildWikiRegeneratesMissingCachedPages(t *testing.T) {
if result.Status != wikiGeneratedStatus {
t.Fatalf("expected missing cached pages to regenerate, got wiki status %q", result.Status)
}
if _, err := os.Stat(filepath.Join(pagesDir, "skills", "athletics.html")); err != nil {
if _, err := os.Stat(filepath.Join(pagesDir, "skills", "Athletics.html")); err != nil {
t.Fatalf("expected regenerated skill page: %v", err)
}
@@ -934,14 +934,14 @@ datasets:
}
}
for _, path := range []string{
filepath.Join(root, ".cache", "wiki", "pages", "feat", "visible.html"),
filepath.Join(root, ".cache", "wiki", "pages", "feat", "class_only.html"),
filepath.Join(root, ".cache", "wiki", "pages", "feat", "Visible_Feat.html"),
filepath.Join(root, ".cache", "wiki", "pages", "feat", "Class_Feat.html"),
} {
if _, err := os.Stat(path); err != nil {
t.Fatalf("expected visible wiki page %s: %v", path, err)
}
}
classPage, err := os.ReadFile(filepath.Join(root, ".cache", "wiki", "pages", "classes", "fighter.html"))
classPage, err := os.ReadFile(filepath.Join(root, ".cache", "wiki", "pages", "classes", "Fighter.html"))
if err != nil {
t.Fatalf("read class page: %v", err)
}
@@ -1321,20 +1321,23 @@ func TestWikiSourceDigestIncludesTemplates(t *testing.T) {
func TestWikiPageIDForKeyNormalizesSlashSeparatorsOnly(t *testing.T) {
got := wikiPageIDForKey("feat:special/attacks_bull_rush")
if want := "feat:special:attacks_bull_rush"; got != want {
if want := "feat:special_attacks_bull_rush"; got != want {
t.Fatalf("expected normalized page ID %q, got %q", want, got)
}
if got := wikiPageIDForKey("feat:bardic_music_inspire_competence"); got != "feat:bardic_music_inspire_competence" {
t.Fatalf("expected underscore to remain in page ID leaf, got %q", got)
}
if got := wikiPageIDForKey("feat:bardic_music/inspire_competence"); got != "feat:bardic_music_inspire_competence" {
t.Fatalf("expected slash-authored key to stay in one page ID leaf, got %q", got)
}
}
func TestWikiPageIDToRelPathKeepsUnderscoreInFileLeaf(t *testing.T) {
if got, want := wikiPageIDToRelPath("feat:bardic_music_inspire_competence"), filepath.FromSlash("feat/bardic_music_inspire_competence.html"); got != want {
func TestWikiPageOutputRelPathUsesCanonicalTitleLeaf(t *testing.T) {
if got, want := wikiPageOutputRelPath("feat:bardic_music_inspire_competence", "Inspire Competence"), filepath.FromSlash("feat/Inspire_Competence.html"); got != want {
t.Fatalf("expected underscore page ID to stay in one file leaf, got %q want %q", got, want)
}
if got := wikiPageIDToRelPath("feat:bardic:music:inspire:competence"); got == filepath.FromSlash("feat/bardic_music_inspire_competence.html") {
t.Fatalf("expected explicit hierarchy path to remain distinct from underscore leaf, got %q", got)
if got, want := wikiPageOutputRelPath(wikiPageIDForKey("feat:bardic_music/inspire_competence"), "Inspire Competence"), filepath.FromSlash("feat/Inspire_Competence.html"); got != want {
t.Fatalf("expected slash-authored key to stay in one file leaf, got %q want %q", got, want)
}
}
@@ -1531,7 +1534,7 @@ func TestBuildNativeRegeneratesWikiWhenTLKTextChanges(t *testing.T) {
if _, err := BuildNative(proj, nil); err != nil {
t.Fatalf("BuildNative after text change failed: %v", err)
}
pagePath := filepath.Join(root, ".cache", "wiki", "pages", "skills", "athletics.html")
pagePath := filepath.Join(root, ".cache", "wiki", "pages", "skills", "Athletics.html")
got, err := os.ReadFile(pagePath)
if err != nil {
t.Fatalf("read regenerated page: %v", err)
@@ -1573,7 +1576,7 @@ func TestBuildPackageIgnoresWikiSourcesForFreshness(t *testing.T) {
t.Fatalf("BuildNative failed: %v", err)
}
pagePath := filepath.Join(root, ".cache", "wiki", "pages", "skills", "athletics.html")
pagePath := filepath.Join(root, ".cache", "wiki", "pages", "skills", "Athletics.html")
newTime := time.Now().Add(2 * time.Second)
if err := os.Chtimes(pagePath, newTime, newTime); err != nil {
t.Fatalf("touch wiki page: %v", err)