Skip to content

Commit 2f071a5

Browse files
small updates
1 parent 5bf6907 commit 2f071a5

8 files changed

+1006
-47
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# Auto detect text files and perform LF normalization
22
* text=auto
3+
pack.sh=LF

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ dist
121121

122122
# CynthiaConfig
123123
/.env
124-
/pack.sh
125124
/reset.sh
126125
/GETTINGSTARTED.MD
127126
/cynthia_config

clean-cyn.tar.gz

-126 Bytes
Binary file not shown.

clean_slate/pack.sh

-3
This file was deleted.

main.js

+36-34
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ const tslog = require("tslog");
1010
const connsola = new tslog.Logger();
1111
const MarkdownIt = require("markdown-it");
1212
const { raw } = require("body-parser");
13-
const md = new MarkdownIt();
13+
const md = new MarkdownIt({
14+
html: true,
15+
linkify: true,
16+
typographer: true,
17+
});
1418
const Axios = require("axios");
1519
const pjson = require("./package.json");
1620
class logging {
@@ -163,6 +167,10 @@ async function ReturnPage(id, currenturl) {
163167
case "external":
164168
rawpagecontent = (await Axios.default.get(pagemeta.content.url).then()).data;
165169
break;
170+
case "external-direct":
171+
return (await Axios.default.get(pagemeta.content.url).then()).data;
172+
case "redirect":
173+
return ({ do: "relocation", url: pagemeta.content.url });
166174
default:
167175
rawpagecontent = fs.readFileSync(
168176
path.join(__dirname, "/site/pages/", pagemeta.content.path),
@@ -243,7 +251,30 @@ Also see: https://github.com/strawmelonjuice/CynthiaCMS-JS/blob/main/README.MD
243251
// console.log(page);
244252
return page;
245253
}
246-
254+
async function CynthiaRespond(id,req,res) {
255+
let anyerrors = true;
256+
try {
257+
const cynspon = await ReturnPage(id, req.url);
258+
if (typeof cynspon !== "object") {
259+
res.send(cynspon);
260+
anyerrors = false;
261+
} else {
262+
if (cynspon.do === "relocation") {
263+
res.redirect(302, cynspon.url);
264+
console.log(`Redirecting '${req.url}' to '${cynspon.url}'.`);
265+
anyerrors = false;
266+
}
267+
}
268+
} catch {
269+
anyerrors = true;
270+
}
271+
if (anyerrors) {
272+
tell.log(0, "500", `[GET] ➡️❌ "${req.url}"`);
273+
res.send(500);
274+
} else {
275+
tell.log(0, "200", `[GET] ➡️✔️ "${req.url}"`);
276+
}
277+
}
247278
const app = express();
248279
app.get("/", async (req, res) => {
249280
let pid = "";
@@ -253,44 +284,15 @@ app.get("/", async (req, res) => {
253284
if (typeof req.query.post !== "undefined") pid = req.query.post;
254285
if (typeof req.query.id !== "undefined") pid = req.query.id;
255286
if (pid !== "") {
256-
try {
257-
res.send(await ReturnPage(pid, req.url));
258-
} catch {
259-
anyerrors = true;
260-
}
261-
if (anyerrors) {
262-
tell.warn(`[GET] ➡️❌ "${req.url} ~ ${pid}"`);
263-
} else {
264-
tell.log(0, "OK", `[GET] ➡️✔️ "${req.url} ~ ${pid}"`);
265-
}
287+
CynthiaRespond(pid,req,res);
266288
} else {
267-
try {
268-
res.send(await ReturnPage("root", "/"));
269-
} catch {
270-
anyerrors = true;
271-
}
272-
if (anyerrors) {
273-
tell.warn(`[GET] ➡️❌ "${req.url}"`);
274-
} else {
275-
tell.log(0, "OK", `[GET] ➡️✔️ "${req.url}"`);
276-
}
289+
CynthiaRespond("root", req, res);
277290
}
278291
});
279292

280293
app.get("/p/:id", async (req, res) => {
281-
let anyerrors = false;
282294
const id = req.params.id;
283-
try {
284-
res.send(await ReturnPage(id, `/p/${id}`));
285-
anyerrors = false;
286-
} catch {
287-
anyerrors = true;
288-
}
289-
if (anyerrors) {
290-
tell.warn(`[GET] ➡️❌ "${req.url}"`);
291-
} else {
292-
tell.log(0, "OK", `[GET] ➡️✔️ "${req.url}"`);
293-
}
295+
CynthiaRespond(id, req, res);
294296
});
295297
app.use("/assets", express.static(path.join(__dirname, "/site/assets/")));
296298
app.use(

pack.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
echo "Packing to 'clean-cyn.tar.gz'..."
3+
ls -A ./clean_slate/
4+
tar -czf ./clean-cyn.tar.gz ./clean_slate/* ./clean_slate/.env

0 commit comments

Comments
 (0)