Page generation to use title instead of key
This commit is contained in:
@@ -189,9 +189,15 @@ func buildWiki(p *project.Project, nativeResult BuildResult, force bool, progres
|
||||
pageTitles := map[string]string{}
|
||||
pageStatuses := map[string]string{}
|
||||
pageIndex := wikiPageIndex{Version: wikiGeneratorVersion}
|
||||
outputPaths := map[string]string{}
|
||||
|
||||
writePage := func(pageID, content, title, status string) error {
|
||||
path := filepath.Join(outputDir, wikiPageIDToRelPath(pageID))
|
||||
relPath := wikiPageOutputRelPath(pageID, title)
|
||||
if previous := outputPaths[relPath]; previous != "" {
|
||||
return fmt.Errorf("duplicate wiki page output path %q for %s and %s", filepath.ToSlash(relPath), previous, pageID)
|
||||
}
|
||||
outputPaths[relPath] = pageID
|
||||
path := filepath.Join(outputDir, relPath)
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -366,15 +372,18 @@ func indexUnregisteredWikiPages(rootDir, outputDir, stalePolicy string, index *w
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pageID := strings.TrimSuffix(filepath.ToSlash(relToPages), filepath.Ext(relToPages))
|
||||
pageID = strings.ReplaceAll(pageID, "/", ":")
|
||||
if _, ok := seen[pageID]; ok {
|
||||
return nil
|
||||
}
|
||||
raw, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pageID := extractWikiPageID(string(raw))
|
||||
if pageID == "" {
|
||||
pageID = strings.TrimSuffix(filepath.ToSlash(relToPages), filepath.Ext(relToPages))
|
||||
pageID = strings.ReplaceAll(pageID, "/", ":")
|
||||
}
|
||||
if _, ok := seen[pageID]; ok {
|
||||
return nil
|
||||
}
|
||||
namespace := strings.SplitN(pageID, ":", 2)[0]
|
||||
relToRoot, err := filepath.Rel(rootDir, path)
|
||||
if err != nil {
|
||||
@@ -1669,7 +1678,7 @@ func wikiPageIDForKey(key string) string {
|
||||
if namespace == "" {
|
||||
return ""
|
||||
}
|
||||
value = strings.NewReplacer("/", ":", "\\", ":").Replace(value)
|
||||
value = strings.NewReplacer("/", "_", "\\", "_").Replace(value)
|
||||
return namespace + ":" + value
|
||||
}
|
||||
|
||||
@@ -1711,6 +1720,23 @@ func wikiSlugifyTitle(value string) string {
|
||||
return slugifyWikiText(value, "topic")
|
||||
}
|
||||
|
||||
func wikiPageOutputRelPath(pageID, title string) string {
|
||||
namespace := strings.TrimSpace(strings.SplitN(pageID, ":", 2)[0])
|
||||
if namespace == "" {
|
||||
namespace = "page"
|
||||
}
|
||||
parts := []string{namespace}
|
||||
for _, part := range strings.Split(title, " :: ") {
|
||||
parts = append(parts, part)
|
||||
}
|
||||
path := canonicalWikiPath(parts...)
|
||||
if path == "" {
|
||||
path = wikiPageIDToRelPath(pageID)
|
||||
return path
|
||||
}
|
||||
return filepath.FromSlash(path + ".html")
|
||||
}
|
||||
|
||||
func wikiPageIDToRelPath(pageID string) string {
|
||||
return filepath.FromSlash(strings.ReplaceAll(pageID, ":", "/") + ".html")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user