Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better more complete fix for allowing filename to set date and slug #3762

Closed

Conversation

maxandersen
Copy link
Contributor

@maxandersen maxandersen commented Aug 1, 2017

This is a better and more complete PR for #3310 which:

  • has actual working tests :)
  • uses a single boolean to decide if should enable filename as fallback or not
    (this allows us to add if needed more and more complex parsing of the header rather than lock it down to user specified regex)
  • also sets the slug so the date is not part of the url

@maxandersen maxandersen force-pushed the devjack-filename-date-fallback branch 2 times, most recently from caaec55 to 903bdef Compare August 1, 2017 20:42
hugolib/page.go Outdated
p.Date = fi.ModTime()
p.Params["date"] = p.Date
}
}

if p.Date.IsZero() && p.s.Cfg.GetString("useFilenameDateAsFallback") != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • useFilenameDateAsFallback is a bool (not a string)
  • also, I think it should default to true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed use of bool and I changed the default to true including updating the docs/commit messages to match.

hugolib/page.go Outdated
p.Date = fi.ModTime()
p.Params["date"] = p.Date
}
}

if p.Date.IsZero() && p.s.Cfg.GetString("useFilenameDateAsFallback") != "" {
dateExp := regexp.MustCompile("(?P<year>\\d{4})\\-(?P<month>\\d{2})\\-(?P<day>\\d{2})-(?P<slug>.*)\\..*")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regexp looks reasonable slow to compile so it should be pulled out into a variable and reused.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

@maxandersen maxandersen force-pushed the devjack-filename-date-fallback branch from 903bdef to b79112a Compare August 17, 2017 09:54
@maxandersen
Copy link
Contributor Author

I've updated with a fix that ensures even if post has no frontmatter dates gets calculated correctly.

Anything else I need to do here to get it merged in ?

@maxandersen maxandersen force-pushed the devjack-filename-date-fallback branch 2 times, most recently from d779ebc to e9417dc Compare August 29, 2017 19:08
@maxandersen
Copy link
Contributor Author

now rebased against master.

@maxandersen maxandersen force-pushed the devjack-filename-date-fallback branch 3 times, most recently from 74addc9 to dfa3673 Compare August 29, 2017 19:17
return err
}
}
p.updateMetadata()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is added so when you render pages that are missing frontmatter they don't get more broken than they need to be. Took me ages to figure out that title/slug and lastmod changes were not handled unless I had an explicit title in frontmatter. With this change it at least still sorts and gets rendered somewhat properly.

@bep bep requested a review from moorereason August 31, 2017 08:29
bep and others added 4 commits September 9, 2017 09:09
Removed useFilenameDateAsFallback option and instead check to see if filenameDateFallbackPattern is set. As a result, filenameDateFallbackPattern now defaults to Nil.

Added a reference example to the docs to ease copy/paste configuration for a popular YYYY-MM-DD filename format.
Why:

 * when migrating from systems like jekylla and awestruct to hugo
   you might have hundreds if not thousands of blog entries using the
   filename as a way to set the date and slug part of page.
   i.e. 2017-08-01-my-life-as-a-dog.md would have a date of 2017-08-01 and
   a url called my-life-as-a-dog.md.

This change addreses the need by:

 * introduce a setting called `useFilenameDateAsFallback` that defaults to true,
   which will derive date and slug from the filename.
 * fix bug where adjusting metadata defaults were ignored when page has no frontmatter
@maxandersen maxandersen force-pushed the devjack-filename-date-fallback branch from dfa3673 to 7e6ca8b Compare September 9, 2017 07:15
@maxandersen
Copy link
Contributor Author

rebased again - hope this can go in soon :)

@stale
Copy link

stale bot commented Jan 7, 2018

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Jan 7, 2018
@maxandersen
Copy link
Contributor Author

this is still relevant - just awaiting for update on it from dev.

@stale stale bot removed the Stale label Jan 17, 2018
@vassudanagunta
Copy link
Contributor

vassudanagunta commented Jan 22, 2018

This takes away the flexibility of @devjack's PR #3310, hardcoding the filename pattern. I think that's the wrong direction to go. I'm going to offer Yet Another Take when I get the chance in the next few of days.

