improve logging

This commit is contained in:
jackyzha0 2021-07-17 01:26:45 -04:00
parent 2d71f4102f
commit 5879c08972

View File

@ -2,6 +2,7 @@ package main
import ( import (
"flag" "flag"
"fmt"
md "github.com/nikitavoloboev/markdown-parser" md "github.com/nikitavoloboev/markdown-parser"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"io/fs" "io/fs"
@ -37,7 +38,9 @@ func parse(dir, pathPrefix string) []Link {
// parse md // parse md
var links []Link var links []Link
fmt.Printf("%s\n", trim(dir, pathPrefix, ".md"))
for text, target := range md.GetAllLinks(string(bytes)) { for text, target := range md.GetAllLinks(string(bytes)) {
fmt.Printf(" %s\n", trim(target, pathPrefix, ".md"))
links = append(links, Link{ links = append(links, Link{
Source: trim(dir, pathPrefix, ".md"), Source: trim(dir, pathPrefix, ".md"),
Target: target, Target: target,
@ -62,6 +65,7 @@ func walk(root, ext string) (res []Link) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
fmt.Printf("parsed %d total links \n", len(res))
return res return res
} }
@ -69,13 +73,13 @@ func walk(root, ext string) (res []Link) {
func filter(links []Link) (res []Link) { func filter(links []Link) (res []Link) {
for _, l := range links { for _, l := range links {
// filter external and non-md // filter external and non-md
println(l.Target)
isInternal := strings.HasPrefix(l.Target, "/") isInternal := strings.HasPrefix(l.Target, "/")
isMarkdown := filepath.Ext(l.Target) == "" || filepath.Ext(l.Target) == ".md" isMarkdown := filepath.Ext(l.Target) == "" || filepath.Ext(l.Target) == ".md"
if isInternal && isMarkdown { if isInternal && isMarkdown {
res = append(res, l) res = append(res, l)
} }
} }
fmt.Printf("removed %d external and non-markdown links\n", len(links) - len(res))
return res return res
} }