Procházet zdrojové kódy

Add html to display page with pictures.

Lee Morgan před 5 roky
rodič
revize
27384bfa88
4 změnil soubory, kde provedl 26 přidání a 9 odebrání
  1. 6 5
      routes.js
  2. 8 2
      travel.js
  3. 2 2
      views/main/index.html
  4. 10 0
      views/travel/index.html

+ 6 - 5
routes.js

@@ -1,5 +1,5 @@
 const controller = require("./controller.js");
-const images = require("./images.js");
+const travel = require("./travel.js");
 
 module.exports = function(app){
     let views = `${__dirname}/views`;
@@ -7,14 +7,12 @@ module.exports = function(app){
     //MAIN
     app.get("/", (req, res)=>{res.sendFile(`${views}/main/index.html`)});
     app.get("/style", (req, res)=>{res.sendFile(`${views}/main/index.css`)});
-    app.get("/getimages", images.listDirectories);
 
     //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", controller.getComments);
     app.post("/writing/comments", controller.createComment);
-
     app.get("/writing/touchscreens", (req, res)=>{res.sendFile(`${views}/writing/touchscreens.html`)});
 
     //IMAGES
@@ -25,8 +23,6 @@ module.exports = function(app){
     app.get("/images/birthday", (req, res)=>{res.sendFile(`${views}/images/birthday.jpg`)});
     app.get("/images/market", (req, res)=>{res.sendFile(`${views}/images/market.jpeg`)});
 
-    app.get("/video/plane", (req, res)=>{res.sendFile(`${views}/videos/planeEdit.mp4`)});
-
     //SUDOKU
     app.get("/sudoku", (req, res)=>{res.sendFile(`${views}/sudoku/index.html`)});
     app.get("/sudoku/style", (req, res)=>{res.sendFile(`${views}/sudoku/index.css`)});
@@ -36,4 +32,9 @@ module.exports = function(app){
     app.get("/birthdayparadox", (req, res)=>{res.sendFile(`${views}/birthdayParadox/index.html`)});
     app.get("/birthdayparadox/style", (req, res)=>{res.sendFile(`${views}/birthdayParadox/index.css`)});
     app.get("/birthdayparadox/code", (req, res)=>{res.sendFile(`${views}/birthdayParadox/index.js`)});
+
+    //TRAVEL
+    app.get("/travel/directories", travel.listDirectories);
+    app.get("/travel/images/*", travel.getImages);
+    app.get("/travel/*", (req, res)=>res.sendFile(`${views}/travel/index.html`));
 }

+ 8 - 2
images.js → travel.js

@@ -29,7 +29,13 @@ module.exports = {
         return res.json(result.contents[0].contents);
     },
 
-    imagesHtml: function(){
-        
+    getImages: function(req, res){
+        let path = req.originalUrl
+            .split("/")
+            .slice(2)
+            .join("/");
+
+        let pictures = fs.readdirSync(`${__dirname}/content/${path}`);
+        console.log(pictures);
     }
 }

+ 2 - 2
views/main/index.html

@@ -170,7 +170,7 @@
                 };
             }
 
-            fetch("/getimages")
+            fetch("/travel/directories")
                 .then(response => response.json())
                 .then((response)=>{
                     let travel = document.getElementById("travel");
@@ -180,7 +180,7 @@
                             let card = {};
                             if(currentArray[i].contents.length === 0) {
                                 card = document.createElement("a");
-                                card.href = currentArray[i].path;
+                                card.href = `/travel${currentArray[i].path}`;
                             }else{
                                 card = document.createElement("div");
                                 card.onclick = ()=>{

+ 10 - 0
views/travel/index.html

@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html lang="en">
+    <head>
+        <meta charset="utf-8">
+        <title>Lee Morgan</title>
+    </head>
+    <body>
+        <h1>Well Done</h1>
+    </body>
+</html>