commands, tpl: Get rid of repeating viper accesses
authorAlbert Nigmatzianov <albertnigma@gmail.com>
Sun, 6 Nov 2016 23:10:32 +0000 (00:10 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 6 Nov 2016 23:10:32 +0000 (00:10 +0100)
* all: Delete some blank lines
* commands, tpl: Get rid of repeating viper accesses

commands/convert.go
commands/hugo.go
helpers/pygments.go
hugolib/config.go
hugolib/handler_page.go
hugolib/page.go
hugolib/site.go
tpl/template_i18n.go
tpl/template_resources.go

index a0424c4a9c66961c74b80fdaaf75ac5d808f5918..411e51ec299509e9b7a1464362e3618c5b9cab5d 100644 (file)
@@ -103,6 +103,7 @@ func convertContents(mark rune) (err error) {
                return fmt.Errorf("No source files found")
        }
 
+       contentDir := helpers.AbsPathify(viper.GetString("contentDir"))
        jww.FEEDBACK.Println("processing", len(site.Source.Files()), "content files")
        for _, file := range site.Source.Files() {
                jww.INFO.Println("Attempting to convert", file.LogicalName())
@@ -134,7 +135,7 @@ func convertContents(mark rune) (err error) {
                        metadata = newmetadata
                }
 
-               page.SetDir(filepath.Join(helpers.AbsPathify(viper.GetString("contentDir")), file.Dir()))
+               page.SetDir(filepath.Join(contentDir, file.Dir()))
                page.SetSourceContent(psr.Content())
                if err = page.SetSourceMetaData(metadata, mark); err != nil {
                        jww.ERROR.Printf("Failed to set source metadata for file %q: %s. For more info see For more info see https://github.com/spf13/hugo/issues/2458", page.FullFilePath(), err)
index 883c92ea98f12747b79f8b3d8ee5cdef9e14944c..54d0a255e9140883c99052595368116ab2291a45 100644 (file)
@@ -426,7 +426,6 @@ func watchConfig() {
 }
 
 func build(watches ...bool) error {
-
        // Hugo writes the output to memory instead of the disk
        // This is only used for benchmark testing. Cause the content is only visible
        // in memory
@@ -786,7 +785,7 @@ func NewWatcher(port int) error {
                                                jww.FEEDBACK.Printf("Syncing all static files\n")
                                                err := copyStatic()
                                                if err != nil {
-                                                       utils.StopOnErr(err, fmt.Sprintf("Error copying static files to %s", helpers.AbsPathify(viper.GetString("publishDir"))))
+                                                       utils.StopOnErr(err, fmt.Sprintf("Error copying static files to %s", publishDir))
                                                }
                                        } else {
                                                staticSourceFs := getStaticSourceFs()
index d729be5dc66b2b65ec6ae045a8083be977e5a189..7903678b6a8fb27a811db2ece82478df4efb740b 100644 (file)
@@ -42,7 +42,6 @@ func HasPygments() bool {
 
 // Highlight takes some code and returns highlighted code.
 func Highlight(code, lang, optsStr string) string {
-
        if !HasPygments() {
                jww.WARN.Println("Highlighting requires Pygments to be installed and in the path")
                return code
@@ -197,7 +196,6 @@ func createOptionsString(options map[string]string) string {
 }
 
 func parseDefaultPygmentsOpts() (map[string]string, error) {
-
        options := make(map[string]string)
        err := parseOptions(options, viper.GetString("pygmentsOptions"))
        if err != nil {
@@ -225,7 +223,6 @@ func parseDefaultPygmentsOpts() (map[string]string, error) {
 }
 
 func parsePygmentsOpts(in string) (string, error) {
-
        options, err := parseDefaultPygmentsOpts()
        if err != nil {
                return "", err
index 94477b75a475e5ae44fabfeff82aa46a8012aab3..e6d28051e62329d35508be2ee52f63fb9cf9d252 100644 (file)
@@ -22,7 +22,6 @@ import (
 
 // LoadGlobalConfig loads Hugo configuration into the global Viper.
 func LoadGlobalConfig(relativeSourcePath, configFilename string) error {
-
        if relativeSourcePath == "" {
                relativeSourcePath = "."
        }
index c71936954445792ff646b7cdb7bb44a833debb3d..45e34973d6368c7d0731dadfb560ff414a244cea 100644 (file)
@@ -105,7 +105,6 @@ func (h mmarkHandler) PageConvert(p *Page, t tpl.Template) HandledResult {
 }
 
 func commonConvert(p *Page, t tpl.Template) HandledResult {
-
        if p.rendered {
                panic(fmt.Sprintf("Page %q already rendered, does not need conversion", p.BaseFileName()))
        }
index 7d7c22fd99a58fdbe379fefe228c6aef56ed43ae..de739159942c385436ce41d5c3bfeed4ad795443 100644 (file)
@@ -584,7 +584,6 @@ func (p *Page) permalink() (*url.URL, error) {
                if err != nil {
                        return nil, err
                }
-               // fmt.Printf("have a section override for %q in section %s → %s\n", p.Title, p.Section, permalink)
        } else {
                if len(pSlug) > 0 {
                        permalink = helpers.URLPrep(viper.GetBool("uglyURLs"), path.Join(dir, p.Slug+"."+p.Extension()))
index 6940d74bfdad965dd61dac792e6cb3ac44fa5aa6..1a6c50fce25c68a87c9d9693bfeeb513202dbe46 100644 (file)
@@ -917,7 +917,6 @@ func (s *SiteInfo) SitemapAbsURL() string {
 }
 
 func (s *Site) initializeSiteInfo() {
-
        var (
                lang      *helpers.Language = s.Language
                languages helpers.Languages
@@ -1980,7 +1979,6 @@ func (s *Site) renderSectionLists(prepare bool) error {
                }
 
                if n.paginator != nil {
-
                        paginatePath := helpers.Config().GetString("paginatePath")
 
                        // write alias for page 1
@@ -2029,7 +2027,6 @@ func (s *Site) renderSectionLists(prepare bool) error {
 }
 
 func (s *Site) renderHomePage(prepare bool) error {
-
        n := s.newHomeNode(prepare, 0)
        if prepare {
                return nil
index 9b681b4cde907fecc9c01765a716723b0a140709..1bec65a78eca5163c0b8aa777fecfd09484955fe 100644 (file)
@@ -65,6 +65,7 @@ func SetI18nTfuncs(bndl *bundle.Bundle) {
                jww.WARN.Printf("No translation bundle found for default language %q", defaultContentLanguage)
        }
 
+       enableMissingTranslationPlaceholders := viper.GetBool("enableMissingTranslationPlaceholders")
        for _, lang := range bndl.LanguageTags() {
                currentLang := lang
 
@@ -78,7 +79,7 @@ func SetI18nTfuncs(bndl *bundle.Bundle) {
                        if Logi18nWarnings {
                                i18nWarningLogger.Printf("i18n|MISSING_TRANSLATION|%s|%s", currentLang, translationID)
                        }
-                       if viper.GetBool("enableMissingTranslationPlaceholders") {
+                       if enableMissingTranslationPlaceholders {
                                return fmt.Sprintf("[i18n] %s", translationID)
                        }
                        if defaultT != nil {
index 507df307e6c4d529f70cdc25498fcb92bc7c691f..116d5df6169720ceb5214caf6c36af35ddb19321 100644 (file)
@@ -114,7 +114,6 @@ func resDeleteCache(id string, fs afero.Fs) error {
 
 // resGetRemote loads the content of a remote file. This method is thread safe.
 func resGetRemote(url string, fs afero.Fs, hc *http.Client) ([]byte, error) {
-
        c, err := resGetCache(url, fs, viper.GetBool("ignoreCache"))
        if c != nil && err == nil {
                return c, nil