Welcome to the launch of my blog! There are many like it, but this one is mine.
I'm honestly not sure what I'm going to write about. The reason I built this was to expand my web development skills and this seemed like an attainable goal. Now that things are working it seemed like a good time to take it live. Since the blog itself is what I'm currently working on I'm going to get a bit meta and blog about the challenges of creating this blog.
One thing that was required to make the comment system work was to establish a one-to-many relationship in the database between the blogs themselves & all the thousands of comments that I'm sure to get. The blog contents are stored in one table & all of the comments are stored in a separate table with an index value to link the data accordingly.
Where this got interesting was when the data had to be rendered for the user (that's you!). This page uses Node.js & Express to handle the page routing & Handlebars to render the pages. What this means is that this page, as you see it, doesn't actually exist anywhere. The address being called is processed by Node/Express, then the database is queried & the correct data is packaged and sent to Handlebars to render the page.
Handlebars.js, the template rendering engine, expects a single data object which it parses to create the page contents. But I have two data objects. First, the blog Content (images, text, author, date etc). Additionally, I have the blog comments. To make this work the way that I want I need to merge this data into a single object to pass to Handlebars for rendering.
This is handled in the route_controller.js file (which you can see on Github). First, I process the blog post being requested & get that data from the database. This is JSON formatted data which will be passed to Handlebars but before I do that I need to check for comments. So, I take the index ID which corresponds to the requested blog and do an additional query in the comments table to look for the index ID (which is now a foreign key) and gather all of the relevant comments. Any comments that are found are then appended to the original JSON object. This combined file is finally passed to Handlebars to be rendered.
So that's how we ended up here. If you have any questions or comments please feel free to leave me a note. I'm not requiring a login to post (and I won't go that route unless I start getting bombarded by spam) so it should be pretty painless. Thanks for reading.