factor out duplication in related content javascript