-
-
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
Add 'title' to collection URLs #2864
Add 'title' to collection URLs #2864
Conversation
This looks great! I'd like to make the handling of slug creation a bit simpler and remove it from the url_placeholders method. Maybe |
Thanks for doing the actual coding here though, it's very appreciated. ❤️ |
Brilliant. 🎉 |
nil | ||
else | ||
name.downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-') | ||
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.
What do you think about this simplification?
if name
name.downcase.gsub # ...
end
Or you can use unless name.nil?
. IIRC, methods return nil
by default. What do you think?
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 can we use something else besides name
? It's pseudo-reserved I think.
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.
I'm beginning to think that a sluggify
function would turn out to be immensely useful throughout the rest of the project as well, and since it doesn't really have anything to do with Documents in the first place, would it be better to move it to Utils?
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.
I also think it should be called slugify
, FWIW.
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, I suggest just stealing Rails method. \w
is clever, but for truly "pretty" URLs it should be both lowercase and accepting of -
or _
.
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.
👍 for moving it to Utils
and for yoinking it from Rails.
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.
I agree 💯% and will update this pull request accordingly. 😄
Incidentally, wouldn't it also be useful to expose the slugify
method in a Liquid template? If so, should that wait for a separate pull request?
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.
Thank you!
If you want to add it to Jekyll::Filters
, go ahead 😄 I think that would be a valuable add. It can just pass to Jekyll::Utils.slugify
.
Looking gooooooood. |
Thanks for all the ✨ feedback, everyone! Let me know if you'd like me to make any more changes—I'd be particularly interested in suggestions for further unit tests. 😄 |
@parkr Does this look good to merge? |
I'll take a look tonight or (more realistically) in the morning tomorrow. Sorry for the delay! Thanks for all your contributions to Jekyll!!!! |
My pleasure! 😄 Just wanted to make sure that I didn't forget anything here. |
# Replace each non-alphanumeric character sequence with a hyphen | ||
slug = string.gsub(/[^a-z0-9]+/i, '-') | ||
# Remove leading/trailing hyphen | ||
slug.gsub!(/^\-|\-$/i, '') |
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.
is this ensuring that there are no double-hyphens? i.e. no "this is my !#-fave blogs" !~> "this-is-my--fave-blogs
?
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.
No, it ensures there's no starting or ending hyphen: "¡Hola!" !~> "hola"
.
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.
What @gjtorikian said. 😄
Actually, the first regex ensures that there are no double hyphens:
string.gsub(/[^a-z0-9]+/i, '-')
Is this the desired behavior, or should we allow double hyphens in some situations?
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.
I've never seen a double hyphen and though "That's a good use of a double hyphen in a 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.
No, it ensures there's no starting or ending hyphen
Merp, yes, I meant to refer to the entire method.
the first regex ensures that there are no double hyphens
Great! Then we're good to go.
LGTM excepting the above comment about double-hyphens. |
Thanks for all your hard work, @kansaichris! I think I'll try to wrap up a 2.4.0 release of Jekyll sometime this weekend or on Monday. |
🎉 |
This mimicks posts most closely. It can be overridden by the YAML front matter. Undoes some of #2864.
Spiritual successor to #2799.
This addresses @parkr's comment from #2799:
This also addresses @gjtorikian's comment from #2847:
Let me know what you think! ❤️