skip drafts
This commit is contained in:
parent
7ac987fa42
commit
4947b7123e
2 changed files with 30 additions and 11 deletions
|
@ -16,6 +16,7 @@ type Content struct {
|
||||||
Categories []string
|
Categories []string
|
||||||
Tags []string
|
Tags []string
|
||||||
Date time.Time
|
Date time.Time
|
||||||
|
Draft bool
|
||||||
|
|
||||||
Filepath string
|
Filepath string
|
||||||
Subdir string
|
Subdir string
|
||||||
|
|
36
main.go
36
main.go
|
@ -29,15 +29,17 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var ext, processor, source, destination, cfgpath string
|
var ext, processor, source, destination, cfgPath string
|
||||||
var uglyurls bool
|
var uglyURLs, noSectionList, withDrafts bool
|
||||||
|
|
||||||
flag.StringVar(&ext, "ext", defaultExt, "ext to look for templates in ./layout")
|
flag.StringVar(&ext, "ext", defaultExt, "ext to look for templates in ./layout")
|
||||||
flag.StringVar(&processor, "proc", defaultProcessor, "processor to pipe markdown content through")
|
flag.StringVar(&processor, "proc", defaultProcessor, "processor to pipe markdown content through")
|
||||||
flag.StringVar(&source, "source", defaultSource, "source directory")
|
flag.StringVar(&source, "source", defaultSource, "source directory")
|
||||||
flag.StringVar(&destination, "destination", defaultDestination, "output directory")
|
flag.StringVar(&destination, "destination", defaultDestination, "output directory")
|
||||||
flag.StringVar(&cfgpath, "config", defaultConfigPath, "hugo config path")
|
flag.StringVar(&cfgPath, "config", defaultConfigPath, "hugo config path")
|
||||||
flag.BoolVar(&uglyurls, "ugly-urls", defaultUglyURLs, "use directories with index or .ext files")
|
flag.BoolVar(&uglyURLs, "ugly-urls", false, "use directories with index or .ext files")
|
||||||
|
flag.BoolVar(&noSectionList, "no-section-list", false, "disable auto append of section content lists")
|
||||||
|
flag.BoolVar(&withDrafts, "enable-withDrafts", false, "include withDrafts in processing and output")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
osfs := afero.NewOsFs()
|
osfs := afero.NewOsFs()
|
||||||
|
@ -51,7 +53,6 @@ func main() {
|
||||||
log.Println("no permalinks from config loaded, using default: ", defaultPermalinkFormat)
|
log.Println("no permalinks from config loaded, using default: ", defaultPermalinkFormat)
|
||||||
}
|
}
|
||||||
|
|
||||||
// test
|
|
||||||
linkpattern := func(subdir string) string {
|
linkpattern := func(subdir string) string {
|
||||||
format, ok := permalinks[subdir]
|
format, ok := permalinks[subdir]
|
||||||
if ok {
|
if ok {
|
||||||
|
@ -74,6 +75,10 @@ func main() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
//fmt.Printf("%s -> %s (%d)\n", file.Source, file.Destination, len(file.Body))
|
//fmt.Printf("%s -> %s (%d)\n", file.Source, file.Destination, len(file.Body))
|
||||||
|
if file.Draft && !withDrafts {
|
||||||
|
fmt.Printf("skipping draft %s (%dbytes)\n", file.Source, len(file.Body))
|
||||||
|
continue
|
||||||
|
}
|
||||||
tree.Files = append(tree.Files, file)
|
tree.Files = append(tree.Files, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +120,7 @@ func main() {
|
||||||
}
|
}
|
||||||
// TODO: change dir^
|
// TODO: change dir^
|
||||||
// TODO: consider links
|
// TODO: consider links
|
||||||
if uglyurls {
|
if uglyURLs {
|
||||||
outdir += ".gmi"
|
outdir += ".gmi"
|
||||||
outfile = ""
|
outfile = ""
|
||||||
}
|
}
|
||||||
|
@ -136,6 +141,13 @@ func main() {
|
||||||
fmt.Printf("written %s (%dbytes)\n", fullpath, n)
|
fmt.Printf("written %s (%dbytes)\n", fullpath, n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// ugly urls
|
||||||
|
//
|
||||||
|
// append section listings
|
||||||
|
// => link title line
|
||||||
|
// date - summary block
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// check/replace links
|
// check/replace links
|
||||||
// write rss?
|
// write rss?
|
||||||
|
@ -154,6 +166,8 @@ type File struct {
|
||||||
Name string
|
Name string
|
||||||
Extension string
|
Extension string
|
||||||
|
|
||||||
|
Draft bool
|
||||||
|
|
||||||
Body []byte
|
Body []byte
|
||||||
NewBody []byte
|
NewBody []byte
|
||||||
}
|
}
|
||||||
|
@ -188,6 +202,7 @@ func destinationPath(file *File, pattern string) error {
|
||||||
}
|
}
|
||||||
c.Filepath = file.Name
|
c.Filepath = file.Name
|
||||||
file.Body = body
|
file.Body = body
|
||||||
|
file.Draft = c.Draft
|
||||||
|
|
||||||
if file.Parent != "." {
|
if file.Parent != "." {
|
||||||
link, err := hugov0492.PathPattern(pattern).Expand(c)
|
link, err := hugov0492.PathPattern(pattern).Expand(c)
|
||||||
|
@ -243,15 +258,18 @@ func NewContentFromMeta(meta map[string]interface{}) *hugov0492.Content {
|
||||||
Categories: stringArrayFromInterface(meta["categories"]),
|
Categories: stringArrayFromInterface(meta["categories"]),
|
||||||
Tags: stringArrayFromInterface(meta["tags"]),
|
Tags: stringArrayFromInterface(meta["tags"]),
|
||||||
Date: dateFromInterface(meta["date"]),
|
Date: dateFromInterface(meta["date"]),
|
||||||
|
Draft: boolFromInterface(meta["draft"]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func stringFromInterface(input interface{}) string {
|
func stringFromInterface(input interface{}) string {
|
||||||
str, ok := input.(string)
|
str, _ := input.(string)
|
||||||
if ok {
|
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
return ""
|
|
||||||
|
func boolFromInterface(input interface{}) bool {
|
||||||
|
v, _ := input.(bool)
|
||||||
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func dateFromInterface(input interface{}) time.Time {
|
func dateFromInterface(input interface{}) time.Time {
|
||||||
|
|
Loading…
Reference in a new issue