add shared logic for tag sorting

To merge with [HabitRPG/#11]()