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

fileSlug should include respect folders with leading ISO dates #1742

Closed
Brixy opened this issue Apr 21, 2021 · 2 comments
Closed

fileSlug should include respect folders with leading ISO dates #1742

Brixy opened this issue Apr 21, 2021 · 2 comments

Comments

@Brixy
Copy link

Brixy commented Apr 21, 2021

Eleventy’s flexibility is great.

So far fileSlug only works for—well, it’s a telling name—file names, but should be extended to be used with folders.

This is a common and very logical way to structure posts and associated media:

.
└─ src/
   └─ posts/
      └─ 2021-04-20-a-post-without-media.md # not a folder
      └─ 2021-04-20-another-post/
      │  ├─ index.md
      │  ├─ image.jpg
      │  └─ audio.mp3
      └─ 2021-04-21-a-third-post/
         ├─ index.md
         └─ image.png

A simple permalink redirect is not possible in posts.json because of the mixture of .md files and folders with leading ISO dates. (Yet, Eleventy seems to recognize dates from folder names.)

It is easy to accomplish something like that using a filters for permalink.

But you run into problems due to #1140.

Thank you!

@Brixy
Copy link
Author

Brixy commented Jul 1, 2021

I just happened to find out that eleventy does get the date from a folder name. Perfect!

The file /posts/2021-07-01-my-post/index.md has the following date (without adding date in front matter):

(Thu Jul 01 2021 00:00:00 GMT+0200 (Mitteleuropäische Sommerzeit)

Should we clarify this?:

  • Is it the expected behaviour that Eleventy gets the date from a folder name?
  • Will this work in the future?

To get rid of the date from the path I just added a little filter:

eleventyConfig.addFilter('removeDateFromPath', (value) => {
  return value.replace(/\d{4}-\d{2}-\d{2}-/, "");
});

zachleat added a commit that referenced this issue Aug 6, 2021
zachleat added a commit to 11ty/11ty-website that referenced this issue Aug 6, 2021
@zachleat
Copy link
Member

zachleat commented Aug 6, 2021

Yeah! This is expected. We use the full input path to search for the date format. I updated the docs to clarify this a bit, thanks for the ping!

@zachleat zachleat closed this as completed Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants