Picture of Daryl Hedley
Slugs as urls
by Daryl Hedley - Wednesday, 27 November 2013, 1:04 PM
 

Hey,

I just wanted to put out there an idea that we've been thinking about. We've gone with underscores to differentiate between content and attributes on models. For example,

"_isComplete":true,

"title":"Title of a component - look I have no underscore on my key"

However _id is reserved for mongodb id's. So what we've been thinking about is using slugs as our unique identifiers and also as our urls.

So instead of getting the following in the url

www.myhostname.com#/co-05

it would become

www.myhostname.com#/my-first-page

Just wanted to get people's thoughts on this idea. I like it due to having bookmarkable urls. But maybe there's problems due to tracking data or the unique-ness of these?

Thanks,

Daryl

Picture of Daryl Hedley
Re: Slugs as urls
by Daryl Hedley - Wednesday, 27 November 2013, 2:02 PM
 

Just to clear up what a slug is. The way Adapt could use slugs is to take the title of the object (let's say a page) and convert any white space into a character like '-'. A page title that was originally "My page title" would have a slug called "my-page-title". So our Adapt urls would become human readable instead of numbers and digits.

thanks,

Daryl

Picture of Matt Leathes
Re: Slugs as urls
by Matt Leathes - Wednesday, 27 November 2013, 2:03 PM
 

I think you should steer well clear of using page titles, for many reasons - not limited to:

  • they frequently change
  • they provide no marker for identifying where exactly in the course hierarchy that element is, unlike IDs (when properly done)
  • pages sometimes have the same title (or swap titles with another page)
  • sometimes you inevitably end up with very long page titles
  • translated page titles may contain characters which are not valid URL strings

Couldn't you use '_ident' instead of '_id'?

 

Picture of Daryl Hedley
Re: Slugs as urls
by Daryl Hedley - Thursday, 28 November 2013, 10:40 AM
 

Hey,

Yeah I agree there's some things that need considering. So we would still have "_id" but these are created by mongodb. We can have some logic and also use a module like this:

https://github.com/dodo/node-slug

to remove any characters that are not valid URL strings. I agree that titles do change quite a lot so this is something that needs looking at. The editor can take care of most of this but what if a developer changes it outside of the editor?

One change to Adapt is that we won't have modules, topics and pages anymore and will instead have contentObjects. This enables us to build menus that are more flexible and can have as much depth as possible without customisation. This was seen as a really big issue when making Adapt open source as menus should be flexible enough. So knowing the course hierachy from a developers point of view won't be through IDs.

We could also have some logic that shortens the titles and adds a versioning if a duplicate is found like below:

"My really really long page title is pretty long right now"

would become:

"my-really-really-long-page"

is a second page that had the same title was created it would be:

"my-really-really-long-page-2"

I like the use of "_ident" and I could see us using that for tracking and the frameworks internal ID system.

At the moment I've left the framework working with "_id" until we have an alternative.

thanks,

Daryl

Picture of Dennis Heaney
Re: Slugs as urls
by Dennis Heaney - Thursday, 28 November 2013, 1:31 PM
 

Just to throw an idea into the mix, the mongodb reserved "_id" attribute really only applies in the context of a course currently being edited in the authoring tool (I think). It might be feasible to run those _ids through a filter to generate something that looks prettier in the browser when publishing/previewing.

Having said that, slugs have the advantage of being descriptive to the user, and the node-slug module looks as though it could handle a lot of the effort for us.