Calculate the page count correctly (blatantly borrowed from Jekyll).