Hacker News new | ask | show | jobs
by a13n 3173 days ago
For Canny, I wrote some awesome code that I'm proud of that turns a "post title" into a unique URL.

https://react-native.canny.io/feature-requests/p/headless-js...

For example, a post with title "post title" will get url "post-title".

Then a second post with title "post title" will get url "post-title-1".

Since there's only one URL part associated with each post, it's a unique identifier.

This gets rid of the ugly id in the URL, for epic URL awesomeness.

Furthermore, if you edit the first post to have "new post title" then its URL will update to "new-post-title", but "post-title" will still redirect to "new-post-title".

Someday I'm gonna open source a lib that lets you easily add awesome URLs to your app. :)

2 comments

> For Canny, I wrote some awesome code that I'm proud of that turns a "post title" into a unique URL.

Did you mean "slug"? What you are describing is a basic feature of most blogging software since the inception of blogs...

It's way more than that.

– Automatically handling duplicates

– Avoiding needing to include the unique ID in the URL

– Updating the URL after editing the post

– Redirecting previous versions to the new version

I think most blog platforms have that...
Wordpress has supported all of that for as long as I can remember
What's your point?
The point is you're reinventing the wheel.
The annoying part is doing the database lookups to check for collisions / canonicalization, so what would your lib be generalizing?
Yeah good point. Maybe it'd be better as a blog post with an associated repo in one implementation (Node + Mongo) and great documentation.