-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
Allow placeholders in permalinks #3031
Conversation
@placeholders.inject(@permalink) do |result, token| | ||
break result if result.index(':').nil? | ||
result.gsub(/:#{token.first}/, self.class.escape_path(token.last)) | ||
end |
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.
This smells of duplication!
👍 |
That should be better. |
# | ||
# Returns the _unsanitizied_ String URL | ||
def generate_url | ||
@placeholders.inject(@template) do |result, token| | ||
@placeholders.inject(@permalink || @template) do |result, token| |
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.
Let's restructure this. #generate_url
should take a parameter – a template – that it uses as the first argument to #inject
. That way we can have #generated_permalink
and #generated_url
use and memoize the permalink and template, respectively.
def to_s
generated_permalink || generated_url
end
def generated_permalink
(@generated_permalink ||= generate_url(@permalink)) if @permalink
end
def generated_url
@generated_url ||= generate_url(@template)
end
def generate_url(template)
@placeholders.inject(template) do |result, token|
# etc...
end
end
Done! |
/cc @benbalter – would love your 👀 |
In the 2.5.0 post what is |
Allow the regular placeholders (
basename
,path
,ext
) in permalinks. This is useful for setting permalink rules in frontmatter defaults (for example if I want my SCSS files in/assets/scss/
to output to/assets/css/
).Changes will only break functionality for people currently using
:path
,:ext
,:basename
, etc. in their permalinks. Permalinks without any of these special symbols will remain the same.Ref. #2475, #1712.