Skip to content

Commit b03639b

Browse files
committed
Tidy up link fixes
1 parent 37c54ae commit b03639b

File tree

1 file changed

+16
-11
lines changed
  • internal/generate-chezmoi.io-content-docs

1 file changed

+16
-11
lines changed

internal/generate-chezmoi.io-content-docs/main.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,20 @@ import (
66
"fmt"
77
"log"
88
"os"
9+
"path"
910
"regexp"
11+
"strings"
1012
)
1113

1214
var (
1315
debug = flag.Bool("debug", false, "debug")
1416
shortTitle = flag.String("shorttitle", "", "short title")
1517
longTitle = flag.String("longtitle", "", "long title")
1618

17-
replaceURLRegexps = map[string]*regexp.Regexp{
18-
"/docs/changes/": regexp.MustCompile(`https://github.com/twpayne/chezmoi/blob/master/docs/CHANGES.md`),
19-
"/docs/contributing/": regexp.MustCompile(`https://github.com/twpayne/chezmoi/blob/master/docs/CONTRIBUTING.md`),
20-
"/docs/faq/": regexp.MustCompile(`https://github.com/twpayne/chezmoi/blob/master/docs/FAQ.md`),
21-
"/docs/how-to/": regexp.MustCompile(`https://github.com/twpayne/chezmoi/blob/master/docs/HOWTO.md`),
22-
"/docs/install/": regexp.MustCompile(`https://github.com/twpayne/chezmoi/blob/master/docs/INSTALL.md`),
23-
"/docs/quick-start/": regexp.MustCompile(`https://github.com/twpayne/chezmoi/blob/master/docs/QUICKSTART.md`),
24-
"/docs/reference/": regexp.MustCompile(`https://github.com/twpayne/chezmoi/blob/master/docs/REFERENCE.md`),
19+
replaceURLRegexp = regexp.MustCompile(`https://github.com/twpayne/chezmoi/blob/master/docs/[A-Z]+.md`)
20+
nonStandardPageRenames = map[string]string{
21+
"HOWTO": "how-to",
22+
"QUICKSTART": "quick-start",
2523
}
2624
)
2725

@@ -56,9 +54,16 @@ func run() error {
5654
}
5755
case "copy-content":
5856
text := s.Text()
59-
for docsURL, re := range replaceURLRegexps {
60-
text = re.ReplaceAllString(text, docsURL)
61-
}
57+
text = replaceURLRegexp.ReplaceAllStringFunc(text, func(s string) string {
58+
name := path.Base(s)
59+
name = strings.TrimSuffix(name, path.Ext(name))
60+
var ok bool
61+
newName, ok := nonStandardPageRenames[name]
62+
if !ok {
63+
newName = strings.ToLower(name)
64+
}
65+
return "/docs/" + newName + "/"
66+
})
6267
fmt.Println(text)
6368
}
6469
}

0 commit comments

Comments
 (0)