aboutsummaryrefslogtreecommitdiff
path: root/routes/admin.js
diff options
context:
space:
mode:
authorBobby <[email protected]>2022-03-21 01:28:56 -0400
committerBobby <[email protected]>2022-03-21 01:28:56 -0400
commit6a43cd05abf6be7d30e405f2e797738ffeaf659a (patch)
tree1d89ba30395fc82e7b41a30610007363af79de26 /routes/admin.js
parentb38eaa1a814769d93b7cd8348804fc1241098189 (diff)
downloadluciferreeves.github.io-6a43cd05abf6be7d30e405f2e797738ffeaf659a.tar.xz
luciferreeves.github.io-6a43cd05abf6be7d30e405f2e797738ffeaf659a.zip
update posts function
Diffstat (limited to 'routes/admin.js')
-rw-r--r--routes/admin.js31
1 files changed, 30 insertions, 1 deletions
diff --git a/routes/admin.js b/routes/admin.js
index b6afab7..260f343 100644
--- a/routes/admin.js
+++ b/routes/admin.js
@@ -1,5 +1,8 @@
const express = require("express");
const router = express.Router();
+const cheerio = require("cheerio");
+const fs = require("fs");
+const firebase = require("../firebase");
router.get("/dashboard", function (req, res) {
res.render("dashboard.html");
@@ -7,7 +10,33 @@ router.get("/dashboard", function (req, res) {
router.get("/dashboard/new", function (req, res) {
res.render("createPost.html");
-})
+});
+
+router.get("/dashboard/edit/:slug", function (req, res) {
+ var html = fs.readFileSync(
+ __dirname + "/../public/views/editPost.html",
+ "utf8"
+ );
+ var $ = cheerio.load(html);
+ const store = firebase.firestore();
+ let query = store.collection("posts");
+ query = query.where("slug", "==", req.params.slug);
+ query
+ .get()
+ .then(function (querySnapshot) {
+ querySnapshot.forEach(function (doc) {
+ $("#title").val(doc.data().title);
+ $("#content").val(Buffer.from(doc.data().content, "base64").toString());
+ $("#tags").val(doc.data().tags);
+ $("#publishDate").val(doc.data().publishDate);
+ });
+ })
+ .then(() => {
+ const publishScript = `<script src="/static/assets/js/pages/publish.js"></script>`;
+ $("body").append(publishScript);
+ res.send($.html());
+ });
+});
router.get("/", (req, res) => {
// Send admin.html from public folder