linnovate/mean — pull request #784 by Luka111 (2014-09-14 15:40:11+00:00)
Title: SEO friendly articles

The example articles package now gets another example for custom mongodb ids.
Instead of using the standard ObjectId from mongo, this extension creates unique String ids and hands them over to mongodb.
With this approach, mean articles become 'SEO friendly'.
The extension is activated through a config setting in the standard mean way. Currently it is in config/env/all.js, in the form of:

articles: {
SEO: false //or true
}

The algorithm for generating unique String ids from titles is simple:
1. 'sanitize' the title of the article to create/save
2. try to write the article with the generated unique String id
3. on duplicate key failure, append an underscore sign _ to the unique String id, and go back to 2

Sanitize is done through a simple encodeURIComponent call. More specific algorithms might be implemented through specialization of the value for the SEO config parameter.

Disclaimer: the extension is still in 'example mode'. It is imporant to note that on a single database one should not switch from ObjectIds to Strings by switching the SEO parameter from false to true. Whatever option is chosen, articles created using the opposite option will not be fetchable from the database.