BTW, the four component commits in this PR are strange. The first only has the second half of @devjack's PR, the third is attributed to @bep and has a diff of +38 −14,450, and the final attributed to @maxandersen has a diff of +14,574 −14. 😮

@maxandersen
Copy link
Contributor Author

the flexibility about customizing pattern was taken away to make the initial feature simpler and avoid overengineering it.

@bep bep added this to the v0.35 milestone Jan 22, 2018
@bep
Copy link
Member

bep commented Jan 22, 2018

This takes away the flexibility of @devjack's PR #3310, hardcoding the filename pattern.

This only works if it is simple. Both to document/explain and to maintain/test and it makes your content as portable as possible. So one filename pattern it is.

I'm sorry for neglecting this issue for so long. I don't need it myself, but I understand that many others are. I have added the tracking issue to the 0.35 milestone. Let's see if we can agree on a solution by then.

bep added a commit to bep/hugo that referenced this pull request Feb 21, 2018
This commit adds a new config option  which, when enabled and no date is set in front matter, will make Hugo try to parse 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`:

[frontmatter]
dateFallbacks = ["filename"]

Fixes gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
bep added a commit to bep/hugo that referenced this pull request Feb 21, 2018
This commit adds a new config option  which, when enabled and no date is set in front matter, will make Hugo try to parse 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]
dateFallbacks = ["filename"]
```

Fixes gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
bep added a commit to bep/hugo that referenced this pull request Feb 21, 2018
This commit adds a new config option  which, when enabled and no date is set in front matter, will make Hugo try to parse 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]
dateFallbacks = ["filename"]
```

Fixes gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
bep added a commit to bep/hugo that referenced this pull request Feb 21, 2018
This commit adds a new config option  which, when enabled and no date is set in front matter, will make Hugo try to parse 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]
dateFallbacks = ["filename"]
```

Fixes gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
bep added a commit to bep/hugo that referenced this pull request Feb 21, 2018
This commit adds a new config option  which, when enabled and no date is set in front matter, will make Hugo try to parse 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]
defaultDate  = ["filename"]
```

Fixes gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
bep added a commit to bep/hugo that referenced this pull request Feb 21, 2018
This commit adds a new config option  which, when enabled and no date is set in front matter, will make Hugo try to parse 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]
defaultDate  = ["filename"]
```

Fixes gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
bep added a commit to bep/hugo that referenced this pull request Feb 22, 2018
This commit adds a new config option  which, when enabled and no date is set in front matter, will make Hugo try to parse 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]
defaultDate  = ["filename"]
```

Fixes gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
bep added a commit to bep/hugo that referenced this pull request Feb 22, 2018
This commit adds a new config option  which, when enabled and no date is set in front matter, will make Hugo try to parse 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]
defaultDate  = ["filename"]
```

Fixes gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
bep added a commit to bep/hugo that referenced this pull request Feb 26, 2018
This commit adds a new config option  which, when enabled and no date is set in front matter, will make Hugo try to parse 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]
defaultDate  = ["filename"]
```

Fixes gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
bep added a commit to bep/hugo that referenced this pull request Mar 8, 2018
This commit adds a new config option  which, when enabled and no date is set in front matter, will make Hugo try to parse 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]
defaultDate  = ["filename"]
```

Fixes gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
bep added a commit to bep/hugo that referenced this pull request Mar 10, 2018
This commit adds a new config option  which, when enabled and no date is set in front matter, will make Hugo try to parse 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]
defaultDate  = ["filename"]
```

Fixes gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
bep added a commit to bep/hugo that referenced this pull request Mar 11, 2018
This commit adds a new config option  which, when enabled and no date is set in front matter, will make Hugo try to parse 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", "date"]
```

This commit also creates a testable unit from the date front matter handling. We should try to get `:git` as a keyword in the same config map, but that will have to wait for a later time.

