1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-27 00:24:41 +01:00

Set TZ from site config

This commit is contained in:
Oliver Steele 2017-07-17 08:23:54 -04:00
parent 7e8feec5a5
commit d88b2bda2f
2 changed files with 18 additions and 2 deletions

View File

@ -44,6 +44,7 @@ type Config struct {
// Outputting
Permalink string
Timezone string
// CLI-only
DryRun bool `yaml:"-"`

View File

@ -4,11 +4,12 @@ import (
"fmt"
"os"
"path/filepath"
"time"
"github.com/osteele/gojekyll/utils"
)
// Clean the destination. Remove files that aren't in keep_files, and resulting empty diretories.
// Clean the destination. Remove files that aren't in keep_files, and resulting empty directories.
func (s *Site) Clean() error {
// TODO PERF when called as part of build, keep files that will be re-generated
removeFiles := func(filename string, info os.FileInfo, err error) error {
@ -37,8 +38,11 @@ func (s *Site) Clean() error {
}
// Build cleans the destination and create files in it.
// It attends to the global options.dry_run.
// This sets TZ from the site config.
func (s *Site) Build() (int, error) {
if err := s.setTimeZone(); err != nil {
return 0, err
}
if err := s.prepareRendering(); err != nil {
return 0, err
}
@ -47,3 +51,14 @@ func (s *Site) Build() (int, error) {
}
return s.WriteFiles()
}
func (s *Site) setTimeZone() error {
if tz := s.config.Timezone; tz != "" {
if _, err := time.LoadLocation(tz); err != nil {
fmt.Fprintf(os.Stderr, "%s; using local time zone\n", err)
} else if err := os.Setenv("TZ", tz); err != nil {
return err
}
}
return nil
}