Skip to content
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

Make PAGE_INDEX work with PRETTY_URLS #2705

Merged
merged 8 commits into from Mar 29, 2017
Merged

Conversation

Kwpolska
Copy link
Member

@Kwpolska Kwpolska commented Mar 27, 2017

This should end the PAGE_INDEX saga for good. PRETTY_URLS and some corner cases, including .php are supported (and I also unearthed a bug in #2706).

@felixfontein
Copy link
Contributor

If you replace if self.site.config["PRETTY_URLS"]: by if post._has_pretty_url(lang):, it works flawlessy. (Too bad it's kind of a private function...)

Also, we shouldn't use self.site.config["INDEX_FILE"] here, since PRETTY_URL will always result in index.html to be appended, no matter what self.site.config["INDEX_FILE"] is (see definition of Post.destination_path).

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
Also simplifies the removal code with str.rstrip() — it’s always
index.html.

h/t @felixfontein

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
@Kwpolska
Copy link
Member Author

Done. @felixfontein, @ralsina: reviews welcome. I’d like to get this out in a release soon.

@@ -64,6 +64,8 @@ def is_enabled(self, lang=None):
def classify(self, post, lang):
"""Classify the given post for the given language."""
destpath = post.destination_path(lang, sep='/')
if post._has_pretty_url(lang):
destpath = destpath.rstrip('/index.html')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If, for whatever obscure reason, your path happens to be https://example.com/something/index.html/index.html/index.html, this will not result in what you want ;-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, rstrip is not a good idea here at all: it removes all letters from the right of the string which are contained in /index.html. So also /end/html/nix.html would be removed, for example.

@@ -64,6 +64,8 @@ def is_enabled(self, lang=None):
def classify(self, post, lang):
"""Classify the given post for the given language."""
destpath = post.destination_path(lang, sep='/')
if post._has_pretty_url(lang):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe turn this in a version not prefixed by _?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks!

Copy link
Contributor

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, except the use of rstrip.

h/t @felixfontein

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
@Kwpolska Kwpolska merged commit 3835c95 into master Mar 29, 2017
@Kwpolska Kwpolska deleted the page_index-pretty_urls branch March 29, 2017 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants