Switch to using friendly_id for permalink generation

It's better for other people (who know better) to maintain the permalink generation code than for us to do it.

Proposed fix for #4167 + others