feat: H1 conversion on the API, markdown and import paths

- the /_journal/api/v1 post writes convert default and translated content
  in the write transaction and answer an additive notices key
- journal:import-posts converts and prints the converted count
  (ImportFromDirConfig, ImportStats.H1Converted)
- a category's pillar text saved in the admin answers
  editor.h1_converted_category
- every GET /categories row reports content_h1_to_h2 (additive key)
This commit is contained in:
Jakub Zych
2026-11-04 09:51:47 +01:00
parent 305f94afd9
commit faaa9b0f55
11 changed files with 459 additions and 42 deletions

View File

@@ -60,3 +60,39 @@ func CountH1(html string) int {
func containsFold(s, sub string) bool {
return strings.Contains(strings.ToLower(s), sub)
}
// ConvertContentH1 applies ConvertH1 to a post body and its rendered HTML
// (content and content_html) and returns both with the number of headings
// converted: content_html's count, or content's when content_html had none
// (a markdown body has no h1 tag, its rendered HTML does).
func ConvertContentH1(content, contentHTML string) (string, string, int) {
content, nContent := ConvertH1(content)
contentHTML, nHTML := ConvertH1(contentHTML)
if nHTML > 0 {
return content, contentHTML, nHTML
}
return content, contentHTML, nContent
}
// ConvertTranslationH1 applies ConvertContentH1 to the string content and
// content_html of one locale's translated attributes, in place, and returns
// the number of headings converted. Other attributes and values that are
// not strings are left alone.
func ConvertTranslationH1(attrs map[string]any) int {
if attrs == nil {
return 0
}
content, hasContent := attrs["content"].(string)
html, hasHTML := attrs["content_html"].(string)
if !hasContent && !hasHTML {
return 0
}
content, html, n := ConvertContentH1(content, html)
if hasContent {
attrs["content"] = content
}
if hasHTML {
attrs["content_html"] = html
}
return n
}