2019-01-02 06:33:26 -05:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
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
|
|
|
//
|
|
|
|
// 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 pagemeta
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
import (
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
)
|
|
|
|
|
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
|
|
|
type URLPath struct {
|
|
|
|
URL string
|
|
|
|
Permalink string
|
|
|
|
Slug string
|
|
|
|
Section string
|
|
|
|
}
|
2019-09-10 05:26:34 -04:00
|
|
|
|
|
|
|
var defaultBuildConfig = BuildConfig{
|
|
|
|
List: true,
|
|
|
|
Render: true,
|
|
|
|
PublishResources: true,
|
|
|
|
set: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
// BuildConfig holds configuration options about how to handle a Page in Hugo's
|
|
|
|
// build process.
|
|
|
|
type BuildConfig struct {
|
|
|
|
// Whether to add it to any of the page collections.
|
|
|
|
// Note that the page can still be found with .Site.GetPage.
|
|
|
|
List bool
|
|
|
|
|
|
|
|
// Whether to render it.
|
2020-02-21 04:12:33 -05:00
|
|
|
Render bool
|
2019-09-10 05:26:34 -04:00
|
|
|
|
|
|
|
// Whether to publish its resources. These will still be published on demand,
|
|
|
|
// but enabling this can be useful if the originals (e.g. images) are
|
|
|
|
// never used.
|
|
|
|
PublishResources bool
|
|
|
|
|
|
|
|
set bool // BuildCfg is non-zero if this is set to true.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable sets all options to their off value.
|
|
|
|
func (b *BuildConfig) Disable() {
|
|
|
|
b.List = false
|
|
|
|
b.Render = false
|
|
|
|
b.PublishResources = false
|
|
|
|
b.set = true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b BuildConfig) IsZero() bool {
|
|
|
|
return !b.set
|
|
|
|
}
|
|
|
|
|
|
|
|
func DecodeBuildConfig(m interface{}) (BuildConfig, error) {
|
|
|
|
b := defaultBuildConfig
|
|
|
|
if m == nil {
|
|
|
|
return b, nil
|
|
|
|
}
|
|
|
|
err := mapstructure.WeakDecode(m, &b)
|
|
|
|
return b, err
|
|
|
|
}
|