Skip to content

Commit 9042515

Browse files
committed
add more info page and fix indentation
1 parent 1b0eed1 commit 9042515

File tree

5 files changed

+92
-72
lines changed

5 files changed

+92
-72
lines changed

app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ app.use(indexRoutes)
4848
app.use(blogRoutes)
4949

5050
//-------------LISTEN ON PORT 5000--------------
51-
app.listen(process.env.PORT || 5000, function() {
52-
console.log("server is running at http://localhost:5000")
51+
app.listen(process.env.PORT || 3000, function() {
52+
console.log("server is running at http://localhost:3000")
5353
})

routes/blogs.js

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ router.get("/blogs/new", function(req, res) {
88
})
99

1010
//POST
11-
router.post("/blogs", function(req, res) {
11+
router.post("/blogs", middleware.isLoggedIn, function(req, res) {
12+
console.log(req.body)
1213
var title = req.body.title
1314
var image = req.body.image
1415
var body = req.body.body
@@ -28,18 +29,18 @@ router.post("/blogs", function(req, res) {
2829
});
2930
})
3031

31-
// //SHOW more info about campgrounds
32-
// router.get("/:id", function(req, res) {
33-
// Campground.findById(req.params.id).populate("comments").exec(function(err, foundCmp){
34-
// if(err){
35-
// console.log(err);
36-
// }
37-
// else{
38-
// console.log(foundCmp)
39-
// res.render("campgrounds/show", {campground: foundCmp})
40-
// }
41-
// })
42-
// })
32+
//SHOW more info about campgrounds
33+
router.get("/blog/:id", function(req, res) {
34+
Blog.findById(req.params.id).populate("comments").exec(function(err, foundBlog){
35+
if(err){
36+
console.log(err);
37+
}
38+
else{
39+
console.log(foundBlog)
40+
res.render("blogs/info", {blog: foundBlog})
41+
}
42+
})
43+
})
4344

4445
// //EDIT
4546
// router.get("/:id/edit", middleware.checkCampgroundOwnership, function(req, res){
@@ -63,15 +64,18 @@ router.post("/blogs", function(req, res) {
6364
// })
6465
// })
6566

66-
// //DELETE
67-
// router.delete("/:id", middleware.checkCampgroundOwnership, function(req, res){
68-
// Campground.findByIdAndRemove(req.params.id, function(err){
69-
// if(err){
70-
// res.redirect("/campgrounds")
71-
// } else{
72-
// res.redirect("/campgrounds")
73-
// }
74-
// })
75-
// })
67+
//DELETE
68+
router.delete("/blog/:id", function(req, res){
69+
console.log("routed to delte")
70+
Blog.findByIdAndRemove(req.params.id, function(err){
71+
if(err){
72+
console.log(err)
73+
res.redirect("/")
74+
} else{
75+
console.log("deleted")
76+
res.redirect("/")
77+
}
78+
})
79+
})
7680

7781
module.exports = router

views/blogs/info.ejs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<%- include('../partials/header') %>
2+
<div class="main-content">
3+
<div class="container">
4+
<div class="columns is-centered is-multiline has-text-centered">
5+
<div class="column is-8">
6+
<h3 class="title is-3"><b><a href="/blog/<%= %>" class="has-text-dark"><%=blog.title%></a></b></h3>
7+
<h4 class="title is-4 is-spaced"><%=blog.body%></h4>
8+
<h6 class="subtitle is-6" style="padding-top: 10px;">Posted by <em><%=blog.author.username%></em> on April 7th 2017 at 9:33pm</h6>
9+
<hr/>
10+
</div>
11+
</div>
12+
</div>
13+
</div>
14+
<form action="/blog/<%=blog._id%>?_method=DELETE" method="POST">
15+
<center><button class="button is-danger is-outlined">Delete</button></center>
16+
</form>
17+
<%- include('../partials/footer') %>

views/blogs/new.ejs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<center><h3 class="title is-3" style="padding: 50px;">CREATE A NEW BLOG</h3></center>
33
<form action="/blogs" method="POST" style="margin: auto; width: 40%;">
44
<div class="field">
5-
<input class="input is-info" type="text" name="title" placeholder="Title">
5+
<input class="input is-info" type="text" name="title" placeholder="Title" required>
66
</div>
77
<div class="field">
8-
<input class="input is-info" type="text" name=image" placeholder="Image URL">
9-
</div>
8+
<input class="input is-info" type="text" name="image" placeholder="Image URL">
9+
</div>
1010
<div class="field">
1111
<textarea class="textarea is-info" name="body" placeholder="Body"></textarea>
1212
</div>

views/home.ejs

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -42,48 +42,47 @@ HOMEPAGE COPIED FROM GITHUB-------------
4242
----------------------------------- --->
4343
<div class="header-wrapper">
4444
<section class="hero-top">
45-
<div class="header">
46-
<!-- navigation links -->
47-
<div class="header-nav">
48-
<nav class="nav">
49-
<div class="nav-center">
50-
<a class="nav-item" href="/">
51-
<b>Home</b>
52-
</a>
53-
<%if(!currentUser){%>
54-
<a class="nav-item" id="regbutton">
55-
<b>Sign-Up/Login</b>
56-
</a>
57-
<%} else{%>
58-
<a class="nav-item" href="/blogs/new">
59-
<b>New Blog</b>
60-
</a>
61-
<a class="nav-item" href="/logout">
62-
<b>Sign Out</b>
63-
</a>
64-
<a class="nav-item -end">
65-
<b>Welcome <%=currentUser.username%></b>
66-
</a>
67-
<%}%>
68-
</div>
69-
</nav>
70-
</div>
71-
<!-- end of navigation links -->
72-
73-
<!-- header titles -->
74-
<div class="header-title">
75-
<section class="hero is-medium has-text-centered">
76-
<div class="hero-body">
77-
<div class="container">
78-
<h1 class="title is-1">Ankush Dutt</h1>
79-
<h3 class="subtitle is-3">The Daily Awesome</h3>
80-
</div>
45+
<div class="header">
46+
<!-- navigation links -->
47+
<div class="header-nav">
48+
<nav class="nav">
49+
<div class="nav-center">
50+
<a class="nav-item" href="/">
51+
<b>Home</b>
52+
</a>
53+
<%if(!currentUser){%>
54+
<a class="nav-item" id="regbutton">
55+
<b>Sign-Up/Login</b>
56+
</a>
57+
<%} else{%>
58+
<a class="nav-item" href="/blogs/new">
59+
<b>New Blog</b>
60+
</a>
61+
<a class="nav-item" href="/logout">
62+
<b>Sign Out</b>
63+
</a>
64+
<a class="nav-item -end">
65+
<b>Welcome <%=currentUser.username%></b>
66+
</a>
67+
<%}%>
68+
</div>
69+
</nav>
70+
</div>
71+
<!-- end of navigation links -->
72+
<!-- header titles -->
73+
<div class="header-title">
74+
<section class="hero is-medium has-text-centered">
75+
<div class="hero-body">
76+
<div class="container">
77+
<h1 class="title is-1">Ankush Dutt</h1>
78+
<h3 class="subtitle is-3">The Daily Awesome</h3>
79+
</div>
80+
</div>
81+
</section>
82+
</div>
83+
<!-- end of header titles -->
8184
</div>
8285
</section>
83-
</div>
84-
<!-- end of header titles -->
85-
</div>
86-
</section>
8786
</div>
8887
<!-- end of header -->
8988

@@ -93,16 +92,16 @@ HOMEPAGE COPIED FROM GITHUB-------------
9392
<div class="columns is-centered is-multiline has-text-centered">
9493
<div class="column is-8">
9594
<% blogs.forEach(function(blog) { %>
96-
<h3 class="title is-3"><b><a href="post.html" class="has-text-dark"><%=blog.title%></a></b></h3>
95+
<h3 class="title is-3"><b><a href="/blog/<%=blog._id %>" class="has-text-dark"><%=blog.title%></a></b></h3>
9796
<!-- <h4 class="title is-4 is-spaced"><%=blog.body%></h4> -->
98-
<h6 class="subtitle is-6">Posted by <b><em><%=blog.author.username%></em></b> on April 7th 2017 at 9:33pm</h6>
97+
<h6 class="subtitle is-6" style="padding-top: 10px;">Posted by <b><em><%=blog.author.username%></em></b> on April 7th 2017 at 9:33pm</h6>
9998
<hr/>
10099
<%})%>
101100
<!-- pagingation -->
102-
<nav class="has-text-right">
101+
<!-- <nav class="has-text-right">
103102
<a class="pagination-next" disabled>Newer Posts</a>
104103
<a class="pagination-previous">Older Posts</a>
105-
</nav>
104+
</nav> -->
106105
<!-- end of pagination -->
107106
</div>
108107
</div>

0 commit comments

Comments
 (0)