Yeah, I know, it sounds like a big change, but please hear me out
Prior discussions:
Issues with the current approach
- Zola’s code has huge duplications. Having pages and sections as separate entities introduces bugs and nasty discrepancies, e.g.:
- transparent sections do not reparent their subsections
- subsection sorting is missing
- subsection pagination isn’t a thing
get_section()
is missinglang
option- taxonomies for sections are missing
- subsections are missing many useful fields, e.g.
summary
,date
,update_date
(requested here)
- The user’s code is duplicated. I run
{% set item = page | default(value=section) %}
in shortcodes and macros to enable them both for sections and pages. This is not perfect, since atm their fields are slightly different. - Users sometimes want to have sections nested under pages.
Page vs. Section
The actual difference between these two is minor:
Pages are missing these fields:
pages: Array<Page>
subsections: Array<String>
generate_feed: bool
Sections are missing:
date: String?
updated: String?
slug: String
draft: Bool
summary: String?
taxonomies: HashMap<String, Array<String>>
lower: Page?
higher: Page?
year: Number?
month: Number?
day: Number?
colocated_path: String?
IMO, if we remember that sections can have markdown, then most of the fields are worth adding anyway, which makes them very similar.
On the other hand, bringing pages to parity with sections looks fairly trivial
Documentation complexity and cognitive load
I hear the arguments that it’s easier for a user to digest familiar concepts section=folder
and page=file
and then operate on this, but later this fires back, as shown in the Issues section of this post.
We can safely assume that Zola’s users are at least somewhat familiar with how HTML and websites work. And for web developers, everything is a page. Many have already created index.html
to represent a “folder” and colocated pages for individual “files”, so the new concept should be even more natural than the filesystem analogy.
I suggest that instead of “sections and pages” we explain it like this:
Page can be an individual file:
post.md
Page can be a directory:post/index.md
Page can have subpages:post/subpost.md
It’s easier to remember than meaningful underscores in filenames, IMO
Backwards compatibility
Of course, we mustn’t break the existing websites by any means. We can achieve backwards compatibility by:
- Adding all missing section’s fields to the page. The
subsections
field can be hidden, but present - In terra context aliasing section to page
- Treating
_index.md
like a normal page, but withtemplate="section.html"
property. This will allow to distinguish between sections and pages for users who prefer it this way
After a couple of versions which warn users of using deprecated sections and page fields, we can drop the compatibility, but leave #3, as it seems like a good idea regardless.
Proposal
So, the actual plan is scoped and straightforward:
- Add
Section
functionality toPage
, i.e. these fieldsgenerate_feed
subpages
- Add aliases:
context.section
→context.page
page.pages
→page.subpages
get_section()
→get_page()
- Add a compatibility field
page.subsections
, which will list subpages with children - Handle
_index.md
to correspond to a page withtemplate="section.html"
Alternatives
One small adjustment can be that any page with subpages would use section.html
template by default, but that’s to be discussed.
Outro
This was a bit hectic post, but hopefully, I made my points clear. I do believe that unifying sections and pages into a single entity will improve Zola’s code base, user experience, and unlock new use cases without sacrificing anything.
Please, let me know what you think about this, any feedback is appreciated