FactGen: Faithful Text Generation by Factuality-aware Pre-training and Contrastive Ranking Fine-tuning