-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
Sorting blog posts in the content/blog
subfolder
#196
Comments
I was able to do so by changing what const getFolderName = (data) => {
const path = data.page.filePathStem;
const parts = path.split("/");
const folderName = parts[parts.length - 2];
return folderName;
};
module.exports = {
tags: ["posts"],
layout: "layouts/post.njk",
eleventyComputed: {
// Compute the `date` property for each post
date: (data) => {
const folderName = getFolderName(data);
const datePart = folderName.split("_")[0]; // 'YYYY-MM-DD'
const [year, month, day] = datePart.split("-").map(Number);
return new Date(year, month - 1, day);
},
// Compute the `permalink` property for each post
permalink: (data) => {
const folderName = getFolderName(data);
// Remove the date part from the folder name
const slug = folderName.split("_").slice(1).join("_");
// Construct the permalink
return `/blog/${slug}/`;
},
},
}; And I used a Python script made with ChatGPT to rename all the folders using dates from the blog posts frontmatter :) What do you think? |
verlok
changed the title
Ordering blog posts in the
Sorting blog posts in the Nov 25, 2024
content/blog
subfoldercontent/blog
subfolder
I applied that to my blog, which is maintained at this GitHub repository, and deployed to this domain. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My
content
folder has ablog
subfolder, which in turn has all the blog posts as subfolders, e.g.how-to-use-this-for-that
, and every blog folder contains anindex.md
file for the post content, plus images that are required for that blog post.The problem I have is to be able to determine which blog post is more recent and what is older in the
content/blog
subfolder. I would like a solution where every folder started with the date, e.g.2024-11-11_how-to-use-this-for-that
.How can I achieve that using eleventy v2? And with v3?
The text was updated successfully, but these errors were encountered: