Skip to content

Commit

Permalink
Tidy up link fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Mar 4, 2020
1 parent 37c54ae commit b03639b
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions internal/generate-chezmoi.io-content-docs/main.go
Expand Up @@ -6,22 +6,20 @@ import (
"fmt"
"log"
"os"
"path"
"regexp"
"strings"
)

var (
debug = flag.Bool("debug", false, "debug")
shortTitle = flag.String("shorttitle", "", "short title")
longTitle = flag.String("longtitle", "", "long title")

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

Expand Down Expand Up @@ -56,9 +54,16 @@ func run() error {
}
case "copy-content":
text := s.Text()
for docsURL, re := range replaceURLRegexps {
text = re.ReplaceAllString(text, docsURL)
}
text = replaceURLRegexp.ReplaceAllStringFunc(text, func(s string) string {
name := path.Base(s)
name = strings.TrimSuffix(name, path.Ext(name))
var ok bool
newName, ok := nonStandardPageRenames[name]
if !ok {
newName = strings.ToLower(name)
}
return "/docs/" + newName + "/"
})
fmt.Println(text)
}
}
Expand Down

0 comments on commit b03639b

Please sign in to comment.