package main import ( "fmt" "path/filepath" "strings" ) func trim(source, prefix, suffix string) string { return strings.TrimPrefix(strings.TrimSuffix(source, suffix), prefix) } func hugoPathTrim(source string) string { return strings.TrimSuffix(strings.TrimSuffix(source, "/index"), "_index") } func processTarget(source string) string { if !isInternal(source) { return source } if strings.HasPrefix(source, "/") { return strings.TrimSuffix(source, ".md") } return "/" + strings.TrimSuffix(strings.TrimSuffix(source, ".html"), ".md") } func isInternal(link string) bool { return !strings.HasPrefix(link, "http") } // filter out certain links (e.g. to media) func filter(links []Link) (res []Link) { for _, l := range links { // filter external and non-md isMarkdown := filepath.Ext(l.Target) == "" || filepath.Ext(l.Target) == ".md" if isInternal(l.Target) && isMarkdown { res = append(res, l) } } fmt.Printf("Removed %d external and non-markdown links\n", len(links)-len(res)) return res }