diff options
Diffstat (limited to 'routes/home.js')
| -rw-r--r-- | routes/home.js | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/routes/home.js b/routes/home.js deleted file mode 100644 index 414e2aa..0000000 --- a/routes/home.js +++ /dev/null @@ -1,50 +0,0 @@ -const express = require("express"); -const router = express.Router(); -const cheerio = require("cheerio"); -const firebase = require("../firebase"); -const fs = require("fs"); - -router.get("/", (req, res) => { - const store = firebase.firestore(); - const posts = []; - let query = store.collection("posts"); - query = query.select("slug", "tags", "title", "shortText", "publishDate"); - query - .get() - .then(function (querySnapshot) { - querySnapshot.forEach(function (doc) { - posts.push(doc.data()); - }); - }) - .then(() => { - var html = fs.readFileSync( - __dirname + "/../public/views/index.html", - "utf8" - ); - var $ = cheerio.load(html); - $("#posts").html(""); - posts.forEach((post, index) => { - $("#posts").append(` - <div class="lead"> - <h2>${post.title}</h2> - <p>${post.shortText}</p> - <p>Published On: ${new Date(post.publishDate).toLocaleString( - undefined, - { - weekday: "long", - year: "numeric", - month: "long", - day: "numeric", - } - )}</p> - <p><a class="btn btn-default" href="/posts/${ - post.slug - }">Read More</a></p> - </div> - `); - }); - res.send($.html()); - }); -}); - -module.exports = router; |
