diff --git a/internal/topdata/wiki_deploy.go b/internal/topdata/wiki_deploy.go index ecdd5e8..b8cd6f5 100644 --- a/internal/topdata/wiki_deploy.go +++ b/internal/topdata/wiki_deploy.go @@ -238,6 +238,7 @@ func planNodeBBDeploy(pages map[string]wikiDeployPage, manifest wikiDeployManife return nil, result, next, fmt.Errorf("wiki page %q requires --category %s= for creation", pageID, page.Namespace) } result.Created++ + page.Title = nodeBBTopicTitle(page) plans = append(plans, wikiDeployPlan{Page: page, Entry: entry, Action: "create", Content: page.Content}) continue } @@ -347,6 +348,22 @@ func extractHTMLTitle(content, fallback string) string { return namespaceTitle(parts[len(parts)-1]) } +func nodeBBTopicTitle(page wikiDeployPage) string { + title := strings.TrimSpace(page.Title) + if len([]rune(title)) >= 5 { + return title + } + namespace := strings.TrimSpace(namespaceTitle(page.Namespace)) + if namespace == "" { + namespace = "Wiki" + } + if title == "" { + parts := strings.Split(page.PageID, ":") + title = namespaceTitle(parts[len(parts)-1]) + } + return namespace + ": " + title +} + func stripSimpleTags(text string) string { var out strings.Builder inTag := false diff --git a/internal/topdata/wiki_deploy_test.go b/internal/topdata/wiki_deploy_test.go index 1581655..973dbb8 100644 --- a/internal/topdata/wiki_deploy_test.go +++ b/internal/topdata/wiki_deploy_test.go @@ -140,3 +140,57 @@ func TestDeployWikiCreatesNodeBBTopicAndWritesManifest(t *testing.T) { t.Fatalf("unexpected manifest entry: %#v", entry) } } + +func TestDeployWikiCreatesNodeBBTopicWithFallbackForShortTitle(t *testing.T) { + root := t.TempDir() + sourceDir := filepath.Join(root, "pages") + if err := os.MkdirAll(filepath.Join(sourceDir, "spells"), 0755); err != nil { + t.Fatalf("create source dir: %v", err) + } + generated := "\n

Aid

\n

Generated spell page

\n\n" + if err := os.WriteFile(filepath.Join(sourceDir, "spells", "aid.html"), []byte(generated), 0644); err != nil { + t.Fatalf("write source page: %v", err) + } + + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodPost || r.URL.Path != "/api/v3/topics" { + t.Fatalf("unexpected request %s %s", r.Method, r.URL.Path) + } + var req struct { + Title string `json:"title"` + Content string `json:"content"` + } + if err := json.NewDecoder(r.Body).Decode(&req); err != nil { + t.Fatalf("decode create request: %v", err) + } + if req.Title != "Spells: Aid" { + t.Fatalf("expected fallback title, got %q", req.Title) + } + if req.Content != generated { + t.Fatalf("expected page body to keep short h1 unchanged:\n%s", req.Content) + } + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(map[string]any{ + "response": map[string]any{ + "tid": 11, + "mainPost": map[string]any{ + "pid": 42, + "tid": 11, + }, + }, + }) + })) + defer server.Close() + + _, err := DeployWikiWithOptions(&project.Project{}, DeployWikiOptions{ + SourceDir: sourceDir, + Endpoint: server.URL, + Token: "nodebb-token", + ManifestPath: filepath.Join(root, "deploy-manifest.json"), + CategoryIDs: map[string]int{"spells": 5}, + AllowCreates: true, + }, nil) + if err != nil { + t.Fatalf("DeployWikiWithOptions create failed: %v", err) + } +} diff --git a/internal/topdata/wiki_native.go b/internal/topdata/wiki_native.go index 919eaf4..27b2cf9 100644 --- a/internal/topdata/wiki_native.go +++ b/internal/topdata/wiki_native.go @@ -833,7 +833,11 @@ func (ctx *wikiContext) renderReferenceList(values []any) string { func (ctx *wikiContext) resolveRowName(category string, row map[string]any) string { spec := specForDataset(category) - for _, field := range spec.NameFields { + nameFields := spec.NameFields + if category == "classes" { + nameFields = []string{"Name", "Plural", "Lower", "CLASS", "Label", "Short"} + } + for _, field := range nameFields { if value, ok := lookupField(row, field); ok { if text := ctx.resolveTextValue(value, nil); text != "" { return text diff --git a/internal/topdata/wiki_native_test.go b/internal/topdata/wiki_native_test.go index 1287fca..34d9741 100644 --- a/internal/topdata/wiki_native_test.go +++ b/internal/topdata/wiki_native_test.go @@ -86,6 +86,17 @@ func TestBuildNativeGeneratesAndSkipsWikiPages(t *testing.T) { } } +func TestWikiClassNamePrefersFullNameInsteadOfShortCode(t *testing.T) { + ctx := &wikiContext{} + got := ctx.resolveRowName("classes", map[string]any{ + "Name": map[string]any{"tlk": map[string]any{"key": "classes:wizard.name", "text": "Wizard"}}, + "Short": map[string]any{"tlk": map[string]any{"key": "classes:wizard.short", "text": "Wiz"}}, + }) + if got != "Wizard" { + t.Fatalf("expected full class name, got %q", got) + } +} + func TestBuildAndPackageBuildsWikiOnlyWhenRequested(t *testing.T) { root := testProjectRoot(t) mkdirAll(t, filepath.Join(root, "topdata", "data", "skills"))