-
-
Notifications
You must be signed in to change notification settings - Fork 510
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
page.fileSlug and directory index files: date doesn't get stripped out #1947
Comments
Just a gentle nudge to see if this is a known issue or if I'm trying to do something dumb 😄 |
Hopefully the commit above makes it easier to debug this; my expectation would be that Test results:
Edit: Ah, so it seems to be related to this line: https://github.com/11ty/eleventy/blob/master/src/TemplateFileSlug.js#L38. The directory array contains the raw string |
+1 for this feature. I've faced with the same issue. Maybe there is sense to add ability to add custom function to extract any mete from file path: #2132 |
I put up a PR (#2111) to fix this a while back, but I assume it's low priority at the moment for the beta release (no reviews yet). Plus it would introduce a breaking change. I'm guessing we want to prefer @mahnunchik's proposed workaround since it wouldn't introduce breaking changes? |
Added a few labels here, you’re absolutely right that this should be fixed but it is a breaking change so unfortunately I have to put it on hold for now (sorry) |
Describe the bug
Currently, my post Markdown files follow the
YYYY-MM-DD-file-slug.md
convention and are located immediately under a_posts
directory. I aggregate all of these files into a customposts
collection using 11ty's collection API:I also have the following
_posts.json
at the root of my_posts
directory to apply common front matter to each post; of note is thepermalink
value, which usespage.fileSlug
:As expected,
page.fileSlug
strips out the dates from my file names. SoYYYY-MM-DD-file-slug
maps to the URL/blog/file-slug/
. This is all working as intended.Now, I want to restructure my blog to co-locate images and posts under the same directory using index files. So instead of containing the Markdown posts as immediate children, my
_posts
directory will now contain nested directories of the formYYYY-MM-DD-file-slug
, and nested inside each directory will be a correspondingindex.md
for the post and animages
directory for any images.I've adjusted my config to create posts using
collection.getFilteredByGlob('src/_posts/**/*.md')
. This works. However, per the examples in the documentation linked above, I would expect the date to also get stripped out from the directory name, but it doesn't. So now, my post permalinks are/blog/YYYY-MM-DD-file-slug/
rather than/blog/file-slug/
:To Reproduce
co-located-images
:yarn
to install dependencies.yarn serve:eleventy
to start up just the 11ty server.localhost:4001
. Click any post, and observe that its URL contains the date in the slug.Expected behavior
When using index files in directories, the date should get stripped out from the directory name in
fileSlug
.Environment:
The text was updated successfully, but these errors were encountered: