It's been a little while since I've posted. Sorry about that; but I'm back.
Now, in the last post I went over how to store your blog posts in a database and retrieve them for editing, now we need to show them to the user and provide them with an rss feed to subscribe to your site with.
First thing is to show the blog roll, and because these pages will no longer be static we will move them from the StaticPages.js file and start a new Class called "PublicPages.js" this page will house all of the dynamic pages on the website. I have posted the entire file below to make it simple, and I will explain the different parts.
For the blog roll specifically we will need to cheange the index.jade to the following:
This is a simple loop in jade to allow for the posts to get listed in .blogMini classed divs and is pretty self explanitory.
If you take a look at the PublicPages class posted above under the pageIndex function we run the same query against the database as we did in the previous post that we used for the admin listing. and apply it to the template (with some minor adjusting of the content for display purposes). Also at the same time we are compiling the short content as a jade template for display purposes.
For each individual post we need a page the user can navigate to and view the post. For this we will be using the same query used in the Admin pages to retrive the post and then parse the content with jade for viewing purposes. See above for the code. The code for the individual page is as follows:
For the RSS feed I am using the RSS template I posted a few months ago here: Jadee template for RSS 2.0
And for this posting I also added the Util.js file to add in date formatting and some URL mangling for use with the post links. (the URL mangling is also used above)
See the PublicPages.js file above to see how I created the items for the RSS template to use.
Including the PublicPages.js file into the project is the same as we have done with teh AdminPages file like so:
Remember to also remove the pages replaced in the StaticPages File
All code created for this website is available on the github page and this tutorial specifically is available here: https://github.com/mikevalstar/mikevalstar_com/tree/Node_Tutorial_pt5
In the next post I plan on adding addition features like archives, paging of the blog roll, tags and perhaps some other items.