From 77c0921bf4f5ee2a75eac4de8b8db2a0ca74057b Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Tue, 15 Mar 2022 00:50:03 -0700 Subject: [PATCH 1/2] normalize path in contenIndex --- main.go | 10 +++++----- walk.go | 10 ++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 5fa7cda..f2acf00 100644 --- a/main.go +++ b/main.go @@ -31,10 +31,10 @@ type Index struct { } type Content struct { - Title string `json:"title"` - Content string `json:"content"` - LastModified time.Time `json:"lastmodified"` - Tags []string `json:"tags"` + Title string `json:"title"` + Content string `json:"content"` + LastModified time.Time `json:"lastmodified"` + Tags []string `json:"tags"` } type ContentIndex = map[string]Content @@ -46,7 +46,7 @@ type ConfigTOML struct { func getIgnoredFiles(base string) (res map[string]struct{}) { res = make(map[string]struct{}) - source, err := ioutil.ReadFile(base + "/config.toml") + source, err := ioutil.ReadFile(filepath.FromSlash("/config.toml")) if err != nil { return res } diff --git a/walk.go b/walk.go index fba7523..f44e6a9 100644 --- a/walk.go +++ b/walk.go @@ -19,10 +19,13 @@ func walk(root, ext string, index bool, ignorePaths map[string]struct{}) (res [] m.Handle("---", front.YAMLHandler) nPrivate := 0 - err := filepath.WalkDir(root, func(s string, d fs.DirEntry, e error) error { + err := filepath.WalkDir(root, func(fp string, d fs.DirEntry, e error) error { if e != nil { return e } + + // path normalize fp + s := filepath.ToSlash(fp) if _, ignored := ignorePaths[s]; ignored { fmt.Printf("[Ignored] %s\n", d.Name()) nPrivate++ @@ -50,8 +53,8 @@ func walk(root, ext string, index bool, ignorePaths map[string]struct{}) (res [] adjustedPath := UnicodeSanitize(strings.Replace(hugoPathTrim(trim(s, root, ".md")), " ", "-", -1)) i[adjustedPath] = Content{ LastModified: info.ModTime(), - Title: title, - Content: body, + Title: title, + Content: body, } } else { fmt.Printf("[Ignored] %s\n", d.Name()) @@ -78,4 +81,3 @@ func getText(dir string) string { return string(fileBytes) } - From 6caa733a1fd366661bbb7c07c76def4657d7c96e Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Tue, 15 Mar 2022 00:52:04 -0700 Subject: [PATCH 2/2] whoops, forgot base --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index f2acf00..8e86154 100644 --- a/main.go +++ b/main.go @@ -46,7 +46,7 @@ type ConfigTOML struct { func getIgnoredFiles(base string) (res map[string]struct{}) { res = make(map[string]struct{}) - source, err := ioutil.ReadFile(filepath.FromSlash("/config.toml")) + source, err := ioutil.ReadFile(filepath.FromSlash(base + "/config.toml")) if err != nil { return res }