Skip to content

Commit

Permalink
Made the website with read more anchor tag going to the desired post
Browse files Browse the repository at this point in the history
  • Loading branch information
nitin-jain3 committed Jun 11, 2021
1 parent 0579d14 commit e84976f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
10 changes: 7 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const _ = require("lodash");
const { request } = require("express");

let postArray = [];

Expand Down Expand Up @@ -54,13 +55,16 @@ app.post("/compose", function (req, res) {
});

app.get("/posts/:routeID", function (req, res) {
const lowerCaseID = _.lowerCase(req.params.routeID);
for (i = 0; i < postArray.length; i++) {

for (i = 0; i < postArray.length; i++) {
let lowerCaseID = _.lowerCase(req.params.routeID);
let lowerCaseTitle = _.lowerCase(postArray[i].title);

if (lowerCaseID === lowerCaseTitle) {
console.log("match found");
res.render("post", {
title: postArray[i].title,
des: (postArray[i].content),
})
} else {
console.log("no match");
}
Expand Down
5 changes: 4 additions & 1 deletion views/home.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
<%= post.title %>
</h1>
<p>
<%= post.content %>
<%= post.content.substring(0, 100) + "..." %>
<a href="/posts/<%=post.title%>">Read More</a>
</p>
<% }); %>


Expand Down
16 changes: 16 additions & 0 deletions views/post.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%- include("partials/header" ); -%>

<h1>
<%= title %>
</h1>
<p>
<%= des %>
</p>







<%- include("partials/footer" ); -%>

0 comments on commit e84976f

Please sign in to comment.