diff options
author | Adam Mathes <adam@trenchant.org> | 2017-02-09 20:14:46 -0800 |
---|---|---|
committer | Adam Mathes <adam@trenchant.org> | 2017-02-09 20:14:46 -0800 |
commit | 50f608846f1021db4f2335744cc023231fb74652 (patch) | |
tree | d75e57955029ebcda9da72a29e3c7555e02b4eb5 | |
parent | ded6e3b25bca083cabe21bda6f4d01f6766587bc (diff) | |
download | snkt-50f608846f1021db4f2335744cc023231fb74652.tar.gz snkt-50f608846f1021db4f2335744cc023231fb74652.tar.bz2 snkt-50f608846f1021db4f2335744cc023231fb74652.zip |
fix some templates, add verbose-logger
-rw-r--r-- | main.go | 18 | ||||
-rw-r--r-- | post/post.go | 23 | ||||
-rw-r--r-- | site/init.go | 9 | ||||
-rw-r--r-- | vlog/vlog.go | 14 |
4 files changed, 43 insertions, 21 deletions
@@ -9,8 +9,8 @@ import ( "snkt/render" "snkt/site" "snkt/web" + "snkt/vlog" "fmt" - "log" ) func main() { @@ -18,13 +18,13 @@ func main() { var configFile, init_dir string var build, preview, version, verbose, help bool - flag.StringVar(&configFile, "c", "config.yml", "configuration file") + flag.StringVar(&configFile, "c", "config.yml", "`configuration` file") flag.StringVar(&init_dir, "init", "", "initialize new site at `directory`") - flag.BoolVar(&build, "b", false, "build the site") - flag.BoolVar(&preview, "p", false, "start local HTTP server for preview") + flag.BoolVar(&build, "b", false, "build site") + flag.BoolVar(&preview, "p", false, "preview site with local HTTP server") flag.BoolVar(&version, "v", false, "print version number") flag.BoolVar(&help, "h", false, "help") - flag.BoolVar(&verbose, "verbose", false, "log more actions while building") + flag.BoolVar(&verbose, "verbose", false, "log actions during build") flag.Parse() if !help && !build && !preview && !version && init_dir=="" { @@ -32,7 +32,7 @@ func main() { return } if(init_dir != "") { - fmt.Printf("Initializing new site in %s\n", init_dir) + fmt.Printf("initializing new site in %s\n", init_dir) site.Init(init_dir) return } @@ -51,14 +51,16 @@ func main() { render.Init() if build { - log.Printf("Building site...\n") + vlog.Printf("building site...\n") var s site.Site + vlog.Printf("reading posts...\n") s.Read() + vlog.Printf("writing posts and archives...\n") s.Write() } if preview { - log.Printf("Spawning preview at [%s] of [%s]\n", + fmt.Printf("spawning preview at [%s] of [%s]\n", config.Config.PreviewDir, config.Config.PreviewServer) web.Serve(config.Config.PreviewServer, config.Config.PreviewDir) } diff --git a/post/post.go b/post/post.go index 19a8e73..ab1ccb6 100644 --- a/post/post.go +++ b/post/post.go @@ -8,6 +8,7 @@ import ( "snkt/config" "snkt/render" "snkt/text" + "snkt/vlog" "github.com/russross/blackfriday" "io/ioutil" "log" @@ -130,18 +131,20 @@ func (p *Post) parse() { if len(ds) > 0 { date_str = ds[0] } - var err error - p.Time, err = time.Parse("2006-1-2", date_str) - if err != nil { - - if config.Config.Verbose { - log.Println(err) - } - // fallback is to use file modtime - // should use create time but that doesn't seem to be in stdlib - // TODO: figure out how to use file birth time + if date_str == "" { p.Time = p.FileInfo.ModTime() + vlog.Printf("no date field in post %s, using file modification time\n", p.SourceFile) + } else { + var err error + p.Time, err = time.Parse("2006-1-2", date_str) + if err != nil { + // fallback is to use file modtime + // should use create time but that doesn't seem to be in stdlib + // TODO: figure out how to use file birth time + vlog.Printf("no valid date parsed for post %s, using file modification time\n", p.SourceFile) + p.Time = p.FileInfo.ModTime() + } } p.Year, p.Month, p.Day = p.Time.Date() diff --git a/site/init.go b/site/init.go index dc17cfa..02a7586 100644 --- a/site/init.go +++ b/site/init.go @@ -27,7 +27,6 @@ var skeletons = []skeleton { <title>{{template "title" .}}</title> </head> <body> - <h1>{{template "title"}}</h1> {{template "content" .}} <hr /> <p><a href="{{.Site.URL}}/index.html">Home</a></p> @@ -55,9 +54,10 @@ var skeletons = []skeleton { Dir: "tmpl", Filename: "post", Content: []byte( -`{{define "title"}}{{ .Post.Title }}{{end}} +`{{define "title"}}{{.Post.Title}} - {{.Site.Title}}{{end}} {{define "content"}} -<h2>{{ .Post.Title }}</h2> +<h1>{{.Site.Title}}</h1> +<h2>{{.Post.Title}}</h2> {{.Post.Content}} {{if .Post.Next.Title}} <p><a href="{{.Post.Next.Permalink}}">{{.Post.Next.Title}}</a></p> @@ -74,6 +74,7 @@ var skeletons = []skeleton { `{{define "title"}}{{.Site.Title}} Archives{{end}} {{define "content"}} <h1>{{ .Site.Title }}</h1> +<h2>Archives</h2> {{range .Posts}} {{if .}}<h2><a href="{{.Permalink}}">{{.Title}}</a></h2>{{end}} {{end}} @@ -124,6 +125,8 @@ func Init(directory string) { } var cfg = config.Settings{ + SiteTitle: "snkt", + SiteURL: "", TxtDir: path.Join(init_dir, "txt"), HtmlDir: path.Join(init_dir, "html"), TmplDir: path.Join(init_dir, "tmpl"), diff --git a/vlog/vlog.go b/vlog/vlog.go new file mode 100644 index 0000000..9ef771c --- /dev/null +++ b/vlog/vlog.go @@ -0,0 +1,14 @@ +// package vlog wraps log actions and only performs them if "verbose" config is set +package vlog + +import ( + "snkt/config" + "log" +) + +func Printf(format string, v ...interface{}) { + if config.Config.Verbose { + log.Printf(format, v...) + } +} + |