mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Merge pull request #10 from noahcampbell/master
Fixed section labels causing panic on windows.
This commit is contained in:
commit
47783c1f03
4 changed files with 35 additions and 15 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
||||||
hugo
|
hugo
|
||||||
docs/public*
|
docs/public*
|
||||||
|
hugo.exe
|
||||||
|
*.swp
|
||||||
|
|
|
@ -91,7 +91,7 @@ func initializePage(filename string) (page Page) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) setSection() {
|
func (p *Page) setSection() {
|
||||||
x := strings.Split(p.FileName, "/")
|
x := strings.Split(p.FileName, string(os.PathSeparator))
|
||||||
|
|
||||||
if section := x[len(x)-2]; section != "content" {
|
if section := x[len(x)-2]; section != "content" {
|
||||||
p.Section = section
|
p.Section = section
|
||||||
|
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"errors"
|
||||||
//"sync"
|
//"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -59,10 +60,13 @@ func NewSite(config *Config) *Site {
|
||||||
return &Site{c: *config, timer: nitro.Initalize()}
|
return &Site{c: *config, timer: nitro.Initalize()}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (site *Site) Build() {
|
func (site *Site) Build() (err error) {
|
||||||
site.Process()
|
if err = site.Process(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
site.Render()
|
site.Render()
|
||||||
site.Write()
|
site.Write()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (site *Site) Analyze() {
|
func (site *Site) Analyze() {
|
||||||
|
@ -70,14 +74,17 @@ func (site *Site) Analyze() {
|
||||||
site.checkDescriptions()
|
site.checkDescriptions()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (site *Site) Process() {
|
func (site *Site) Process() (err error){
|
||||||
site.initialize()
|
site.initialize()
|
||||||
site.prepTemplates()
|
site.prepTemplates()
|
||||||
site.timer.Step("initialize & template prep")
|
site.timer.Step("initialize & template prep")
|
||||||
site.CreatePages()
|
site.CreatePages()
|
||||||
site.timer.Step("import pages")
|
site.timer.Step("import pages")
|
||||||
site.BuildSiteMeta()
|
if err = site.BuildSiteMeta(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
site.timer.Step("build indexes")
|
site.timer.Step("build indexes")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (site *Site) Render() {
|
func (site *Site) Render() {
|
||||||
|
@ -213,7 +220,7 @@ func (s *Site) CreatePages() {
|
||||||
s.Pages.Sort()
|
s.Pages.Sort()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) BuildSiteMeta() {
|
func (s *Site) BuildSiteMeta() (err error) {
|
||||||
s.Indexes = make(IndexList)
|
s.Indexes = make(IndexList)
|
||||||
s.Sections = make(Index)
|
s.Sections = make(Index)
|
||||||
|
|
||||||
|
@ -243,8 +250,11 @@ func (s *Site) BuildSiteMeta() {
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Info.Indexes = s.Indexes.BuildOrderedIndexList()
|
s.Info.Indexes = s.Indexes.BuildOrderedIndexList()
|
||||||
|
if len(s.Pages) == 0 {
|
||||||
|
return errors.New(fmt.Sprintf("Unable to build site metadata, no pages found in directory %s", s.c.ContentDir))
|
||||||
|
}
|
||||||
s.Info.LastChange = s.Pages[0].Date
|
s.Info.LastChange = s.Pages[0].Date
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) RenderPages() {
|
func (s *Site) RenderPages() {
|
||||||
|
|
24
main.go
24
main.go
|
@ -90,7 +90,7 @@ func main() {
|
||||||
defer pprof.StopCPUProfile()
|
defer pprof.StopCPUProfile()
|
||||||
|
|
||||||
for i := 0; i < *cpuprofile; i++ {
|
for i := 0; i < *cpuprofile; i++ {
|
||||||
_ = buildSite(config)
|
_, _ = buildSite(config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,15 +108,20 @@ func main() {
|
||||||
|
|
||||||
if *watchMode {
|
if *watchMode {
|
||||||
fmt.Println("Watching for changes. Press ctrl+c to stop")
|
fmt.Println("Watching for changes. Press ctrl+c to stop")
|
||||||
_ = buildSite(config)
|
_, err = buildSite(config)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
err := NewWatcher(config, *port, *server)
|
err := NewWatcher(config, *port, *server)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = buildSite(config)
|
if _, err = buildSite(config); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
if *server {
|
if *server {
|
||||||
serve(*port, config)
|
serve(*port, config)
|
||||||
|
@ -135,13 +140,16 @@ func serve(port string, config *hugolib.Config) {
|
||||||
panic(http.ListenAndServe(":"+port, http.FileServer(http.Dir(config.GetAbsPath(config.PublishDir)))))
|
panic(http.ListenAndServe(":"+port, http.FileServer(http.Dir(config.GetAbsPath(config.PublishDir)))))
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildSite(config *hugolib.Config) *hugolib.Site {
|
func buildSite(config *hugolib.Config) (site *hugolib.Site, err error) {
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
site := hugolib.NewSite(config)
|
site = hugolib.NewSite(config)
|
||||||
site.Build()
|
err = site.Build()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
site.Stats()
|
site.Stats()
|
||||||
fmt.Printf("in %v ms\n", int(1000*time.Since(startTime).Seconds()))
|
fmt.Printf("in %v ms\n", int(1000*time.Since(startTime).Seconds()))
|
||||||
return site
|
return site, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func watchChange(c *hugolib.Config) {
|
func watchChange(c *hugolib.Config) {
|
||||||
|
|
Loading…
Reference in a new issue