Fixes gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
bep added a commit to bep/hugo that referenced this pull request Mar 11, 2018
This commit adds a new config option  which, when enabled and no date is set in front matter, will make Hugo try to parse 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", "date"]
```

This commit also creates a testable unit from the date front matter handling. We should try to get `:git` as a keyword in the same config map, but that will have to wait for a later time.

So, if you want to use the `file modification time`, this can be a good configuration:

```toml
[frontmatter]
date = [ "date",":fileModTime"]
lastMod = ["lastMod" ,":fileModTime", "date"]
```

The current config (what you get when doing nothing):

```toml
[frontmatter]
date = ["date","publishDate", "lastmod"]
lastmod = ["lastmod", "date","publishDate"]
publishDate = ["publishDate", "date"]
expiryDate = ["expiryDate"]
```

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`)..

Fixes gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
bep added a commit to bep/hugo that referenced this pull request Mar 11, 2018
This commit adds a new config option which, when enabled and no date is set in front matter, will make Hugo try to parse 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", "date"]
```

This commit also creates a testable unit from the date front matter handling. We should try to get `:git` as a keyword in the same config map, but that will have to wait for a later time.

So, if you want to use the `file modification time`, this can be a good configuration:

```toml
[frontmatter]
date = [ "date",":fileModTime"]
lastMod = ["lastMod" ,":fileModTime", "date"]
```

The current config (what you get when doing nothing):

```toml
[frontmatter]
date = ["date","publishDate", "lastmod"]
lastmod = ["lastmod", "date","publishDate"]
publishDate = ["publishDate", "date"]
expiryDate = ["expiryDate"]
```

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`).

Fixes gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
bep added a commit to bep/hugo that referenced this pull request Mar 11, 2018
This commit adds a new config option which, when enabled and no date is set in front matter, will make Hugo try to parse 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", "date"]
```

This commit also creates a testable unit from the date front matter handling. We should try to get `:git` as a keyword in the same config map, but that will have to wait for a later time.

So, if you want to use the `file modification time`, this can be a good configuration:

```toml
[frontmatter]
date = [ "date",":fileModTime"]
lastMod = ["lastMod" ,":fileModTime", "date"]
```

The current config (what you get when doing nothing):

```toml
[frontmatter]
date = ["date","publishDate", "lastmod"]
lastmod = ["lastmod", "date","publishDate"]
publishDate = ["publishDate", "date"]
expiryDate = ["expiryDate"]
```

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.

Fixes gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
bep added a commit to bep/hugo that referenced this pull request Mar 11, 2018
This commit adds a new config option which, when enabled and no date is set in front matter, will make Hugo try to parse 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", "date"]
```

This commit also creates a testable unit from the date front matter handling. We should try to get `:git` as a keyword in the same config map, but that will have to wait for a later time.

So, if you want to use the `file modification time`, this can be a good configuration:

```toml
[frontmatter]
date = [ "date",":fileModTime"]
lastMod = ["lastMod" ,":fileModTime", "date"]
```

The current config (what you get when doing nothing):

```toml
[frontmatter]
date = ["date","publishDate", "lastmod"]
lastmod = ["lastmod", "date","publishDate"]
publishDate = ["publishDate", "date"]
expiryDate = ["expiryDate"]
```

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.

Fixes gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
bep added a commit to bep/hugo that referenced this pull request Mar 11, 2018
This commit adds a new config option which, when enabled and no date is set in front matter, will make Hugo try to parse 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. 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 gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
bep added a commit to bep/hugo that referenced this pull request Mar 11, 2018
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. 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 gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
bep added a commit to bep/hugo that referenced this pull request Mar 11, 2018
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 gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
bep added a commit to bep/hugo that referenced this pull request Mar 11, 2018
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 gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
bep added a commit to bep/hugo that referenced this pull request Mar 11, 2018
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 gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
bep added a commit to bep/hugo that referenced this pull request Mar 11, 2018
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 gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
bep added a commit to bep/hugo that referenced this pull request Mar 11, 2018
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 gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
bep added a commit to bep/hugo that referenced this pull request Mar 11, 2018
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 gohugoio#285
Closes gohugoio#3310
Closes gohugoio#3762
Closes gohugoio#4340
@bep bep closed this in #4494 Mar 11, 2018
@github-actions
Copy link

github-actions bot commented Feb 6, 2022

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants