Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32b277b
commit 56b46eb
Showing
11 changed files
with
272 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,3 +1,7 @@ | |||
h2 Admin | h2 Admin | ||
|
|
||
h3 You are logged in | h3 You are logged in | ||
|
|||
ul | |||
li | |||
a(href="/Admin/PostList") Blog Posts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,21 @@ | |||
h2 Edit Post | |||
span.postid= post.id | |||
|
|||
form(method="post", action="/Admin/Post") | |||
input(type="hidden", name="id", value=post.id) | |||
h3 ID | |||
input(type="text", name="sid", value=post.sid) | |||
h3 Title | |||
input(type="text", name="title", style="width: 100%;", value=post.title) | |||
h4 Image Large | |||
input(type="text", name="img_lg", style="width: 50%;", value=post.img_lg) | |||
h4 Image Small | |||
input(type="text", name="img_sm", style="width: 50%;", value=post.img_sm) | |||
h3 Content | |||
textarea(name="short", style="width: 100%; height: 5em;")= post.short | |||
textarea(name="content", style="width: 100%; height: 20em;")= post.content | |||
span.i All content is in jade format | |||
h4 Link to external content | |||
input(type="text", name="ext_link", style="width: 100%;", value=post.ext_link) | |||
br | |||
input(type="submit", value="Save") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,24 @@ | |||
h2 Admin - Post Listing | |||
|
|||
table.aPostList | |||
thead | |||
tr | |||
th Post ID | |||
th Title | |||
th Int/Ext | |||
th Posted | |||
tbody | |||
- posts.forEach(function(item){ | |||
tr | |||
td= item.sid | |||
td: a(href="/Admin/Post/" + item.sid)= item.title | |||
td | |||
- if(item.ext_link != ""){ | |||
| External | |||
- }else{ | |||
| Internal | |||
- } | |||
td: time= item.posted | |||
- }) | |||
|
|||
a(href="/Admin/NewPost") Create a new post |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,43 @@ | |||
# Coding with Node.js: Part 4; Storing blog posts | |||
|
|||
_See [Coding with Node.js: Part 1; Getting started with Express.](/Blog/103/Coding_with_Node.js_Part_1_Getting_started_with_Express) for the beginning of this tutorial series._ | |||
|
|||
With the admin login page completed we now need a list of blog entries and a way to create and edit them. So to start lets give ourselves an admin interface for blog posts that we can later integrate into the main website. | |||
|
|||
## Structuring the posts | |||
For the blog posts i'm going with the below structure for the posts to fit my blog. One key column I'm adding in is the external link, this will be very useful for determining posts that are not full articles like this one but comments on something else that I would like to link to. | |||
|
|||
So lets first add the structure to the database | |||
#### Database.js | |||
|
|||
## Listing your posts | |||
Now that we have our database structure setup we'll need to setup a page to display all of the current posts and provide a link to create a new one. | |||
|
|||
#### AdminPages.js | |||
|
|||
#### postlist.jade | |||
|
|||
## Editing Post | |||
The first step we need to add is creating the post. Because we want to keep an id for our posts that is short and numeric we're using the sid column to link to posts; and we need to find the maximum for the column before we start a page as seen below. | |||
|
|||
Also we need to check for when a user posts back the data in the form and apply that to the database. | |||
|
|||
#### AdminPages.js | |||
|
|||
#### post.jade | |||
|
|||
Also note above that we set the post id to 1 when no maximum post id can be found. | |||
|
|||
## Deficiencies | |||
* No error checking - because this is a simple uxorial.. and I'll be the only one using the software I have put 0 error checking into this demo. if you plan on making anything like this public make sure to add in some error checking. | |||
* Post ID Collision - I do not currently detect a duplicate post id, this would be a good idea to add and i may do so later. | |||
* Look & Feel - I have made the interface very spartan for now for this demo but once again plan on making this better in the future. | |||
|
|||
## Final Thoughts | |||
With the ability to add/edit blog posts we can now start translating all the posts into the database and be ready to switch over to a db driven blog listing. | |||
|
|||
## The Code | |||
All code created for this website is available on the [github page](https://github.com/mikevalstar/mikevalstar_com) and this tutorial specifically is available here: [https://github.com/mikevalstar/mikevalstar\_com/tree/Node\_Tutorial\_pt4](https://github.com/mikevalstar/mikevalstar_com/tree/Node_Tutorial_pt4) | |||
|
|||
## Next Time | |||
In the next part of this series we can show these blog posts on the front page. And later an RSS feed. |