Преглед на файлове

Remove all of the code from "writing" that isn't being used anymore.

Lee Morgan преди 4 години
родител
ревизия
23923587fd
променени са 5 файла, в които са добавени 16 реда и са изтрити 205 реда
  1. 2 0
      app.js
  2. 11 0
      middleware.js
  3. 3 8
      routes.js
  4. 0 123
      views/writing/index.css
  5. 0 74
      views/writing/index.js

+ 2 - 0
app.js

@@ -6,6 +6,8 @@ const fs = require("fs");
 const bodyParser = require("body-parser");
 const fileUpload = require("express-fileupload");
 
+const Visitor = require("./models/visitor.js");
+
 const app = express();
 
 let mongooseOptions = {

+ 11 - 0
middleware.js

@@ -0,0 +1,11 @@
+module.exports = {
+    visit: function(req, res, next){
+        new Visitor({
+            time: new Date(),
+            route: req.baseUrl,
+            ip: req.ip,
+            method: req.method
+        }).save().catch((err)=>{console.error(err)});
+        next();
+    }
+}    

+ 3 - 8
routes.js

@@ -3,20 +3,15 @@ const gallery = require("./controllers/gallery.js");
 const learn = require("./controllers/learn.js");
 const blog = require("./controllers/blog.js");
 
+const visit = require("./middleware.js").visit;
+
 module.exports = function(app){
     let views = `${__dirname}/views`;
 
     //MAIN
-    app.get("/", (req, res)=>{res.sendFile(`${views}/main/index.html`)});
+    app.get("/", visit, (req, res)=>{res.sendFile(`${views}/main/index.html`)});
     app.get("/style", (req, res)=>{res.sendFile(`${views}/main/index.css`)});
 
-    //WRITING
-    app.get("/writing/style", (req, res)=>{res.sendFile(`${views}/writing/index.css`)});
-    app.get("/writing/code", (req, res)=>{res.sendFile(`${views}/writing/index.js`)});
-    app.get("/writing/comments/:article", writing.getComments);
-    app.post("/writing/comments", writing.createComment);
-    app.get("/writing/directories", writing.listDirectories);
-
     //BLOG
     app.get("/blog/style", (req, res)=>{res.sendFile(`${views}/blog/index.css`)});
     app.get("/blog/new", (req, res)=>{res.sendFile(`${views}/blog/new.html`)});

+ 0 - 123
views/writing/index.css

@@ -1,123 +0,0 @@
-*{margin:0;padding:0;}
-
-body{
-    font-family: monospace;
-    background: #152730;
-    box-sizing: border-box;
-    padding: 25px;
-}
-
-h1{
-    text-align: center;
-    margin-bottom: 15px;
-    font-size: 50px;
-}
-
-.metaData{
-    text-align: center;
-    margin-bottom: 15px;
-}
-
-.article{
-    background: #C4C6C0;
-    width: 75vw;
-    box-sizing: border-box;
-    padding: 50px;
-    margin: auto;
-    margin-bottom: 50px;
-}
-
-.paragraph{
-    text-indent: 50px;
-    margin-bottom: 22px;
-    text-align: justify;
-    font-size: 22px;
-    line-height: 1.8;
-}
-
-#createComment{
-    display: flex;
-    flex-direction: column;
-    align-items: center;
-    width: 75vw;
-    background: #C4C6C0;
-    box-sizing: border-box;
-    margin: auto;
-    padding: 25px;
-    margin-bottom: 50px;
-}
-
-    #createComment > *{
-        margin: 10px;
-    }
-
-    #createComment label{
-        display: flex;
-        flex-direction: column;
-        width: 60%;
-    }
-
-    #nameInput{
-        font-size: 16px;
-    }
-
-    #commentInput{
-        font-size: 16px;
-    }
-
-    input[type=submit]{
-        border: none;
-        background: black;
-        color: white;
-        padding: 10px;
-        cursor: pointer;
-        font-size: 20px;
-        box-shadow: 0 0 5px black;
-    }
-
-    input[type=submit]:hover{
-        background: white;
-        color: black;
-    }
-
-    input[type=submit]:active{
-        box-shadow: none;
-    }
-
-#comments{
-    display: flex;
-    flex-direction: column;
-    align-items: center;
-    width: 75vw;
-    background: #C4C6C0;
-    box-sizing: border-box;
-    margin: auto;
-    padding-bottom: 25px;
-}
-
-    #comments > *{
-        margin: 10px;
-    }
-
-    .comment{
-        display: flex;
-        flex-direction: column;
-        width: 75%;
-        background: white;
-        padding: 25px;
-    }
-
-        .comment h3{
-            font-size: 16px;
-        }
-
-        .comment > div{
-            display: flex;
-            justify-content: space-between;
-            align-items: center;
-            margin-bottom: 15px;
-        }
-
-        .comment > p{
-            font-size: 16px;
-        }

+ 0 - 74
views/writing/index.js

@@ -1,74 +0,0 @@
-fetch("/writing/comments/touchscreens")
-    .then(response => response.json())
-    .then((response)=>{
-        if(typeof(response) === "string"){
-            console.log(response);
-        }else{
-            let comments = document.getElementById("comments");
-            let template = document.getElementById("comment").content.children[0];
-
-            let dateOptions = {
-                month: "long",
-                day: "numeric",
-                year: "numeric",
-                hour: "2-digit",
-                minute: "2-digit"
-            };
-
-            for(let i = 0; i < response.length; i++){
-                let comment = template.cloneNode(true);
-                comment.children[0].children[0].innerText = response[i].name;
-                comment.children[0].children[1].innerText = new Date(response[i].date).toLocaleString("en-US", dateOptions);
-                comment.children[1].innerText = response[i].content;
-                comments.appendChild(comment);
-            }
-        }
-    })
-    .catch((err)=>{});
-
-    createComment = ()=>{
-        event.preventDefault();
-
-        let data = {
-            article: document.getElementById("articleInput").getAttribute("article"),
-            name: document.getElementById("nameInput").value,
-            content: document.getElementById("commentInput").value,
-            date: new Date()
-        };
-
-        fetch("/writing/comments", {
-            method: "post",
-            headers: {
-                "Content-Type": "application/json;charset=utf-8"
-            },
-            body: JSON.stringify(data)
-        })
-            .then(response => response.json())
-            .then((response)=>{
-                if(typeof(response) === "string"){
-                    console.log(response);
-                }else{
-                    
-                    let comments = document.getElementById("comments");
-                    let comment = document.getElementById("comment").content.children[0].cloneNode(true);
-
-                    let dateOptions = {
-                        month: "long",
-                        day: "numeric",
-                        year: "numeric",
-                        hour: "2-digit",
-                        minute: "2-digit"
-                    };
-
-                    comment.children[0].children[0].innerText = response.name;
-                    comment.children[0].children[1].innerText = new Date(response.date).toLocaleString("en-US", dateOptions);
-                    comment.children[1].innerText = response.content;
-                    comments.insertBefore(comment, comments.children[1]);
-                }
-            })
-            .catch((err)=>{
-                console.log(err);
-            });
-    }
-
-document.getElementById("createComment").onsubmit = ()=>{createComment()};