Fix bug where .standAloneFiles doesn't work with section indexes #124
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a bug in the current code where using
.standAloneFiles
produces broken links on generated section pages.The bug this addresses
You can reproduce the bug as follows:
main.swift
so that the publishing code looks like this:Build the site. Serve it using either
publish run
orpython3 -m http.server 8000
Navigate to
http://localhost:8000/posts/
and click on the "My first post" link.The link is broken. It points to
http://localhost:8000/posts/first-post
, but since HTML generation used the.standAloneFiles
mode, there's noindex.html
at that path.At first this seems the problem is that the foundation theme doesn't support
.standAloneFiles
, which would be fine. However it's impossible for a theme to discover the file mode, so it's impossible to fix this at the theme level. No theme can find the correct path in this case.The fix
I'm addressing this by moving file mode to
Website
so that it will be more widely available:Website
now includesvar fileMode: HTMLFileMode
, and an extension defaults this to.foldersAndIndexFiles
.In
generateHTML(...)
, thefileMode
argument now defaults to nil instead of.foldersAndIndexFiles
. TheHTMLGenerator
instance will usefileMode
if it's provided, which means existing code will still work. If file mode is not provided, it uses the site's value described above.Item
has a newfunc linkPath(for site:Site) -> String
that provides the correct destination for the item based on the site's file mode.The foundation theme has been modified to use this new function on
Item
, to demonstrate how a theme can make use of this functionality.Unit tests have also been updated.
The effect of all of this is that in the reproduction steps above
. foldersAndIndexFiles
is used, the link to "My first post" is stillhttp://localhost:8000/posts/first-post
.standAloneFiles
is used, the link is nowhttp://localhost:8000/posts/first-post.html
.