mirror of
https://github.com/jackyzha0/hugo-obsidian.git
synced 2024-06-14 11:42:35 +03:00
normalize path in contenIndex
This commit is contained in:
parent
2be4e959e9
commit
77c0921bf4
10
main.go
10
main.go
@ -31,10 +31,10 @@ type Index struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Content struct {
|
type Content struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
LastModified time.Time `json:"lastmodified"`
|
LastModified time.Time `json:"lastmodified"`
|
||||||
Tags []string `json:"tags"`
|
Tags []string `json:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContentIndex = map[string]Content
|
type ContentIndex = map[string]Content
|
||||||
@ -46,7 +46,7 @@ type ConfigTOML struct {
|
|||||||
func getIgnoredFiles(base string) (res map[string]struct{}) {
|
func getIgnoredFiles(base string) (res map[string]struct{}) {
|
||||||
res = make(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 {
|
if err != nil {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
10
walk.go
10
walk.go
@ -19,10 +19,13 @@ func walk(root, ext string, index bool, ignorePaths map[string]struct{}) (res []
|
|||||||
m.Handle("---", front.YAMLHandler)
|
m.Handle("---", front.YAMLHandler)
|
||||||
nPrivate := 0
|
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 {
|
if e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// path normalize fp
|
||||||
|
s := filepath.ToSlash(fp)
|
||||||
if _, ignored := ignorePaths[s]; ignored {
|
if _, ignored := ignorePaths[s]; ignored {
|
||||||
fmt.Printf("[Ignored] %s\n", d.Name())
|
fmt.Printf("[Ignored] %s\n", d.Name())
|
||||||
nPrivate++
|
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))
|
adjustedPath := UnicodeSanitize(strings.Replace(hugoPathTrim(trim(s, root, ".md")), " ", "-", -1))
|
||||||
i[adjustedPath] = Content{
|
i[adjustedPath] = Content{
|
||||||
LastModified: info.ModTime(),
|
LastModified: info.ModTime(),
|
||||||
Title: title,
|
Title: title,
|
||||||
Content: body,
|
Content: body,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("[Ignored] %s\n", d.Name())
|
fmt.Printf("[Ignored] %s\n", d.Name())
|
||||||
@ -78,4 +81,3 @@ func getText(dir string) string {
|
|||||||
|
|
||||||
return string(fileBytes)
|
return string(fileBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user