mirror of
https://github.com/jackyzha0/hugo-obsidian.git
synced 2024-06-14 11:42:35 +03:00
improve logging
This commit is contained in:
parent
2d71f4102f
commit
5879c08972
6
main.go
6
main.go
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user