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
.standAloneFilesproduces broken links on generated section pages.The bug this addresses
You can reproduce the bug as follows:
main.swiftso that the publishing code looks like this:Build the site. Serve it using either
publish runorpython3 -m http.server 8000Navigate 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.standAloneFilesmode, there's noindex.htmlat 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
Websiteso that it will be more widely available:Websitenow includesvar fileMode: HTMLFileMode, and an extension defaults this to.foldersAndIndexFiles.In
generateHTML(...), thefileModeargument now defaults to nil instead of.foldersAndIndexFiles. TheHTMLGeneratorinstance will usefileModeif it's provided, which means existing code will still work. If file mode is not provided, it uses the site's value described above.Itemhas a newfunc linkPath(for site:Site) -> Stringthat 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
. foldersAndIndexFilesis used, the link to "My first post" is stillhttp://localhost:8000/posts/first-post.standAloneFilesis used, the link is nowhttp://localhost:8000/posts/first-post.html.