From 0223e8acd61544b1485fecd3a18829e53dd5ff32 Mon Sep 17 00:00:00 2001 From: Aman Yadav <97724135+Its-Aman-Yadav@users.noreply.github.com> Date: Tue, 13 Jun 2023 14:16:00 +0530 Subject: [PATCH] Add files via upload --- projects/app.js | 80 ++++++++++++++++++++++++++++++ projects/package.json | 18 +++++++ projects/public/css/styles.css | 44 ++++++++++++++++ projects/views/about.ejs | 4 ++ projects/views/compose.ejs | 14 ++++++ projects/views/contact.ejs | 4 ++ projects/views/home.ejs | 20 ++++++++ projects/views/partials/footer.ejs | 9 ++++ projects/views/partials/header.ejs | 26 ++++++++++ projects/views/post.ejs | 10 ++++ projects/views/test.ejs | 15 ++++++ 11 files changed, 244 insertions(+) create mode 100644 projects/app.js create mode 100644 projects/package.json create mode 100644 projects/public/css/styles.css create mode 100644 projects/views/about.ejs create mode 100644 projects/views/compose.ejs create mode 100644 projects/views/contact.ejs create mode 100644 projects/views/home.ejs create mode 100644 projects/views/partials/footer.ejs create mode 100644 projects/views/partials/header.ejs create mode 100644 projects/views/post.ejs create mode 100644 projects/views/test.ejs diff --git a/projects/app.js b/projects/app.js new file mode 100644 index 00000000..991e71ac --- /dev/null +++ b/projects/app.js @@ -0,0 +1,80 @@ +const express = require("express"); +const bodyParser = require("body-parser"); +const ejs = require("ejs"); +const mongoose = require('mongoose'); + +const homeStartingContent = "Hey, this website is created by Aman Yadav, if you want to write somthing, click on the upper right corner i.e write button and start writing"; + +const aboutContent = "This web app is created by the use of HTML, CSS, JS, ExpressJS, EJS, Loodash"; + +const contactContent = "Mail to: itsamanyadav18@gmail.com"; + +const app = express(); + +app.set('view engine', 'ejs'); + +app.use(bodyParser.urlencoded({extended: true})); +app.use(express.static("public")); + +mongoose.connect("mongodb://localhost:27017/blogDB", {useNewUrlParser: true}); + +const postSchema = { + title: String, + content: String +}; + +const Post = mongoose.model("Post", postSchema); + +app.get("/", function(req, res){ + + Post.find({}, function(err, posts){ + res.render("home", { + startingContent: homeStartingContent, + posts: posts + }); + }); +}); + +app.get("/compose", function(req, res){ + res.render("compose"); +}); + +app.post("/compose", function(req, res){ + const post = new Post({ + title: req.body.postTitle, + content: req.body.postBody + }); + + + post.save(function(err){ + if (!err){ + res.redirect("/"); + } + }); +}); + +app.get("/posts/:postId", function(req, res){ + +const requestedPostId = req.params.postId; + + Post.findOne({_id: requestedPostId}, function(err, post){ + res.render("post", { + title: post.title, + content: post.content + }); + }); + +}); + +app.get("/about", function(req, res){ + res.render("about", {aboutContent: aboutContent}); +}); + +app.get("/contact", function(req, res){ + res.render("contact", {contactContent: contactContent}); +}); + + +app.listen(3000, function() { + console.log("Server started on port 3000"); +}); diff --git a/projects/package.json b/projects/package.json new file mode 100644 index 00000000..2f673b89 --- /dev/null +++ b/projects/package.json @@ -0,0 +1,18 @@ +{ + "name": "ejs-challenge", + "version": "1.0.0", + "description": "", + "main": "app.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "body-parser": "^1.18.3", + "ejs": "^3.1.9", + "express": "^4.16.3", + "lodash": "^4.17.11", + "mongoose": "^5.3.6" + } +} diff --git a/projects/public/css/styles.css b/projects/public/css/styles.css new file mode 100644 index 00000000..8d9fb612 --- /dev/null +++ b/projects/public/css/styles.css @@ -0,0 +1,44 @@ +html { + min-height: 100%; + position: relative; +} + +.container-fluid { + padding-top: 70px; + padding-bottom: 70px; +} +.navbar { + padding-top: 15px; + padding-bottom: 15px; + border: 0; + border-radius: 0; + margin-bottom: 0; + font-size: 12px; + letter-spacing: 5px; +} +.navbar-nav li a:hover { + color: #1abc9c !important; +} + +.footer-padding { + padding-bottom: 60px; +} + +.footer { + position: absolute; + text-align: center; + bottom: 0; + width: 100%; + height: 60px; + background-color: #1abc9c; +} + +.footer p { + margin-top: 25px; + font-size: 12px; + color: #fff; +} + +.name{ + color: white; +} \ No newline at end of file diff --git a/projects/views/about.ejs b/projects/views/about.ejs new file mode 100644 index 00000000..6cb31869 --- /dev/null +++ b/projects/views/about.ejs @@ -0,0 +1,4 @@ +<%- include("partials/header"); -%> +

About

+

<%= aboutContent %>

+<%- include("partials/footer"); -%> diff --git a/projects/views/compose.ejs b/projects/views/compose.ejs new file mode 100644 index 00000000..f2e2cd8d --- /dev/null +++ b/projects/views/compose.ejs @@ -0,0 +1,14 @@ + +<%- include("partials/header"); -%> +

Compose

+
+
+ + + + +
+ +
+ +<%- include("partials/footer"); -%> diff --git a/projects/views/contact.ejs b/projects/views/contact.ejs new file mode 100644 index 00000000..f8d33ef7 --- /dev/null +++ b/projects/views/contact.ejs @@ -0,0 +1,4 @@ +<%- include("partials/header"); -%> +

Contact

+

<%= contactContent %>

+<%- include("partials/footer"); -%> diff --git a/projects/views/home.ejs b/projects/views/home.ejs new file mode 100644 index 00000000..a0319d3a --- /dev/null +++ b/projects/views/home.ejs @@ -0,0 +1,20 @@ + +<%- include("partials/header"); -%> + +

Home

+

<%= startingContent %>

+ + + <% posts.forEach(function(post){ %> + +

<%=post.title%>

+

+ <%=post.content.substring(0, 100) + " ..."%> + Read More +

+ + + <% }) %> + + +<%- include("partials/footer"); -%> diff --git a/projects/views/partials/footer.ejs b/projects/views/partials/footer.ejs new file mode 100644 index 00000000..3d72d3ac --- /dev/null +++ b/projects/views/partials/footer.ejs @@ -0,0 +1,9 @@ + + + + + + + diff --git a/projects/views/partials/header.ejs b/projects/views/partials/header.ejs new file mode 100644 index 00000000..4d2a884e --- /dev/null +++ b/projects/views/partials/header.ejs @@ -0,0 +1,26 @@ + + + + + + Daily Journal + + + + + + +
diff --git a/projects/views/post.ejs b/projects/views/post.ejs new file mode 100644 index 00000000..aae04b21 --- /dev/null +++ b/projects/views/post.ejs @@ -0,0 +1,10 @@ + +<%- include("partials/header"); -%> + + +

<%=title%>

+

<%=content%>

+ + + +<%- include("partials/footer"); -%> diff --git a/projects/views/test.ejs b/projects/views/test.ejs new file mode 100644 index 00000000..0fe972d3 --- /dev/null +++ b/projects/views/test.ejs @@ -0,0 +1,15 @@ +<%- include("partials/header"); -%> +

Home

+

<%= startingContent %>

+ + + <% posts.forEach(function(post){ %> + +

<%=post.title%>

+

+ <%=post.content.substring(0, 100) + " ..."%> + Read More +

+ + + <% }) %>