-
-
Notifications
You must be signed in to change notification settings - Fork 485
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
Collections for directory indexes #502
Comments
To be clear here, the output you showed above is what you expect the output to be, correct? The following is the structure of the content that should appear in your output directory, yes?
Assuming the following structure of input files …
… and the posts having this structure … ---
title: Title 1
date: 2014-01-04
---
# Title 1 … and the posts.json file looking like this … {
"layout": "base.liquid",
"permalink": "{{ page.date | date: '%Y' }}/{{ page.date | date: '%m' }}/{{ page.date | date: '%d' }}/{{ page.fileSlug }}/index.html"
} … you can achieve the desired output structure. For more information on what you can do with permalinks, read https://www.11ty.io/docs/permalinks. |
Thanks @kleinfreund, to output: This is straightforward. My difficulty is with the index files in the parent directories: output:
I was under the impression (apart from pagination) 11ty didn’t provide a means to generate multiple output files from a single template. I’ll be super excited if I’m wrong!? The index files I’m after are not the post itself, but rather a list of links to posts contained by the each sub directory (e.g. https://ollicle.com/2007/, https://ollicle.com/2007/jun/). I’m looking for a means to generate and update these without manually editing each index.liquid template. My input currently includes these subdirectories. Partly because I was assuming I needed template files in place to generate the sub-directory – mostly because I am transforming my old output to be my new input and I’m lazy:
I hope that is clearer. |
Did you have a look at this #332, especially Zach's comment?
I don't think you're wrong there. But you could create a custom collection / object structure that multiple templates can consume and use Maybe you could have a
If it were me, I'd consider compiling a single HTML archive for each year (or year-month if many posts), attaching HTML IDs (anchors) for each dated section, then 301 redirect those legacy URLs to their corresponding anchors on the single archive page, something like # /2014/index.html
<h1>2014</h1>
<h2 id="jan">January 2014</h2>
<h3 id="jan-04">January 4th, 2014</h3>
<ul><li>[... posts]</li></ul>
<h2 id="feb">February 2014</h2>
<h3 id="feb-12">February 12th, 2014</h3>
<ul><li>[... posts]</li></ul> redirect /2014/01/04 >>> /2014/index.html#jan-04
redirect /2014/02 >>> /2014/index.html#feb |
Thank-you @jevets, |
Thank you everyone for participating here! @ollicle did this get you far enough along or do you want to pivot this issue into a feature request? |
Sorry @zachleat life has intruded on my opportunities to try this thus far. Feel free to close for now. The code solutions generously offered seem feasible at a glace. |
I’ve adapted the approach suggested by @edwardhorsford but I am struggling to see output collection. Running
Specifically how do I eye-ball the content of a collection, presuming it is not in the shape I am expecting. Does anyone have general debugging strategies when building and using custom collections such as this? |
Hm, Nunjucks has dump for that. You could define one as filter, though. |
@ollicle I'm assuming you modified my code since it was somewhat specific to my usage of tags. My first step might be to put some console logs in the js generating the collection - so you can see what data structure you're giving to eleventy. A couple things I do / have set up on the Nunjucks side: A debug filter which logs the thing to the server console. FYI this can be rather long for eleventy objects. So: Or iterate through them:
|
Thank-you @Ryuno-Ki and @edwardhorsford you guys are most excellent! I switched to nunjucks and got console logging and now I am getting somewhere.
@edwardhorsford I had indeed changed your code, although insufficiently as it turned out. Not sure I have the collections correct yet - but now I can see the output things are looking up. I took your iteration idea a step further :)
|
Thanks again @edwardhorsford for sharing the paths you have travelled on this. The ah-ha moment for me has been understanding:
contentByDate.js:
eleventy.js:
snippet of njk layout:
I’ve got lots of work to do before I’ll mark this off as a real world solution – but I consider my question answered, thanks all. |
Thanks for sharing all of this, it helped me find a way to seriously increase performance. I had initially created a template that filtered for content, but pre-processing into a collection-of-collections is much more efficient. |
@ollicle hi, I'm looking for the same feature, and looking at your layout code (thanks for sharing!), it seems you don't use pagination. How do you generate pages for each year and month? [UPDATE] I've managed to do it, with a template for months and another for years! |
@nhoizey same - I have a template for each and a collection for each. |
While attempting to translate my old Moveable Type generated blog to 11ty I’ve hit a snag. The posts appear in directories based on post dates e.g.
/2014/jan/04/eg-post-1.html
Each of these sub directories include indexes which list the posts whose date shares the same year, month, day. Example of the desired file output:
So far I’ve attempted to do this by iterating over a large set of years/months/days, creating a glob based collection for each. By deriving the collection names from the date I hoped to later correlate these collections with each index template via its inputPath.
This is not working, but aside from that, generating these collections is really slow which makes it impractical anyway.
Is there a more effective approach to generate directory indexes for date derived sub directories with 11yt?
Thanks in advance for your ideas.
The text was updated successfully, but these errors were encountered: