From 1b8e05ad1f142ef4dd47a93cd047f604d17134b0 Mon Sep 17 00:00:00 2001 From: Raj Nandan Sharma Date: Fri, 15 Nov 2024 22:52:36 +0530 Subject: [PATCH] feat: added sitemap again, fixed #59 also --- Dockerfile | 1 + build.js | 2 +- config/site.example.yaml | 1 + docs/customize-site.md | 8 +++++++ docs/home.md | 8 +++++-- main.js | 14 +++++++++++++ sitemap.js | 45 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 sitemap.js diff --git a/Dockerfile b/Dockerfile index 5d0a5c2..ef4e950 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,6 +44,7 @@ COPY --from=base /usr/local/lib /usr/local/lib COPY --chown=abc:abc static /app/static COPY --chown=abc:abc database /app/database COPY --chown=abc:abc build.js /app/build.js +COPY --chown=abc:abc sitemap.js /app/sitemap.js COPY --chown=abc:abc src/lib/server /app/src/lib/server COPY --chown=abc:abc src/lib/helpers.js /app/src/lib/helpers.js diff --git a/build.js b/build.js index d2a6bbd..38e1600 100644 --- a/build.js +++ b/build.js @@ -249,7 +249,7 @@ async function Build() { } if (site.github.incidentSince === undefined || site.github.incidentSince === null) { - site.github.incidentSince = 48; + site.github.incidentSince = 720; } if (!!site.analytics) { const providers = {}; diff --git a/config/site.example.yaml b/config/site.example.yaml index 74d61bd..fe5e0a6 100644 --- a/config/site.example.yaml +++ b/config/site.example.yaml @@ -2,6 +2,7 @@ title: "Kener - Open-Source and Modern looking Node.js Status Page for Effortles siteName: "Kener.ing" home: "/" logo: "/logo.png" +siteURL: "https://kener.ing" favicon: "/logo96.png" github: owner: "rajnandan1" diff --git a/docs/customize-site.md b/docs/customize-site.md index 9f8e603..cce1305 100644 --- a/docs/customize-site.md +++ b/docs/customize-site.md @@ -327,3 +327,11 @@ analytics: - id: "FKOdsKener" type: "MIXPANEL" ``` + +## siteURL + +This is required for sitemap generation + +```yaml +siteURL: https://kener.ing +``` diff --git a/docs/home.md b/docs/home.md index 80da70f..a157a04 100644 --- a/docs/home.md +++ b/docs/home.md @@ -26,9 +26,13 @@ description: Kener is an open-source Node.js status page tool, designed to make #### 👉 Quick Start [here](/docs/quick-start) -Kener: Open-source Node.js status page tool, designed to make service monitoring and incident handling a breeze. It offers a sleek and user-friendly interface that simplifies tracking service outages and improves how we communicate during incidents. And the best part? Kener integrates seamlessly with GitHub, making incident management a team effort—making it easier for us to track and fix issues together in a collaborative and friendly environment. +## What is Kener? -It uses files to store the data. Other adapters are coming soon +Kener: Open-source sveltekit status page tool, designed to make service monitoring and incident handling a breeze. It offers a sleek and user-friendly interface that simplifies tracking service outages and improves how we communicate during incidents. Kener integrates seamlessly with GitHub, making incident management a team effort—making. + +It uses files to store the data. + +Kener name is derived from the word "Kene" which means "how is it going" in Assamese, then .ing is added to make cooler. ## Features diff --git a/main.js b/main.js index b7834bf..c90e4e6 100644 --- a/main.js +++ b/main.js @@ -2,9 +2,23 @@ import { handler } from "./build/handler.js"; import dotenv from "dotenv"; dotenv.config(); import express from "express"; +import sitemap from "./sitemap.js"; const PORT = process.env.PORT || 3000; const app = express(); +app.use((req, res, next) => { + if (req.path.startsWith("/embed")) { + res.setHeader("Content-Security-Policy", "frame-ancestors *"); + } + next(); +}); +app.get("/healthcheck", (req, res) => { + res.end("ok"); +}); +app.get("/sitemap.xml", (req, res) => { + res.setHeader("Content-Type", "application/xml"); + res.end(sitemap); +}); app.use(handler); app.listen(PORT, () => { diff --git a/sitemap.js b/sitemap.js new file mode 100644 index 0000000..74c3070 --- /dev/null +++ b/sitemap.js @@ -0,0 +1,45 @@ +//read from process.env.PUBLIC_KENER_FOLDER / site.json +//read from process.env.PUBLIC_KENER_FOLDER / monitors.json +// create sitemap.xml +import fs from "fs-extra"; +let siteMap = ""; +import dotenv from "dotenv"; +dotenv.config(); +const site = fs.readJSONSync("./database/site.json", "utf8"); +const monitors = fs.readJSONSync("./database/monitors.json", "utf8"); +if (site.siteURL !== undefined && site.siteURL !== null && site.siteURL !== "") { + if (monitors.length > 0) { + siteMap = ` + + ${monitors + .map((monitor) => { + return ` + + ${site.siteURL}/incident/${monitor.folderName} + ${new Date().toISOString()} + daily + 0.8 + `; + }) + .join("\n")} + ${monitors + .map((monitor) => { + return ` + + ${site.siteURL}/monitor-${encodeURIComponent(monitor.tag)} + ${new Date().toISOString()} + daily + 0.8 + `; + }) + .join("\n")} +`; + } +} + +//export default siteMap +export default siteMap;