added check for posts directory
This commit is contained in:
parent
63ca2a7b46
commit
fb67ef046a
7 changed files with 37 additions and 4 deletions
2
go.mod
2
go.mod
|
@ -8,4 +8,4 @@ require (
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require golang.org/x/text v0.20.0
|
require golang.org/x/text v0.21.0
|
||||||
|
|
|
@ -89,7 +89,8 @@ func buildPageData(m Metadata, in string, out string, settings *Settings) *PageD
|
||||||
p.FooterName = settings.FooterName
|
p.FooterName = settings.FooterName
|
||||||
p.Footer = settings.Footer
|
p.Footer = settings.Footer
|
||||||
}
|
}
|
||||||
if t, ok := m["type"].(string); ok && t == "article" || t == "post" {
|
// TODO: Don't hard code posts dir name
|
||||||
|
if t, ok := m["type"].(string); util.InDir(in, "posts") && !ok || (ok && t == "article" || t == "post") {
|
||||||
p.Template = (settings.ArticleTemplate)
|
p.Template = (settings.ArticleTemplate)
|
||||||
} else {
|
} else {
|
||||||
p.Template = (settings.DefaultTemplate)
|
p.Template = (settings.DefaultTemplate)
|
||||||
|
|
|
@ -40,6 +40,27 @@ func ReplaceRoot(inPath, outRoot string) string {
|
||||||
return outPath
|
return outPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InDir checks whether checkPath is
|
||||||
|
// inside targDir.
|
||||||
|
func InDir(checkPath string, targDir string) bool {
|
||||||
|
// fmt.Println("checking dir..")
|
||||||
|
i := 0
|
||||||
|
for i < 10 {
|
||||||
|
parent := filepath.Dir(checkPath)
|
||||||
|
fmted := filepath.Base(parent)
|
||||||
|
switch fmted {
|
||||||
|
case targDir:
|
||||||
|
// fmt.Printf("%s in %s\n", checkPath, targDir)
|
||||||
|
return true
|
||||||
|
case ".":
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
checkPath = parent
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// FileExists returns a boolean indicating
|
// FileExists returns a boolean indicating
|
||||||
// whether something exists at the path.
|
// whether something exists at the path.
|
||||||
func FileExists(path string) bool {
|
func FileExists(path string) bool {
|
||||||
|
|
|
@ -5,4 +5,4 @@ fi
|
||||||
|
|
||||||
go run cmd/zona/main.go test
|
go run cmd/zona/main.go test
|
||||||
|
|
||||||
bat foobar/in.html
|
bat foobar/posts/in.html
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
type: article
|
title: tiltetest
|
||||||
---
|
---
|
||||||
|
|
||||||
# My amazing markdown file!
|
# My amazing markdown file!
|
||||||
|
|
10
test/posts/in.md
Normal file
10
test/posts/in.md
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
title: tiltetest
|
||||||
|
---
|
||||||
|
|
||||||
|
# My amazing markdown file!
|
||||||
|
|
||||||
|
I can _even_ do **this**!
|
||||||
|
|
||||||
|
- Or, I could...
|
||||||
|
- [Link](page.md) to this file
|
|
@ -1,5 +1,6 @@
|
||||||
---
|
---
|
||||||
title: Yaml testing file
|
title: Yaml testing file
|
||||||
|
type: article
|
||||||
---
|
---
|
||||||
|
|
||||||
# My amazing markdown file!
|
# My amazing markdown file!
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue