2016-08-05 05:04:52 -04:00
|
|
|
// Copyright 2016-present The Hugo Authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package hugolib
|
|
|
|
|
|
|
|
import (
|
2017-11-12 04:03:56 -05:00
|
|
|
"errors"
|
2016-08-05 05:04:52 -04:00
|
|
|
"fmt"
|
2018-03-18 06:07:24 -04:00
|
|
|
"path/filepath"
|
2016-08-05 05:04:52 -04:00
|
|
|
|
2017-09-25 02:59:02 -04:00
|
|
|
"io"
|
|
|
|
"strings"
|
|
|
|
|
2017-11-02 03:25:20 -04:00
|
|
|
"github.com/gohugoio/hugo/config"
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/helpers"
|
2017-06-13 13:07:35 -04:00
|
|
|
"github.com/spf13/afero"
|
2016-08-05 05:04:52 -04:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
2018-03-18 05:32:29 -04:00
|
|
|
// ConfigSourceDescriptor describes where to find the config (e.g. config.toml etc.).
|
|
|
|
type ConfigSourceDescriptor struct {
|
2018-03-18 06:07:24 -04:00
|
|
|
Fs afero.Fs
|
|
|
|
|
|
|
|
// Full path to the config file to use, i.e. /my/project/config.toml
|
|
|
|
Filename string
|
|
|
|
|
|
|
|
// The path to the directory to look for configuration. Is used if Filename is not
|
|
|
|
// set.
|
|
|
|
Path string
|
|
|
|
|
|
|
|
// The project's working dir. Is used to look for additional theme config.
|
|
|
|
WorkingDir string
|
2018-03-18 05:32:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d ConfigSourceDescriptor) configFilenames() []string {
|
2018-03-18 06:07:24 -04:00
|
|
|
return strings.Split(d.Filename, ",")
|
2018-03-18 05:32:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// LoadConfigDefault is a convenience method to load the default "config.toml" config.
|
|
|
|
func LoadConfigDefault(fs afero.Fs) (*viper.Viper, error) {
|
2018-03-18 06:07:24 -04:00
|
|
|
v, _, err := LoadConfig(ConfigSourceDescriptor{Fs: fs, Filename: "config.toml"})
|
|
|
|
return v, err
|
2018-03-18 05:32:29 -04:00
|
|
|
}
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
// LoadConfig loads Hugo configuration into a new Viper and then adds
|
|
|
|
// a set of defaults.
|
2018-03-18 06:07:24 -04:00
|
|
|
func LoadConfig(d ConfigSourceDescriptor) (*viper.Viper, []string, error) {
|
|
|
|
var configFiles []string
|
|
|
|
|
2018-03-18 05:32:29 -04:00
|
|
|
fs := d.Fs
|
2017-02-04 22:20:06 -05:00
|
|
|
v := viper.New()
|
|
|
|
v.SetFs(fs)
|
2018-03-18 05:32:29 -04:00
|
|
|
|
2018-03-18 06:07:24 -04:00
|
|
|
if d.Path == "" {
|
|
|
|
d.Path = "."
|
2016-08-05 05:04:52 -04:00
|
|
|
}
|
2018-03-18 05:32:29 -04:00
|
|
|
|
|
|
|
configFilenames := d.configFilenames()
|
2017-02-04 22:20:06 -05:00
|
|
|
v.AutomaticEnv()
|
|
|
|
v.SetEnvPrefix("hugo")
|
2017-08-09 14:13:02 -04:00
|
|
|
v.SetConfigFile(configFilenames[0])
|
2018-03-18 06:07:24 -04:00
|
|
|
v.AddConfigPath(d.Path)
|
2018-03-18 05:32:29 -04:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
err := v.ReadInConfig()
|
2016-08-05 05:04:52 -04:00
|
|
|
if err != nil {
|
|
|
|
if _, ok := err.(viper.ConfigParseError); ok {
|
2018-03-18 06:07:24 -04:00
|
|
|
return nil, configFiles, err
|
2016-08-05 05:04:52 -04:00
|
|
|
}
|
2018-03-18 06:07:24 -04:00
|
|
|
return nil, configFiles, fmt.Errorf("Unable to locate Config file. Perhaps you need to create a new site.\n Run `hugo help new` for details. (%s)\n", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if cf := v.ConfigFileUsed(); cf != "" {
|
|
|
|
configFiles = append(configFiles, cf)
|
2016-08-05 05:04:52 -04:00
|
|
|
}
|
2018-03-18 06:07:24 -04:00
|
|
|
|
2017-08-09 14:13:02 -04:00
|
|
|
for _, configFile := range configFilenames[1:] {
|
|
|
|
var r io.Reader
|
|
|
|
var err error
|
|
|
|
if r, err = fs.Open(configFile); err != nil {
|
2018-03-18 06:07:24 -04:00
|
|
|
return nil, configFiles, fmt.Errorf("Unable to open Config file.\n (%s)\n", err)
|
2017-08-09 14:13:02 -04:00
|
|
|
}
|
|
|
|
if err = v.MergeConfig(r); err != nil {
|
2018-03-18 06:07:24 -04:00
|
|
|
return nil, configFiles, fmt.Errorf("Unable to parse/merge Config file (%s).\n (%s)\n", configFile, err)
|
2017-08-09 14:13:02 -04:00
|
|
|
}
|
2018-03-18 06:07:24 -04:00
|
|
|
configFiles = append(configFiles, configFile)
|
2017-08-09 14:13:02 -04:00
|
|
|
}
|
2016-08-05 05:04:52 -04:00
|
|
|
|
2017-11-02 03:25:20 -04:00
|
|
|
if err := loadDefaultSettingsFor(v); err != nil {
|
2018-03-18 06:07:24 -04:00
|
|
|
return v, configFiles, err
|
2017-11-02 03:25:20 -04:00
|
|
|
}
|
2016-08-05 05:04:52 -04:00
|
|
|
|
2018-03-18 06:07:24 -04:00
|
|
|
themeConfigFile, err := loadThemeConfig(d, v)
|
|
|
|
if err != nil {
|
|
|
|
return v, configFiles, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if themeConfigFile != "" {
|
|
|
|
configFiles = append(configFiles, themeConfigFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := loadLanguageSettings(v, nil); err != nil {
|
|
|
|
return v, configFiles, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return v, configFiles, nil
|
|
|
|
|
2016-08-05 05:04:52 -04:00
|
|
|
}
|
|
|
|
|
2017-11-12 04:03:56 -05:00
|
|
|
func loadLanguageSettings(cfg config.Provider, oldLangs helpers.Languages) error {
|
2018-01-25 11:03:29 -05:00
|
|
|
|
|
|
|
defaultLang := cfg.GetString("defaultContentLanguage")
|
|
|
|
|
|
|
|
var languages map[string]interface{}
|
|
|
|
|
|
|
|
languagesFromConfig := cfg.GetStringMap("languages")
|
|
|
|
disableLanguages := cfg.GetStringSlice("disableLanguages")
|
|
|
|
|
|
|
|
if len(disableLanguages) == 0 {
|
|
|
|
languages = languagesFromConfig
|
|
|
|
} else {
|
|
|
|
languages = make(map[string]interface{})
|
|
|
|
for k, v := range languagesFromConfig {
|
|
|
|
isDisabled := false
|
|
|
|
for _, disabled := range disableLanguages {
|
|
|
|
if disabled == defaultLang {
|
|
|
|
return fmt.Errorf("cannot disable default language %q", defaultLang)
|
|
|
|
}
|
|
|
|
|
|
|
|
if strings.EqualFold(k, disabled) {
|
|
|
|
isDisabled = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !isDisabled {
|
|
|
|
languages[k] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-02 03:25:20 -04:00
|
|
|
var (
|
|
|
|
langs helpers.Languages
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
2018-01-25 11:03:29 -05:00
|
|
|
if len(languages) == 0 {
|
2017-11-02 03:25:20 -04:00
|
|
|
langs = append(langs, helpers.NewDefaultLanguage(cfg))
|
|
|
|
} else {
|
2018-01-25 11:03:29 -05:00
|
|
|
langs, err = toSortedLanguages(cfg, languages)
|
2017-11-02 03:25:20 -04:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Failed to parse multilingual config: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-12 04:03:56 -05:00
|
|
|
if oldLangs != nil {
|
|
|
|
// When in multihost mode, the languages are mapped to a server, so
|
|
|
|
// some structural language changes will need a restart of the dev server.
|
|
|
|
// The validation below isn't complete, but should cover the most
|
|
|
|
// important cases.
|
|
|
|
var invalid bool
|
|
|
|
if langs.IsMultihost() != oldLangs.IsMultihost() {
|
|
|
|
invalid = true
|
|
|
|
} else {
|
|
|
|
if langs.IsMultihost() && len(langs) != len(oldLangs) {
|
|
|
|
invalid = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if invalid {
|
|
|
|
return errors.New("language change needing a server restart detected")
|
|
|
|
}
|
|
|
|
|
|
|
|
if langs.IsMultihost() {
|
|
|
|
// We need to transfer any server baseURL to the new language
|
|
|
|
for i, ol := range oldLangs {
|
|
|
|
nl := langs[i]
|
|
|
|
nl.Set("baseURL", ol.GetString("baseURL"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-19 02:24:10 -05:00
|
|
|
// The defaultContentLanguage is something the user has to decide, but it needs
|
|
|
|
// to match a language in the language definition list.
|
|
|
|
langExists := false
|
|
|
|
for _, lang := range langs {
|
|
|
|
if lang.Lang == defaultLang {
|
|
|
|
langExists = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !langExists {
|
|
|
|
return fmt.Errorf("site config value %q for defaultContentLanguage does not match any language definition", defaultLang)
|
|
|
|
}
|
|
|
|
|
2017-11-02 03:25:20 -04:00
|
|
|
cfg.Set("languagesSorted", langs)
|
2017-11-12 04:03:56 -05:00
|
|
|
cfg.Set("multilingual", len(langs) > 1)
|
|
|
|
|
2018-01-06 12:42:32 -05:00
|
|
|
multihost := langs.IsMultihost()
|
2017-11-12 04:03:56 -05:00
|
|
|
|
2018-01-06 12:42:32 -05:00
|
|
|
if multihost {
|
2017-11-12 04:03:56 -05:00
|
|
|
cfg.Set("defaultContentLanguageInSubdir", true)
|
|
|
|
cfg.Set("multihost", true)
|
|
|
|
}
|
2017-11-02 03:25:20 -04:00
|
|
|
|
2018-01-06 12:42:32 -05:00
|
|
|
if multihost {
|
|
|
|
// The baseURL may be provided at the language level. If that is true,
|
|
|
|
// then every language must have a baseURL. In this case we always render
|
|
|
|
// to a language sub folder, which is then stripped from all the Permalink URLs etc.
|
|
|
|
for _, l := range langs {
|
|
|
|
burl := l.GetLocal("baseURL")
|
|
|
|
if burl == nil {
|
|
|
|
return errors.New("baseURL must be set on all or none of the languages")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-02 03:25:20 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-03-18 06:07:24 -04:00
|
|
|
func loadThemeConfig(d ConfigSourceDescriptor, v1 *viper.Viper) (string, error) {
|
|
|
|
|
|
|
|
theme := v1.GetString("theme")
|
|
|
|
if theme == "" {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
|
|
|
themesDir := helpers.AbsPathify(d.WorkingDir, v1.GetString("themesDir"))
|
|
|
|
configDir := filepath.Join(themesDir, theme)
|
|
|
|
|
|
|
|
var (
|
|
|
|
configPath string
|
|
|
|
exists bool
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
// Viper supports more, but this is the sub-set supported by Hugo.
|
|
|
|
for _, configFormats := range []string{"toml", "yaml", "yml", "json"} {
|
|
|
|
configPath = filepath.Join(configDir, "config."+configFormats)
|
|
|
|
exists, err = helpers.Exists(configPath, d.Fs)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
if exists {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !exists {
|
|
|
|
// No theme config set.
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
|
|
|
v2 := viper.New()
|
|
|
|
v2.SetFs(d.Fs)
|
|
|
|
v2.AutomaticEnv()
|
|
|
|
v2.SetEnvPrefix("hugo")
|
|
|
|
v2.SetConfigFile(configPath)
|
|
|
|
|
|
|
|
err = v2.ReadInConfig()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
paramsKey = "params"
|
|
|
|
languagesKey = "languages"
|
|
|
|
menuKey = "menu"
|
|
|
|
)
|
|
|
|
|
|
|
|
for _, key := range []string{paramsKey, "outputformats", "mediatypes"} {
|
|
|
|
mergeStringMapKeepLeft("", key, v1, v2)
|
|
|
|
}
|
|
|
|
|
|
|
|
themeLower := strings.ToLower(theme)
|
|
|
|
themeParamsNamespace := paramsKey + "." + themeLower
|
|
|
|
|
|
|
|
// Set namespaced params
|
|
|
|
if v2.IsSet(paramsKey) && !v1.IsSet(themeParamsNamespace) {
|
|
|
|
// Set it in the default store to make sure it gets in the same or
|
|
|
|
// behind the others.
|
|
|
|
v1.SetDefault(themeParamsNamespace, v2.Get(paramsKey))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only add params and new menu entries, we do not add language definitions.
|
|
|
|
if v1.IsSet(languagesKey) && v2.IsSet(languagesKey) {
|
|
|
|
v1Langs := v1.GetStringMap(languagesKey)
|
|
|
|
for k, _ := range v1Langs {
|
|
|
|
langParamsKey := languagesKey + "." + k + "." + paramsKey
|
|
|
|
mergeStringMapKeepLeft(paramsKey, langParamsKey, v1, v2)
|
|
|
|
}
|
|
|
|
v2Langs := v2.GetStringMap(languagesKey)
|
|
|
|
for k, _ := range v2Langs {
|
|
|
|
if k == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
langParamsKey := languagesKey + "." + k + "." + paramsKey
|
|
|
|
langParamsThemeNamespace := langParamsKey + "." + themeLower
|
|
|
|
// Set namespaced params
|
|
|
|
if v2.IsSet(langParamsKey) && !v1.IsSet(langParamsThemeNamespace) {
|
|
|
|
v1.SetDefault(langParamsThemeNamespace, v2.Get(langParamsKey))
|
|
|
|
}
|
|
|
|
|
|
|
|
langMenuKey := languagesKey + "." + k + "." + menuKey
|
|
|
|
if v2.IsSet(langMenuKey) {
|
|
|
|
// Only add if not in the main config.
|
|
|
|
v2menus := v2.GetStringMap(langMenuKey)
|
|
|
|
for k, v := range v2menus {
|
|
|
|
menuEntry := menuKey + "." + k
|
|
|
|
menuLangEntry := langMenuKey + "." + k
|
|
|
|
if !v1.IsSet(menuEntry) && !v1.IsSet(menuLangEntry) {
|
|
|
|
v1.Set(menuLangEntry, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add menu definitions from theme not found in project
|
|
|
|
if v2.IsSet("menu") {
|
|
|
|
v2menus := v2.GetStringMap(menuKey)
|
|
|
|
for k, v := range v2menus {
|
|
|
|
menuEntry := menuKey + "." + k
|
|
|
|
if !v1.IsSet(menuEntry) {
|
|
|
|
v1.SetDefault(menuEntry, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return v2.ConfigFileUsed(), nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func mergeStringMapKeepLeft(rootKey, key string, v1, v2 *viper.Viper) {
|
|
|
|
if !v2.IsSet(key) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !v1.IsSet(key) && !(rootKey != "" && rootKey != key && v1.IsSet(rootKey)) {
|
|
|
|
v1.Set(key, v2.Get(key))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
m1 := v1.GetStringMap(key)
|
|
|
|
m2 := v2.GetStringMap(key)
|
|
|
|
|
|
|
|
for k, v := range m2 {
|
|
|
|
if _, found := m1[k]; !found {
|
|
|
|
if rootKey != "" && v1.IsSet(rootKey+"."+k) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
m1[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-25 02:59:02 -04:00
|
|
|
func loadDefaultSettingsFor(v *viper.Viper) error {
|
2017-02-04 22:20:06 -05:00
|
|
|
|
2017-09-25 02:59:02 -04:00
|
|
|
c, err := helpers.NewContentSpec(v)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-02-04 22:20:06 -05:00
|
|
|
|
2018-03-18 05:32:29 -04:00
|
|
|
v.RegisterAlias("indexes", "taxonomies")
|
|
|
|
|
2018-01-10 10:53:40 -05:00
|
|
|
v.SetDefault("cleanDestinationDir", false)
|
2017-02-04 22:20:06 -05:00
|
|
|
v.SetDefault("watch", false)
|
|
|
|
v.SetDefault("metaDataFormat", "toml")
|
|
|
|
v.SetDefault("contentDir", "content")
|
|
|
|
v.SetDefault("layoutDir", "layouts")
|
|
|
|
v.SetDefault("staticDir", "static")
|
:sparkles: Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.
Some hightlights include:
* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).
A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:
```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64%
```
Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-07-24 03:00:23 -04:00
|
|
|
v.SetDefault("resourceDir", "resources")
|
2017-02-04 22:20:06 -05:00
|
|
|
v.SetDefault("archetypeDir", "archetypes")
|
|
|
|
v.SetDefault("publishDir", "public")
|
|
|
|
v.SetDefault("dataDir", "data")
|
|
|
|
v.SetDefault("i18nDir", "i18n")
|
|
|
|
v.SetDefault("themesDir", "themes")
|
|
|
|
v.SetDefault("buildDrafts", false)
|
|
|
|
v.SetDefault("buildFuture", false)
|
|
|
|
v.SetDefault("buildExpired", false)
|
|
|
|
v.SetDefault("uglyURLs", false)
|
|
|
|
v.SetDefault("verbose", false)
|
|
|
|
v.SetDefault("ignoreCache", false)
|
|
|
|
v.SetDefault("canonifyURLs", false)
|
|
|
|
v.SetDefault("relativeURLs", false)
|
|
|
|
v.SetDefault("removePathAccents", false)
|
2017-07-30 11:46:04 -04:00
|
|
|
v.SetDefault("titleCaseStyle", "AP")
|
2017-02-04 22:20:06 -05:00
|
|
|
v.SetDefault("taxonomies", map[string]string{"tag": "tags", "category": "categories"})
|
|
|
|
v.SetDefault("permalinks", make(PermalinkOverrides, 0))
|
|
|
|
v.SetDefault("sitemap", Sitemap{Priority: -1, Filename: "sitemap.xml"})
|
|
|
|
v.SetDefault("pygmentsStyle", "monokai")
|
|
|
|
v.SetDefault("pygmentsUseClasses", false)
|
|
|
|
v.SetDefault("pygmentsCodeFences", false)
|
2017-09-25 02:59:02 -04:00
|
|
|
v.SetDefault("pygmentsUseClassic", false)
|
2017-02-04 22:20:06 -05:00
|
|
|
v.SetDefault("pygmentsOptions", "")
|
|
|
|
v.SetDefault("disableLiveReload", false)
|
|
|
|
v.SetDefault("pluralizeListTitles", true)
|
|
|
|
v.SetDefault("preserveTaxonomyNames", false)
|
|
|
|
v.SetDefault("forceSyncStatic", false)
|
|
|
|
v.SetDefault("footnoteAnchorPrefix", "")
|
|
|
|
v.SetDefault("footnoteReturnLinkContents", "")
|
|
|
|
v.SetDefault("newContentEditor", "")
|
|
|
|
v.SetDefault("paginate", 10)
|
|
|
|
v.SetDefault("paginatePath", "page")
|
2017-09-29 03:04:55 -04:00
|
|
|
v.SetDefault("summaryLength", 70)
|
Reuse the BlackFriday instance when possible
This is in heavy use in rendering, so this makes a difference:
```bash
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_pages=500,tags_per_page=5,shortcodes,render-4 124551144 107743429 -13.49%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_pages=500,tags_per_page=5,shortcodes,render-4 528684 435118 -17.70%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_pages=500,tags_per_page=5,shortcodes,render-4 53306848 45147832 -15.31%
```
2017-12-16 12:56:58 -05:00
|
|
|
v.SetDefault("blackfriday", c.BlackFriday)
|
2017-02-04 22:20:06 -05:00
|
|
|
v.SetDefault("rSSUri", "index.xml")
|
2017-03-09 19:41:59 -05:00
|
|
|
v.SetDefault("rssLimit", -1)
|
2017-02-04 22:20:06 -05:00
|
|
|
v.SetDefault("sectionPagesMenu", "")
|
|
|
|
v.SetDefault("disablePathToLower", false)
|
|
|
|
v.SetDefault("hasCJKLanguage", false)
|
|
|
|
v.SetDefault("enableEmoji", false)
|
|
|
|
v.SetDefault("pygmentsCodeFencesGuessSyntax", false)
|
|
|
|
v.SetDefault("useModTimeAsFallback", false)
|
|
|
|
v.SetDefault("defaultContentLanguage", "en")
|
|
|
|
v.SetDefault("defaultContentLanguageInSubdir", false)
|
|
|
|
v.SetDefault("enableMissingTranslationPlaceholders", false)
|
|
|
|
v.SetDefault("enableGitInfo", false)
|
2017-05-06 03:41:24 -04:00
|
|
|
v.SetDefault("ignoreFiles", make([]string, 0))
|
2017-06-20 04:30:40 -04:00
|
|
|
v.SetDefault("disableAliases", false)
|
2017-07-27 16:36:22 -04:00
|
|
|
v.SetDefault("debug", false)
|
Only re-render the view(s) you're working on
Hugo already, in its server mode, support partial rebuilds. To put it simply: If you change `about.md`, only that content page is read and processed, then Hugo does some processing (taxonomies etc.) and the full site is rendered.
This commit covers the rendering part: We now only re-render the pages you work on, i.e. the last n pages you watched in the browser (which obviously also includes the page in the example above).
To be more specific: When you are running the hugo server in watch (aka. livereload) mode, and change a template or a content file, then we do a partial re-rendering of the following:
* The current content page (if it is a content change)
* The home page
* Up to the last 10 pages you visited on the site.
This should in most cases be enough, but if you navigate to something completely different, you may see stale content. Doing an edit will then refresh that page.
Note that this feature is enabled by default. To turn it off, run `hugo server --disableFastRender`.
Fixes #3962
See #1643
2017-10-14 07:40:43 -04:00
|
|
|
v.SetDefault("disableFastRender", false)
|
2017-09-25 02:59:02 -04:00
|
|
|
|
hugolib: Extract date and slug from filename
This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter.
This should make it easier to move content from Jekyll to Hugo.
To enable, put this in your `config.toml`:
```toml
[frontmatter]
date = [":filename", ":default"]
```
This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc.
So, if you want to use the `file modification time`, this can be a good configuration:
```toml
[frontmatter]
date = [ "date",":fileModTime", ":default"]
lastmod = ["lastmod" ,":fileModTime", ":default"]
```
The current `:default` values for the different dates are
```toml
[frontmatter]
date = ["date","publishDate", "lastmod"]
lastmod = ["lastmod", "date","publishDate"]
publishDate = ["publishDate", "date"]
expiryDate = ["expiryDate"]
```
The above will now be the same as:
```toml
[frontmatter]
date = [":default"]
lastmod = [":default"]
publishDate = [":default"]
expiryDate = [":default"]
```
Note:
* We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate.
* If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved.
* All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`).
* The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values.
* The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list.
Fixes #285
Closes #3310
Closes #3762
Closes #4340
2018-03-11 06:32:55 -04:00
|
|
|
// Remove in Hugo 0.39
|
|
|
|
|
2018-01-29 07:52:04 -05:00
|
|
|
if v.GetBool("useModTimeAsFallback") {
|
hugolib: Extract date and slug from filename
This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter.
This should make it easier to move content from Jekyll to Hugo.
To enable, put this in your `config.toml`:
```toml
[frontmatter]
date = [":filename", ":default"]
```
This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc.
So, if you want to use the `file modification time`, this can be a good configuration:
```toml
[frontmatter]
date = [ "date",":fileModTime", ":default"]
lastmod = ["lastmod" ,":fileModTime", ":default"]
```
The current `:default` values for the different dates are
```toml
[frontmatter]
date = ["date","publishDate", "lastmod"]
lastmod = ["lastmod", "date","publishDate"]
publishDate = ["publishDate", "date"]
expiryDate = ["expiryDate"]
```
The above will now be the same as:
```toml
[frontmatter]
date = [":default"]
lastmod = [":default"]
publishDate = [":default"]
expiryDate = [":default"]
```
Note:
* We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate.
* If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved.
* All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`).
* The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values.
* The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list.
Fixes #285
Closes #3310
Closes #3762
Closes #4340
2018-03-11 06:32:55 -04:00
|
|
|
|
|
|
|
helpers.Deprecated("Site config", "useModTimeAsFallback", `Replace with this in your config.toml:
|
|
|
|
|
|
|
|
[frontmatter]
|
|
|
|
date = [ "date",":fileModTime", ":default"]
|
|
|
|
lastmod = ["lastmod" ,":fileModTime", ":default"]
|
|
|
|
`, false)
|
2018-01-29 07:52:04 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-18 06:07:24 -04:00
|
|
|
return nil
|
2016-08-05 05:04:52 -04:00
|
|
|
}
|