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

Extract date and permalink from filename #285

Closed
xaprb opened this issue May 11, 2014 · 10 comments · Fixed by #4494
Closed

Extract date and permalink from filename #285

xaprb opened this issue May 11, 2014 · 10 comments · Fixed by #4494

Comments

@xaprb
Copy link

xaprb commented May 11, 2014

One of the Jekyll features I enjoy is extracting the date and slug/permalink from the filename so I don't need to specify them in the front matter. It would be nice if Hugo would support this as well.

@whereisaaron
Copy link

The Go re2 library supports named capture groups in regular expressions. So one option for this feature would be to configure a regular expression in the config.yaml that, if it yields named matches, could populate the content date and/or link, e.g. if you like to prefix your file names with a date like '20140531-something.md' in would match:

filename-re2: "^(?P<year>\d{4})(?P<month>\d{2})(?P<day>\d{2})"

http://code.google.com/p/re2/wiki/Syntax *

(?P<name>re)    named & numbered capturing group

* The 'P' stands for either 'Principled' or 'Perverse' YMMV :-)

@jon49
Copy link

jon49 commented Sep 5, 2015

Here's a workaround until the enhancement made for people on linux/macs, or if you're smart and figure out how to do it on windows.

POST_SRC := $(subst ./,,$(shell find ./src/post/ -regextype posix-extended -regex '.*[0-9]{4}-[0-9]{2}-[0-9]{2}-.*\.md'))
POST_DEST := content/post/

default: all

define POSTS_PARSE
_target := $(POST_DEST)$(shell echo $1 | grep -Po '\w+\.md')
POSTS := $$(POSTS) $$(_target)
$$(_target): $1
    date=$$$$(echo '$$<' | grep -Po '\d{4}-\d{2}-\d{2}') && \
        sed "1 adate: $$$$date" $$< > $$@;
endef

$(foreach x,$(POST_SRC),$(eval $(call POSTS_PARSE,$x)))

posts: $(POSTS)

init:
    mkdir -p content/post/

all: posts

clean:
    rm -rf content/post/*

.PHONY: all posts init clean

put your original files in ./src/post and it will export to ./content/post. Just type make for one time use and watch make when actively editing files.

@robsonsobral
Copy link

It's easier to keep the files organized too.

@bep bep added the Stale label Feb 28, 2017
@bep
Copy link
Member

bep commented Mar 1, 2017

Note/Update: This issue is marked as stale, and I may have said something earlier about "opening a thread on the discussion forum". Please don't.

If this is a bug and you can still reproduce this error on the latest release or 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.

@borisschapira
Copy link

@bep

  • Easier to keep the files organized
  • No need to charge the Front-Matter with the info (same goes for the language for example)

@borisschapira
Copy link

And I'll add: easier to migrate from Jekyll :)

@bep bep removed the Stale label Mar 1, 2017
@xaprb
Copy link
Author

xaprb commented Mar 1, 2017

I agree, it's a feature request and valuable for the reasons Boris mentioned.

maxandersen pushed a commit to maxandersen/hugo that referenced this issue Jul 31, 2017
Parses filenames for a given date format and parses it into the date variable. Applied using the useFilenameDateAsFallback configuration option which defaults to false for backwards compatibility. Useful for content migration (e.g. from Jekyll et. al.) where date values are provided in filenames and not in frontmatter. Additional config values filenameDateFallbackPattern and filenameDateFallbackFormat allow custom date formats.

Partially addresses functionality discussed in gohugoio#285

fix tests
@stale
Copy link

stale bot commented Dec 6, 2017

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 Dec 6, 2017
@robsonsobral
Copy link

Please, don't give up on this.

@stale stale bot removed the Stale label Dec 6, 2017
@bep bep added this to the v0.35 milestone Jan 22, 2018
@bep bep added the Keep label Jan 22, 2018
@bep bep modified the milestones: v0.35, v0.36, v0.37 Jan 31, 2018
@bep bep modified the milestones: v0.37, v0.38 Feb 11, 2018
@bep bep modified the milestones: v0.38, v0.37 Feb 21, 2018
bep added a commit to bep/hugo that referenced this issue Feb 21, 2018
This commit adds `enableFilenameDateAsFallback` 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.

Fixes gohugoio#285
Closes gohugoio#3310
bep added a commit to bep/hugo that referenced this issue 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 issue 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 issue 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 issue 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 issue 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 issue 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 issue 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 bep modified the milestones: v0.37, v0.38 Feb 26, 2018
bep added a commit to bep/hugo that referenced this issue 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 issue 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 issue 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 issue 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 issue 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 issue 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 issue 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 issue 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 issue 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 issue 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 issue 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 issue 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 issue 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 issue 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 issue 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 as completed in #4494 Mar 11, 2018
@github-actions
Copy link

github-actions bot commented Mar 7, 2022

This issue 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 Mar 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
7 participants