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

Improve permalinks customizations #64

Merged
merged 6 commits into from Jan 19, 2016

Conversation

Projects
None yet
2 participants
@jjk-jacky
Copy link
Contributor

jjk-jacky commented Jan 17, 2016

As I was trying out Spress and looking into permalinks, I noticed a few "flaws"
in the way it works, and how some things seemed impossible to be done, so I
looked into addressing them, resulting in those patches.

Specifically, I think that falling back to the current date when an item doesn't
have an attribute "date" is useless (I can't imagine anyone who'd like a page to
have a different URL based on the date of generation of the site), as
illustrated by the fact that predefined permalinks do not actually work that
way, but instead fallback to permalink "none" when there's no "date" attribute.

I think this should in fact have been the behavior for user-defined permalinks
as well, makes (more) sense and also makes things consistent. So now if
date-related variables are used in a user-defined permalink, but there's no
"date" attribute, simply fallback to "none".

Another thing was that "pretty" also came with a special "extensionless" mode,
which wasn't available by any other means. As a result, if one wanted to use
that mode but with a different template for its permalink, it simply wasn't
possible.

So a patch adds a new option "no_html_extension" which, when true, enables this
"extensionless" mode (for items resulting in "html" files only, ofc). What it basically
does is remove ":extension" and ".:extension" from the permalink, then use the
result as link (urlPath), and adds "/index.html" for the generated file (path)

As a result "pretty" is simply the same permalink as "date" only with
"no_html_extension" forced enabled.
And of course, it is possible to enable "no_html_extension" with any user-defined
permalink as well.

jjk-jacky added some commits Jan 15, 2016

PermalinkGenerator: Use constant PERMALINK_NONE for clarity
Makes it clearer when we're defaulting/falling back to the predefined
permalink 'none'
PermalinkGenerator: Always fallback to 'none' if no 'date'
If a permalink uses date variables (:year, etc) but the item has no
attribute 'date', fallback to predefined permalink 'none' instead of
using the current date, as that doesn't make a lot of sense.

Also, it's consistent behavior since predefined permalinks work that way
already.
PermalinkGenerator: Make 'pretty' more consistent...
...when it comes to falling back to 'none'

That is, instead of falling back for extension other than 'html', we
only do so for items w/out a 'date' attribute.

The end result will pretty much be the same, but it's more consistent
with other predefined permalinks as well as user-defined ones.
Add 'no_html_extension' for extensionless URLs
This is what the predefined permalink 'pretty' did, only now it is
available as an option, so it can be used with any user-defined permalink.
@yosymfony

This comment has been minimized.

Copy link
Member

yosymfony commented Jan 18, 2016

👍

@yosymfony yosymfony merged commit 087d490 into spress:master Jan 19, 2016

3 checks passed

Scrutinizer Running
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

yosymfony added a commit that referenced this pull request Jan 19, 2016

yosymfony added a commit to spress/spress.yosymfony.com that referenced this pull request Jul 23, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment