guncebektas / meteor-friendly-slugs

Meteor package to generate URL friendly slugs from a field with auto-incrementation to ensure unique URLs.
65 stars 15 forks source link

Slug distinct up to a list of fields #17

Closed glyphing closed 9 years ago

glyphing commented 9 years ago

This PR define a new option distinctUpTo, which is relevant only if distinct = true.

Business case: The slug have to be distinct not for the whole collection but only for the given user. Example, we insert:

{title:'Title A', created_user_id:'U1' }
{title:'Title B', created_user_id:'U1' }
{title:'Title C', created_user_id:'U2' }
{title:'Title B', created_user_id:'U2' }
{title:'Title C', created_user_id:'U2' }

And the generated slugs are:

title-a
title-b
title-c
title-b
title-c-1

The URL will be *https://............/:user/:slug

Use of the new option:

    @pages_coll = new Mongo.Collection 'wiki_pages'
    @pages_coll.friendlySlugs { slugFrom: 'title', distinctUpTo: ['created_user_id'] }
todda00 commented 9 years ago

great idea, will publish a new version with this today!