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
always include file extension on destination files #3490
Conversation
@@ -164,6 +164,8 @@ def destination(base_directory) | |||
dest = site.in_dest_dir(base_directory) | |||
path = site.in_dest_dir(dest, URL.unescape_path(url)) | |||
path = File.join(path, "index.html") if url =~ /\/$/ | |||
output_ext = Jekyll::Renderer.new(site, self).output_ext | |||
path += output_ext if path !~ /#{output_ext}$/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if path.end_with?(output_ext)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
So dope. Thanks for the PR! |
What about checking for the existence of a file extension before adding this one? >> File.extname("path/to/file.htm")
=> ".htm"
>> File.extname("path/to/file.htm").empty?
=> false
>> File.extname("path/to/file")
=> ""
>> File.extname("path/to/file").empty?
=> true If it's empty, then add the output extension. Otherwise, pass. Also, let's use |
permalink: /:title | ||
--- | ||
|
||
Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we output {{ page.url }}
here to ensure the Liquid URL is being set properly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
So I did think about that. It will certainly work, but there's two things I didn't like about it:
That said, I'm happy to add it in if you'd like.
Done. |
okay, thinking more about it, I agree that respecting existing extensions in permalink is probably the way to go for right now at least. This next commit should be safe to merge I think. |
You make good points... people should be able to use dots in their files, and we don't want to limit file extensions... Hm... |
Would you mind adding a test for |
okay, yeah... I now see that there are test cases that specifically focus on files with dots in their name, so this is definitely something we'll want to support. So now I'm back to feeling like we will need to back out the test case from #2925 and find another way to support that (if at all). As @pathawks mentioned on that bug, he could setup redirects for the legacy URLs, which may be the better option here. Right now, I'm fairly certain that Pages still end up with URLs contain the ".html" extension. That never actually impacted me, so I sort of forgot about it. I'll look into what it will take to fix that, and add tests for that and Document (as well as additional tests for dotted filenames). |
I think we should be able to support One idea is to release this in a beta, have @pathawks take a look, and come up with a fix for that later.
Yes, I believe they are presently just as flexible as Posts, so it would be good to have them under test. Thank you!! |
I'd be happy to test 👍 You want I should test this pull request? |
@pathawks Yes please. |
Actually pages are the worst in terms of permalink flexibility (from _config.yaml that is). If you're not using |
Ok then this PR looks good to me. @pathawks, let me know what you figure out. It's hacky, but we could also check for |
@@ -280,6 +280,7 @@ def destination(dest) | |||
# The url needs to be unescaped in order to preserve the correct filename | |||
path = site.in_dest_dir(dest, URL.unescape_path(url)) | |||
path = File.join(path, "index.html") if self.url =~ /\/$/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also this should totally be .end_with?("/")
... not sure if that's for this PR but it's an optimization we should take advantage of. i'll write a benchmark to ensure this
@parkr: as previously noted, we do have tests that ensure that files with dots in them work, which this method of simply looking for a file extension doesn't work with. As a result, this next commit switches back to enforcing This next commit also includes tests for posts and documents. |
What about allowing configuration of HTML files' file extension? is that crazy? |
personally I think so, yes. :) Also keep in mind that I'm fairly certain @pathawks was only interested in having ".htm" extension for legacy, imported-in content. I don't think there is any real demand for having .htm versus .html long-term, we just need a solution that is good enough to handle Pat's imported content (which I personally would still argue that just redirecting to the new URLs would be the much simpler approach) |
👍 |
also /cc @benbalter for that great image above. ben's always talking about our 🎄 of options. |
Yup.
Yup. |
@pathawks: in my brief testing, this plugin seems to do the trick of preserving the ".htm" extension when a post's custom permalink contains that extension: module Jekyll
module Convertible
def output_ext_with_htm
ext = output_ext_without_htm
ext = ".htm" if self.permalink.to_s.end_with?(".htm")
ext
end
alias_method :output_ext_without_htm, :output_ext
alias_method :output_ext, :output_ext_with_htm
end
end Or of course, you could also just redirect from within the web server itself. Assuming that is okay and we're fine removing this behavior from jekyll core, then this should be ready for final review. @parkr could you take another look (there's a few additional tests now as well) |
This ensures that destination files for HTML posts, pages and collections always include the proper file extension (as defined by output_ext) regardless of permalink structure. This allows for URLs that contain no extension or trailing slash to still result in proper destination files with .html extensions. Because this change relies so heavily on output_ext accurately identifying the extension of the destination file, this change also removes the feature test that tested support for permalinks with a .htm extension. In order to support alternate file extensions, a future patch or plugin will need to modify the output_ext value, at which point everything else should work as expected.
I'm fine with removing this feature. We'll need to include it on our upgrading docs page. |
This looks great to me! Thanks, Will! |
I don't think it necessarily needs mentioning in the upgrade docs, since this never actually worked until #3014, which has only shipped with 3.0.0.beta1. (and just to make sure, "ship-it squirrel" == "go ahead and merge"? Or should I wait for you or someone else to merge?) |
👍 |
Yep, means I'm cool merging it. Thanks for checking :) |
Looks good! Though this only works for Markdown and converted files, right? So if I had a ---
layout: default
permalink: /a-page
---
<strong>This is a page</strong> It would output as |
It works just as well for non-converted files. If there is no converter registered for the file extension, then |
always include file extension on destination files
@willnorris Right, forgot about that. Thanks! |
I like the idea of configuring the html extension for .html files as well... I'm hosting on Amazon S3, which supports serving files that are extension-less and doesn't really offer configuration |
@snickers0129 you could do a variation of #3490 (comment) to customize the extension for HTML output files. |
err, you might actually need to patch the Markdown converter, but it would still be the |
Why not just do folder based navigation? The AWS docs states that's supported? |
@willnorris Thanks! I saw that... I just thought I'd cast my vote! @envygeeks You mean putting folders with index.html in them? That causes 302 redirects from url/page to url/page/ |
Oh fair enough, I didn't notice it would do that crazy mess, but I guess I shouldn't be surprised it is a CDN. |
This is an initial take at always including file extensions on destination files written to disk. This is a continuation of the discussion that's happened on #2294 and #3463, and coincides with the WEBrick changes in #3452.
This should only have any impact when the site or post permalink setting is configured without either a trailing slash or the file extension for that file type. In that case, the file written to disk will contain the correct extension for that type, while the URL will remain as specified in the permalink setting.
Notably, this does break the test that was added in #2925 to support files ending in ".htm" rather than ".html" (cc @pathawks to discuss), because this is using the
output_ext
value to determine the expected extension for the destination file. I believe this is the correct behavior. I think that any attempt to support alternate extensions (like ".htm") should make sure one way or another thatoutput_ext
returns the desired alternate extension. Not doing so seems likely to cause more problems down the road. Either way, we certainly need to resolve this breaking test before this can be safely merged.