Refactor slug generation

This is a partial fix for bugs which prevent published documents from being visible through the frontend.