refactoring attachments, now read reference dir
permalink added both in display and in edit