Adds sort query to posts api
Separates front-end script to data and shell