mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 05:37:27 +00:00
Docs i18n: harden doc-mode pipeline
This commit is contained in:
37
scripts/docs-i18n/order.go
Normal file
37
scripts/docs-i18n/order.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type orderedFile struct {
|
||||
path string
|
||||
rel string
|
||||
}
|
||||
|
||||
func orderFiles(docsRoot string, files []string) ([]string, error) {
|
||||
entries := make([]orderedFile, 0, len(files))
|
||||
for _, file := range files {
|
||||
abs, err := filepath.Abs(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rel, err := filepath.Rel(docsRoot, abs)
|
||||
if err != nil {
|
||||
rel = abs
|
||||
}
|
||||
entries = append(entries, orderedFile{path: file, rel: rel})
|
||||
}
|
||||
if len(entries) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
sort.Slice(entries, func(i, j int) bool {
|
||||
return entries[i].rel < entries[j].rel
|
||||
})
|
||||
ordered := make([]string, 0, len(entries))
|
||||
for _, entry := range entries {
|
||||
ordered = append(ordered, entry.path)
|
||||
}
|
||||
return ordered, nil
|
||||
}
|
||||
Reference in New Issue
Block a user