From a60edb74d6304a925cf226f4a4970f10d1e3734b Mon Sep 17 00:00:00 2001 From: w3project Date: Fri, 21 Jul 2023 19:47:30 +0530 Subject: [PATCH] Blog Posting Done --- models/blog.js | 5 +-- public/css/home.css | 7 ++++ public/css/myBlogs.css | 7 ++++ routes/slash-home.js | 7 ++-- routes/slash-post.js | 6 ++-- views/home.ejs | 75 ++++++++++++++++++++++++++++++++++++++++++ views/home.html | 2 ++ views/myBlogs.html | 2 ++ 8 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 views/home.ejs diff --git a/models/blog.js b/models/blog.js index 7f8cc0e..8c7129f 100644 --- a/models/blog.js +++ b/models/blog.js @@ -3,8 +3,9 @@ var currBlog = []; module.exports = class newBlog { - constructor(title, content) + constructor(user, title, content) { + this.user = user; this.title = title; this.content = content; this.id = Math.random().toString(); @@ -12,7 +13,7 @@ module.exports = class newBlog save() { - const tmp = {TITLE:this.title, CONTENT:this.content, ID:this.id}; + const tmp = {USER:this.user, TITLE:this.title, CONTENT:this.content, ID:this.id}; arr.push(tmp); currBlog = []; currBlog.push(tmp); diff --git a/public/css/home.css b/public/css/home.css index 342eff0..85bc807 100644 --- a/public/css/home.css +++ b/public/css/home.css @@ -261,6 +261,13 @@ body background-color: rgb(107, 34, 176); } +.null +{ + font:17px helvetica-reg; + color:rgba(0, 0, 0, 0.4); + margin:30px auto 0px auto; +} + @media screen and (min-width:800px) { .topbar diff --git a/public/css/myBlogs.css b/public/css/myBlogs.css index 342eff0..85bc807 100644 --- a/public/css/myBlogs.css +++ b/public/css/myBlogs.css @@ -261,6 +261,13 @@ body background-color: rgb(107, 34, 176); } +.null +{ + font:17px helvetica-reg; + color:rgba(0, 0, 0, 0.4); + margin:30px auto 0px auto; +} + @media screen and (min-width:800px) { .topbar diff --git a/routes/slash-home.js b/routes/slash-home.js index 22fdf93..a03affd 100644 --- a/routes/slash-home.js +++ b/routes/slash-home.js @@ -1,9 +1,12 @@ const exp = require('express'); +const newBlog = require('../models/blog'); const route = exp.Router(); -const path = require('path'); route.get('/home', (req,res) => { - res.sendFile(path.join(__dirname, '../', 'views', 'home.html')); + const arr = newBlog.getAllBLogs(); + const data ={arr:arr}; + + res.render('home', data); }) module.exports = route; \ No newline at end of file diff --git a/routes/slash-post.js b/routes/slash-post.js index 3012c5f..99c3b82 100644 --- a/routes/slash-post.js +++ b/routes/slash-post.js @@ -9,13 +9,13 @@ route.get('/post', (req,res) => { }) route.post('/post', (req,res) => { - const obj = new newBlog(req.body.TITLE, req.body.BLOG); + const currProfile = addProfile.getCurrentUser(); + + const obj = new newBlog(currProfile[0].USERNAME, req.body.TITLE, req.body.BLOG); obj.save(); const latestBlog = newBlog.getLastBlog(); - const currProfile = addProfile.getCurrentUser(); - addProfile.saveBlog(latestBlog[0].ID, currProfile[0].USERNAME); res.redirect('/home'); }) diff --git a/views/home.ejs b/views/home.ejs new file mode 100644 index 0000000..0e7286b --- /dev/null +++ b/views/home.ejs @@ -0,0 +1,75 @@ + + + + BlogBase | Home + + + + + + +
+ logo +

BlogBase

+ + + +
+ +
+ logo +

BlogBase

+
+
+
+
+
+
+ + + +

LATEST BLOGS

+ + <% if(arr.length==0){ %> +

No Latest Blogs Posted :(

+ <% } else{ %> + <% for(let i=0; i +
+
+ + + +
+

<%= arr[i].USER %>

+

<%= arr[i].TITLE %>

+
+
+

<%= arr[i].CONTENT %>

+ + +
+ <% } %> + <% } %> + + + + + + + + + + \ No newline at end of file diff --git a/views/home.html b/views/home.html index d5d523e..3cae023 100644 --- a/views/home.html +++ b/views/home.html @@ -38,6 +38,8 @@

LATEST BLOGS

+

No Latest Blogs Posted :(

+
diff --git a/views/myBlogs.html b/views/myBlogs.html index c23b64a..bd8da04 100644 --- a/views/myBlogs.html +++ b/views/myBlogs.html @@ -38,6 +38,8 @@

MY BLOGS

+

No Blogs Posted By You! :(

+