mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Adding support for logging & verbose logging. Consolidation of error handling. Integration of jWalterWeatherman library. Fixed #137
This commit is contained in:
parent
2fa3761ec9
commit
e50b9d8ac1
15 changed files with 140 additions and 111 deletions
|
@ -15,18 +15,20 @@ package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mostafah/fsync"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"github.com/spf13/hugo/hugolib"
|
|
||||||
"github.com/spf13/hugo/utils"
|
|
||||||
"github.com/spf13/hugo/watcher"
|
|
||||||
"github.com/spf13/nitro"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/mostafah/fsync"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/hugo/hugolib"
|
||||||
|
"github.com/spf13/hugo/utils"
|
||||||
|
"github.com/spf13/hugo/watcher"
|
||||||
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
|
"github.com/spf13/nitro"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Config *hugolib.Config
|
var Config *hugolib.Config
|
||||||
|
@ -44,8 +46,8 @@ Complete documentation is available at http://hugo.spf13.com`,
|
||||||
}
|
}
|
||||||
var hugoCmdV *cobra.Command
|
var hugoCmdV *cobra.Command
|
||||||
|
|
||||||
var BuildWatch, Draft, UglyUrls, Verbose bool
|
var BuildWatch, Draft, UglyUrls, Verbose, Logging, VerboseLog bool
|
||||||
var Source, Destination, BaseUrl, CfgFile string
|
var Source, Destination, BaseUrl, CfgFile, LogFile string
|
||||||
|
|
||||||
func Execute() {
|
func Execute() {
|
||||||
AddCommands()
|
AddCommands()
|
||||||
|
@ -67,6 +69,9 @@ func init() {
|
||||||
HugoCmd.PersistentFlags().BoolVar(&UglyUrls, "uglyurls", false, "if true, use /filename.html instead of /filename/")
|
HugoCmd.PersistentFlags().BoolVar(&UglyUrls, "uglyurls", false, "if true, use /filename.html instead of /filename/")
|
||||||
HugoCmd.PersistentFlags().StringVarP(&BaseUrl, "base-url", "b", "", "hostname (and path) to the root eg. http://spf13.com/")
|
HugoCmd.PersistentFlags().StringVarP(&BaseUrl, "base-url", "b", "", "hostname (and path) to the root eg. http://spf13.com/")
|
||||||
HugoCmd.PersistentFlags().StringVar(&CfgFile, "config", "", "config file (default is path/config.yaml|json|toml)")
|
HugoCmd.PersistentFlags().StringVar(&CfgFile, "config", "", "config file (default is path/config.yaml|json|toml)")
|
||||||
|
HugoCmd.PersistentFlags().BoolVar(&Logging, "log", false, "Enable Logging")
|
||||||
|
HugoCmd.PersistentFlags().StringVar(&LogFile, "logfile", "", "Log File path (if set, logging enabled automatically)")
|
||||||
|
HugoCmd.PersistentFlags().BoolVar(&VerboseLog, "verboselog", false, "verbose logging")
|
||||||
HugoCmd.PersistentFlags().BoolVar(&nitro.AnalysisOn, "stepAnalysis", false, "display memory and timing of different steps of the program")
|
HugoCmd.PersistentFlags().BoolVar(&nitro.AnalysisOn, "stepAnalysis", false, "display memory and timing of different steps of the program")
|
||||||
HugoCmd.Flags().BoolVarP(&BuildWatch, "watch", "w", false, "watch filesystem for changes and recreate as needed")
|
HugoCmd.Flags().BoolVarP(&BuildWatch, "watch", "w", false, "watch filesystem for changes and recreate as needed")
|
||||||
hugoCmdV = HugoCmd
|
hugoCmdV = HugoCmd
|
||||||
|
@ -86,12 +91,35 @@ func InitializeConfig() {
|
||||||
if hugoCmdV.PersistentFlags().Lookup("verbose").Changed {
|
if hugoCmdV.PersistentFlags().Lookup("verbose").Changed {
|
||||||
Config.Verbose = Verbose
|
Config.Verbose = Verbose
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if hugoCmdV.PersistentFlags().Lookup("logfile").Changed {
|
||||||
|
Config.LogFile = LogFile
|
||||||
|
}
|
||||||
|
|
||||||
if BaseUrl != "" {
|
if BaseUrl != "" {
|
||||||
Config.BaseUrl = BaseUrl
|
Config.BaseUrl = BaseUrl
|
||||||
}
|
}
|
||||||
if Destination != "" {
|
if Destination != "" {
|
||||||
Config.PublishDir = Destination
|
Config.PublishDir = Destination
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if VerboseLog || Logging || Config.LogFile != "" {
|
||||||
|
if Config.LogFile != "" {
|
||||||
|
jww.SetLogFile(Config.LogFile)
|
||||||
|
} else {
|
||||||
|
jww.UseTempLogFile("hugo")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
jww.DiscardLogging()
|
||||||
|
}
|
||||||
|
|
||||||
|
if Config.Verbose {
|
||||||
|
jww.SetStdoutThreshold(jww.LevelDebug)
|
||||||
|
}
|
||||||
|
|
||||||
|
if VerboseLog {
|
||||||
|
jww.SetLogThreshold(jww.LevelDebug)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func build(watches ...bool) {
|
func build(watches ...bool) {
|
||||||
|
@ -103,8 +131,8 @@ func build(watches ...bool) {
|
||||||
utils.StopOnErr(buildSite(BuildWatch || watch))
|
utils.StopOnErr(buildSite(BuildWatch || watch))
|
||||||
|
|
||||||
if BuildWatch {
|
if BuildWatch {
|
||||||
fmt.Println("Watching for changes in", Config.GetAbsPath(Config.ContentDir))
|
jww.FEEDBACK.Println("Watching for changes in", Config.GetAbsPath(Config.ContentDir))
|
||||||
fmt.Println("Press ctrl+c to stop")
|
jww.FEEDBACK.Println("Press ctrl+c to stop")
|
||||||
utils.CheckErr(NewWatcher(0))
|
utils.CheckErr(NewWatcher(0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +151,7 @@ func getDirList() []string {
|
||||||
var a []string
|
var a []string
|
||||||
walker := func(path string, fi os.FileInfo, err error) error {
|
walker := func(path string, fi os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Walker: ", err)
|
jww.ERROR.Println("Walker: ", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +179,7 @@ func buildSite(watching ...bool) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
site.Stats()
|
site.Stats()
|
||||||
fmt.Printf("in %v ms\n", int(1000*time.Since(startTime).Seconds()))
|
jww.FEEDBACK.Printf("in %v ms\n", int(1000*time.Since(startTime).Seconds()))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,9 +210,7 @@ func NewWatcher(port int) error {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case evs := <-watcher.Event:
|
case evs := <-watcher.Event:
|
||||||
if Verbose {
|
jww.INFO.Println(evs)
|
||||||
fmt.Println(evs)
|
|
||||||
}
|
|
||||||
|
|
||||||
static_changed := false
|
static_changed := false
|
||||||
dynamic_changed := false
|
dynamic_changed := false
|
||||||
|
@ -214,7 +240,7 @@ func NewWatcher(port int) error {
|
||||||
|
|
||||||
if static_changed {
|
if static_changed {
|
||||||
fmt.Print("Static file changed, syncing\n\n")
|
fmt.Print("Static file changed, syncing\n\n")
|
||||||
utils.CheckErr(copyStatic(), fmt.Sprintf("Error copying static files to %s", Config.GetAbsPath(Config.PublishDir)))
|
utils.StopOnErr(copyStatic(), fmt.Sprintf("Error copying static files to %s", Config.GetAbsPath(Config.PublishDir)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if dynamic_changed {
|
if dynamic_changed {
|
||||||
|
|
|
@ -15,9 +15,10 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -33,22 +34,22 @@ var limit = &cobra.Command{
|
||||||
var rLimit syscall.Rlimit
|
var rLimit syscall.Rlimit
|
||||||
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error Getting Rlimit ", err)
|
jww.ERROR.Println("Error Getting Rlimit ", err)
|
||||||
}
|
}
|
||||||
fmt.Println("Current rLimit:", rLimit)
|
jww.FEEDBACK.Println("Current rLimit:", rLimit)
|
||||||
|
|
||||||
fmt.Println("Attempting to increase limit")
|
jww.FEEDBACK.Println("Attempting to increase limit")
|
||||||
rLimit.Max = 999999
|
rLimit.Max = 999999
|
||||||
rLimit.Cur = 999999
|
rLimit.Cur = 999999
|
||||||
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error Setting rLimit ", err)
|
jww.ERROR.Println("Error Setting rLimit ", err)
|
||||||
}
|
}
|
||||||
err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error Getting rLimit ", err)
|
jww.ERROR.Println("Error Getting rLimit ", err)
|
||||||
}
|
}
|
||||||
fmt.Println("rLimit after change:", rLimit)
|
jww.FEEDBACK.Println("rLimit after change:", rLimit)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,14 +57,14 @@ func tweakLimit() {
|
||||||
var rLimit syscall.Rlimit
|
var rLimit syscall.Rlimit
|
||||||
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Unable to obtain rLimit", err)
|
jww.ERROR.Println("Unable to obtain rLimit", err)
|
||||||
}
|
}
|
||||||
if rLimit.Cur < rLimit.Max {
|
if rLimit.Cur < rLimit.Max {
|
||||||
rLimit.Max = 999999
|
rLimit.Max = 999999
|
||||||
rLimit.Cur = 999999
|
rLimit.Cur = 999999
|
||||||
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Unable to increase number of open files limit", err)
|
jww.ERROR.Println("Unable to increase number of open files limit", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,13 @@ package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
)
|
)
|
||||||
|
|
||||||
var serverPort int
|
var serverPort int
|
||||||
|
@ -62,7 +64,7 @@ func server(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
// Watch runs its own server as part of the routine
|
// Watch runs its own server as part of the routine
|
||||||
if serverWatch {
|
if serverWatch {
|
||||||
fmt.Println("Watching for changes in", Config.GetAbsPath(Config.ContentDir))
|
jww.FEEDBACK.Println("Watching for changes in", Config.GetAbsPath(Config.ContentDir))
|
||||||
err := NewWatcher(serverPort)
|
err := NewWatcher(serverPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -73,21 +75,19 @@ func server(cmd *cobra.Command, args []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func serve(port int) {
|
func serve(port int) {
|
||||||
if Verbose {
|
jww.FEEDBACK.Println("Serving pages from " + Config.GetAbsPath(Config.PublishDir))
|
||||||
fmt.Println("Serving pages from " + Config.GetAbsPath(Config.PublishDir))
|
|
||||||
}
|
|
||||||
|
|
||||||
if BaseUrl == "" {
|
if BaseUrl == "" {
|
||||||
fmt.Printf("Web Server is available at %s\n", Config.BaseUrl)
|
jww.FEEDBACK.Printf("Web Server is available at %s\n", Config.BaseUrl)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Web Server is available at http://localhost:%v\n", port)
|
jww.FEEDBACK.Printf("Web Server is available at http://localhost:%v\n", port)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Press ctrl+c to stop")
|
fmt.Println("Press ctrl+c to stop")
|
||||||
|
|
||||||
err := http.ListenAndServe(":"+strconv.Itoa(port), http.FileServer(http.Dir(Config.GetAbsPath(Config.PublishDir))))
|
err := http.ListenAndServe(":"+strconv.Itoa(port), http.FileServer(http.Dir(Config.GetAbsPath(Config.PublishDir))))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error: %s\n", err.Error())
|
jww.ERROR.Printf("Error: %s\n", err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,12 @@ Make sure either hugo is in your path or provide a path to it.
|
||||||
-D, --build-drafts=false: include content marked as draft
|
-D, --build-drafts=false: include content marked as draft
|
||||||
--config="": config file (default is path/config.yaml|json|toml)
|
--config="": config file (default is path/config.yaml|json|toml)
|
||||||
-d, --destination="": filesystem path to write files to
|
-d, --destination="": filesystem path to write files to
|
||||||
|
--log=false: Enable Logging
|
||||||
|
--logfile="": Log File path (if set, logging enabled automatically)
|
||||||
-s, --source="": filesystem path to read files relative from
|
-s, --source="": filesystem path to read files relative from
|
||||||
--uglyurls=false: if true, use /filename.html instead of /filename/
|
--uglyurls=false: if true, use /filename.html instead of /filename/
|
||||||
-v, --verbose=false: verbose output
|
-v, --verbose=false: verbose output
|
||||||
|
--verboselog=false: verbose logging
|
||||||
-w, --watch=false: watch filesystem for changes and recreate as needed
|
-w, --watch=false: watch filesystem for changes and recreate as needed
|
||||||
|
|
||||||
Use "hugo help [command]" for more information about that command.
|
Use "hugo help [command]" for more information about that command.
|
||||||
|
|
|
@ -15,16 +15,18 @@ package helpers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"log"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Highlight(code string, lexer string) string {
|
func Highlight(code string, lexer string) string {
|
||||||
var pygmentsBin = "pygmentize"
|
var pygmentsBin = "pygmentize"
|
||||||
|
|
||||||
if _, err := exec.LookPath(pygmentsBin); err != nil {
|
if _, err := exec.LookPath(pygmentsBin); err != nil {
|
||||||
log.Print("Highlighting requries Pygments to be installed and in the path")
|
|
||||||
|
jww.WARN.Println("Highlighting requries Pygments to be installed and in the path")
|
||||||
return code
|
return code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +39,7 @@ func Highlight(code string, lexer string) string {
|
||||||
cmd.Stderr = &stderr
|
cmd.Stderr = &stderr
|
||||||
|
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
log.Print(stderr.String())
|
jww.ERROR.Print(stderr.String())
|
||||||
return code
|
return code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,13 +14,10 @@
|
||||||
package helpers
|
package helpers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Println
|
|
||||||
|
|
||||||
// Similar to MakePath, but with Unicode handling
|
// Similar to MakePath, but with Unicode handling
|
||||||
// Example:
|
// Example:
|
||||||
// uri: Vim (text editor)
|
// uri: Vim (text editor)
|
||||||
|
|
|
@ -16,21 +16,23 @@ package hugolib
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/BurntSushi/toml"
|
|
||||||
"github.com/spf13/hugo/helpers"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"launchpad.net/goyaml"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/BurntSushi/toml"
|
||||||
|
"github.com/spf13/hugo/helpers"
|
||||||
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
|
"launchpad.net/goyaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// config file items
|
// config file items
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ContentDir, PublishDir, BaseUrl, StaticDir string
|
ContentDir, PublishDir, BaseUrl, StaticDir string
|
||||||
Path, CacheDir, LayoutDir, DefaultLayout string
|
Path, CacheDir, LayoutDir, DefaultLayout string
|
||||||
ConfigFile string
|
ConfigFile, LogFile string
|
||||||
Title string
|
Title string
|
||||||
Indexes map[string]string // singular, plural
|
Indexes map[string]string // singular, plural
|
||||||
ProcessFilters map[string][]string
|
ProcessFilters map[string][]string
|
||||||
|
@ -50,8 +52,8 @@ func SetupConfig(cfgfile *string, path *string) *Config {
|
||||||
c.ConfigFile = cfg
|
c.ConfigFile = cfg
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("%v", err)
|
jww.ERROR.Printf("%v", err)
|
||||||
fmt.Println(" using defaults instead")
|
jww.FEEDBACK.Println("using defaults instead")
|
||||||
}
|
}
|
||||||
|
|
||||||
// set defaults
|
// set defaults
|
||||||
|
@ -92,19 +94,19 @@ func (c *Config) readInConfig() {
|
||||||
switch path.Ext(c.ConfigFile) {
|
switch path.Ext(c.ConfigFile) {
|
||||||
case ".yaml":
|
case ".yaml":
|
||||||
if err := goyaml.Unmarshal(file, &c); err != nil {
|
if err := goyaml.Unmarshal(file, &c); err != nil {
|
||||||
fmt.Printf("Error parsing config: %s", err)
|
jww.ERROR.Printf("Error parsing config: %s", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
case ".json":
|
case ".json":
|
||||||
if err := json.Unmarshal(file, &c); err != nil {
|
if err := json.Unmarshal(file, &c); err != nil {
|
||||||
fmt.Printf("Error parsing config: %s", err)
|
jww.ERROR.Printf("Error parsing config: %s", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
case ".toml":
|
case ".toml":
|
||||||
if _, err := toml.Decode(string(file), &c); err != nil {
|
if _, err := toml.Decode(string(file), &c); err != nil {
|
||||||
fmt.Printf("Error parsing config: %s", err)
|
jww.ERROR.Printf("Error parsing config: %s", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,13 +117,13 @@ func (c *Config) setPath(p string) {
|
||||||
if p == "" {
|
if p == "" {
|
||||||
path, err := findPath()
|
path, err := findPath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error finding path: %s", err)
|
jww.ERROR.Printf("Error finding path: %s", err)
|
||||||
}
|
}
|
||||||
c.Path = path
|
c.Path = path
|
||||||
} else {
|
} else {
|
||||||
path, err := filepath.Abs(p)
|
path, err := filepath.Abs(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error finding path: %s", err)
|
jww.ERROR.Printf("Error finding path: %s", err)
|
||||||
}
|
}
|
||||||
c.Path = path
|
c.Path = path
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,10 @@ package hugolib
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
)
|
)
|
||||||
|
|
||||||
func interfaceToTime(i interface{}) time.Time {
|
func interfaceToTime(i interface{}) time.Time {
|
||||||
|
@ -17,9 +18,9 @@ func interfaceToTime(i interface{}) time.Time {
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
errorln("Could not parse Date/Time format:", e)
|
jww.ERROR.Println("Could not parse Date/Time format:", e)
|
||||||
default:
|
default:
|
||||||
errorln("Only Time is supported for this key")
|
jww.ERROR.Println("Only Time is supported for this key")
|
||||||
}
|
}
|
||||||
|
|
||||||
return *new(time.Time)
|
return *new(time.Time)
|
||||||
|
@ -53,11 +54,6 @@ func stringToDate(s string) (time.Time, error) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO remove this and return a proper error.
|
|
||||||
func errorln(str string, a ...interface{}) {
|
|
||||||
fmt.Fprintln(os.Stderr, str, a)
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseDateWith(s string, dates []string) (d time.Time, e error) {
|
func parseDateWith(s string, dates []string) (d time.Time, e error) {
|
||||||
for _, dateType := range dates {
|
for _, dateType := range dates {
|
||||||
if d, e = time.Parse(dateType, s); e == nil {
|
if d, e = time.Parse(dateType, s); e == nil {
|
||||||
|
@ -77,7 +73,7 @@ func interfaceToBool(i interface{}) bool {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
default:
|
default:
|
||||||
errorln("Only Boolean values are supported for this YAML key")
|
jww.ERROR.Println("Only Boolean values are supported for this YAML key")
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
@ -109,11 +105,11 @@ func interfaceToFloat64(i interface{}) float64 {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return float64(v)
|
return float64(v)
|
||||||
} else {
|
} else {
|
||||||
errorln("Only Floats are supported for this key\nErr:", err)
|
jww.ERROR.Println("Only Floats are supported for this key\nErr:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
errorln("Only Floats are supported for this key")
|
jww.ERROR.Println("Only Floats are supported for this key")
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0.0
|
return 0.0
|
||||||
|
@ -136,10 +132,10 @@ func interfaceToInt(i interface{}) int {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return int(v)
|
return int(v)
|
||||||
} else {
|
} else {
|
||||||
errorln("Only Ints are supported for this key\nErr:", err)
|
jww.ERROR.Println("Only Ints are supported for this key\nErr:", err)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
errorln("Only Ints are supported for this key")
|
jww.ERROR.Println("Only Ints are supported for this key")
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
@ -154,7 +150,7 @@ func interfaceToString(i interface{}) string {
|
||||||
case int:
|
case int:
|
||||||
return strconv.FormatInt(int64(i.(int)), 10)
|
return strconv.FormatInt(int64(i.(int)), 10)
|
||||||
default:
|
default:
|
||||||
errorln(fmt.Sprintf("Only Strings are supported for this key (got type '%T'): %s", s, s))
|
jww.ERROR.Println(fmt.Sprintf("Only Strings are supported for this key (got type '%T'): %s", s, s))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
|
@ -17,19 +17,21 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/BurntSushi/toml"
|
|
||||||
"github.com/spf13/hugo/helpers"
|
|
||||||
"github.com/spf13/hugo/parser"
|
|
||||||
"github.com/spf13/hugo/template/bundle"
|
|
||||||
"github.com/theplant/blackfriday"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"launchpad.net/goyaml"
|
|
||||||
json "launchpad.net/rjson"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/BurntSushi/toml"
|
||||||
|
"github.com/spf13/hugo/helpers"
|
||||||
|
"github.com/spf13/hugo/parser"
|
||||||
|
"github.com/spf13/hugo/template/bundle"
|
||||||
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
|
"github.com/theplant/blackfriday"
|
||||||
|
"launchpad.net/goyaml"
|
||||||
|
json "launchpad.net/rjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Page struct {
|
type Page struct {
|
||||||
|
@ -142,6 +144,8 @@ func newPage(filename string) *Page {
|
||||||
File: File{FileName: filename, Extension: "html"},
|
File: File{FileName: filename, Extension: "html"},
|
||||||
Node: Node{Keywords: make([]string, 10, 30)},
|
Node: Node{Keywords: make([]string, 10, 30)},
|
||||||
Params: make(map[string]interface{})}
|
Params: make(map[string]interface{})}
|
||||||
|
|
||||||
|
jww.DEBUG.Println("Reading from", page.File.FileName)
|
||||||
page.Date, _ = time.Parse("20060102", "20080101")
|
page.Date, _ = time.Parse("20060102", "20080101")
|
||||||
page.guessSection()
|
page.guessSection()
|
||||||
return &page
|
return &page
|
||||||
|
@ -212,6 +216,7 @@ func ReadFrom(buf io.Reader, name string) (page *Page, err error) {
|
||||||
|
|
||||||
// Parse for metadata & body
|
// Parse for metadata & body
|
||||||
if err = p.parse(buf); err != nil {
|
if err = p.parse(buf); err != nil {
|
||||||
|
jww.ERROR.Print(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,15 +15,14 @@ package hugolib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
|
||||||
"github.com/spf13/hugo/template/bundle"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
|
||||||
|
|
||||||
var _ = fmt.Println
|
"github.com/spf13/hugo/template/bundle"
|
||||||
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
|
)
|
||||||
|
|
||||||
type ShortcodeFunc func([]string) string
|
type ShortcodeFunc func([]string) string
|
||||||
|
|
||||||
|
@ -296,8 +295,8 @@ func ShortcodeRender(tmpl *template.Template, data *ShortcodeWithPage) string {
|
||||||
buffer := new(bytes.Buffer)
|
buffer := new(bytes.Buffer)
|
||||||
err := tmpl.Execute(buffer, data)
|
err := tmpl.Execute(buffer, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("error processing shortcode", tmpl.Name(), "\n ERR:", err)
|
jww.ERROR.Println("error processing shortcode", tmpl.Name(), "\n ERR:", err)
|
||||||
fmt.Println(data)
|
jww.WARN.Println(data)
|
||||||
}
|
}
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,21 +14,23 @@
|
||||||
package hugolib
|
package hugolib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bitbucket.org/pkg/inflect"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/spf13/hugo/helpers"
|
|
||||||
"github.com/spf13/hugo/source"
|
|
||||||
"github.com/spf13/hugo/target"
|
|
||||||
"github.com/spf13/hugo/template/bundle"
|
|
||||||
"github.com/spf13/hugo/transform"
|
|
||||||
"github.com/spf13/nitro"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"bitbucket.org/pkg/inflect"
|
||||||
|
"github.com/spf13/hugo/helpers"
|
||||||
|
"github.com/spf13/hugo/source"
|
||||||
|
"github.com/spf13/hugo/target"
|
||||||
|
"github.com/spf13/hugo/template/bundle"
|
||||||
|
"github.com/spf13/hugo/transform"
|
||||||
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
|
"github.com/spf13/nitro"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = transform.AbsURL
|
var _ = transform.AbsURL
|
||||||
|
@ -104,9 +106,9 @@ func (s *Site) Build() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = s.Render(); err != nil {
|
if err = s.Render(); err != nil {
|
||||||
fmt.Printf("Error rendering site: %s\nAvailable templates:\n", err)
|
jww.ERROR.Printf("Error rendering site: %s\nAvailable templates:\n", err)
|
||||||
for _, template := range s.Tmpl.Templates() {
|
for _, template := range s.Tmpl.Templates() {
|
||||||
fmt.Printf("\t%s\n", template.Name())
|
jww.ERROR.Printf("\t%s\n", template.Name())
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -190,7 +192,7 @@ func (s *Site) Render() (err error) {
|
||||||
func (s *Site) checkDescriptions() {
|
func (s *Site) checkDescriptions() {
|
||||||
for _, p := range s.Pages {
|
for _, p := range s.Pages {
|
||||||
if len(p.Description) < 60 {
|
if len(p.Description) < 60 {
|
||||||
fmt.Println(p.FileName + " ")
|
jww.FEEDBACK.Println(p.FileName + " ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -309,9 +311,7 @@ func (s *Site) BuildSiteMeta() (err error) {
|
||||||
s.Indexes[plural].Add(idx, x)
|
s.Indexes[plural].Add(idx, x)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if s.Config.Verbose {
|
jww.ERROR.Printf("Invalid %s in %s\n", plural, p.File.FileName)
|
||||||
fmt.Fprintf(os.Stderr, "Invalid %s in %s\n", plural, p.File.FileName)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -533,9 +533,9 @@ func (s *Site) RenderHomePage() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) Stats() {
|
func (s *Site) Stats() {
|
||||||
fmt.Printf("%d pages created \n", len(s.Pages))
|
jww.FEEDBACK.Printf("%d pages created \n", len(s.Pages))
|
||||||
for _, pl := range s.Config.Indexes {
|
for _, pl := range s.Config.Indexes {
|
||||||
fmt.Printf("%d %s index created\n", len(s.Indexes[pl]), pl)
|
jww.FEEDBACK.Printf("%d %s index created\n", len(s.Indexes[pl]), pl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -572,9 +572,7 @@ func (s *Site) render(d interface{}, out string, layouts ...string) (err error)
|
||||||
|
|
||||||
layout := s.findFirstLayout(layouts...)
|
layout := s.findFirstLayout(layouts...)
|
||||||
if layout == "" {
|
if layout == "" {
|
||||||
if s.Config.Verbose {
|
jww.WARN.Printf("Unable to locate layout: %s\n", layouts)
|
||||||
fmt.Printf("Unable to locate layout: %s\n", layouts)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -601,7 +599,7 @@ func (s *Site) render(d interface{}, out string, layouts ...string) (err error)
|
||||||
err = s.renderThing(d, layout, renderBuffer)
|
err = s.renderThing(d, layout, renderBuffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Behavior here should be dependent on if running in server or watch mode.
|
// Behavior here should be dependent on if running in server or watch mode.
|
||||||
fmt.Println(fmt.Errorf("Rendering error: %v", err))
|
jww.ERROR.Println(fmt.Errorf("Rendering error: %v", err))
|
||||||
if !s.Running() {
|
if !s.Running() {
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
@ -631,7 +629,6 @@ func (s *Site) renderThing(d interface{}, layout string, w io.Writer) error {
|
||||||
if s.Tmpl.Lookup(layout) == nil {
|
if s.Tmpl.Lookup(layout) == nil {
|
||||||
return fmt.Errorf("Layout not found: %s", layout)
|
return fmt.Errorf("Layout not found: %s", layout)
|
||||||
}
|
}
|
||||||
//defer w.Close()
|
|
||||||
return s.Tmpl.ExecuteTemplate(w, layout, d)
|
return s.Tmpl.ExecuteTemplate(w, layout, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -652,9 +649,7 @@ func (s *Site) initTarget() {
|
||||||
func (s *Site) WritePublic(path string, reader io.Reader) (err error) {
|
func (s *Site) WritePublic(path string, reader io.Reader) (err error) {
|
||||||
s.initTarget()
|
s.initTarget()
|
||||||
|
|
||||||
if s.Config.Verbose {
|
jww.DEBUG.Println("writing to", path)
|
||||||
fmt.Println(path)
|
|
||||||
}
|
|
||||||
return s.Target.Publish(path, reader)
|
return s.Target.Publish(path, reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -666,9 +661,7 @@ func (s *Site) WriteAlias(path string, permalink template.HTML) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Config.Verbose {
|
jww.DEBUG.Println("alias created at", path)
|
||||||
fmt.Println(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
return s.Alias.Publish(path, permalink)
|
return s.Alias.Publish(path, permalink)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,10 @@ package hugolib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
)
|
)
|
||||||
|
|
||||||
var summaryLength = 70
|
var summaryLength = 70
|
||||||
|
@ -62,7 +63,7 @@ func getRstContent(content []byte) string {
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
fmt.Println(err)
|
jww.ERROR.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rstLines := strings.Split(out.String(), "\n")
|
rstLines := strings.Split(out.String(), "\n")
|
||||||
|
|
3
main.go
3
main.go
|
@ -14,8 +14,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/hugo/commands"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"github.com/spf13/hugo/commands"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -1,22 +1,24 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CheckErr(err error, s ...string) {
|
func CheckErr(err error, s ...string) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, message := range s {
|
for _, message := range s {
|
||||||
log.Fatalf(message)
|
jww.ERROR.Println(message)
|
||||||
}
|
}
|
||||||
log.Fatalf("Fatal Error: %v", err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func StopOnErr(err error, s ...string) {
|
func StopOnErr(err error, s ...string) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
CheckErr(err, s...)
|
for _, message := range s {
|
||||||
|
jww.CRITICAL.Println(message)
|
||||||
|
}
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue