From 2ebd3cc94ea1b3b1aa06bf716ce9abbd9f35f914 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 7 Jan 2024 20:43:57 +0000 Subject: [PATCH] f --- app/api/sitemap.server.jsx | 14 ++++++++ app/routes/[sitemap.xml].jsx | 65 ++++++++++++++++++++++++++++++++++++ app/wikid.server.js | 6 ++-- 3 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 app/api/sitemap.server.jsx create mode 100644 app/routes/[sitemap.xml].jsx diff --git a/app/api/sitemap.server.jsx b/app/api/sitemap.server.jsx new file mode 100644 index 0000000..4d0866a --- /dev/null +++ b/app/api/sitemap.server.jsx @@ -0,0 +1,14 @@ +import { hotRequest } from "../wikid.server"; +import env from "../environment.server"; + +const sitemap = async () => { + const request = { + url: `${env.readHotUrl}/internal/sitemap`, + method: 'get', + postData: null, + jwt: null + } + return hotRequest(request); +} + +export default sitemap; diff --git a/app/routes/[sitemap.xml].jsx b/app/routes/[sitemap.xml].jsx new file mode 100644 index 0000000..63d8ca5 --- /dev/null +++ b/app/routes/[sitemap.xml].jsx @@ -0,0 +1,65 @@ +import sitemap from "../api/sitemap.server"; + +export const loader = async () => { + + const [data, error] = await sitemap(); + + if (!!error) { + return new Response("System error", { + status: 500, + headers: { + "Content-Type": "application/text", + "xml-version": "1.0", + "encoding": "UTF-8" + } + }); + } + + const content = ` + + + https://www.wikid.app/ + 1.0 + always + + + https://www.wikid.app/signup + 1.0 + monthly + + + https://www.wikid.app/login + 1.0 + monthly + + + https://www.wikid.app/terms + 1.0 + monthly + + ${data.communities.map(community => ` + + https://www.wikid.app/c/${community.handle} + 1.0 + always + + ${community.channels.map(channel => ` + + https://www.wikid.app/c/${community.handle}/${channel.handle} + 1.0 + always + + `)} + `)} + + `; + + return new Response(content, { + status: 200, + headers: { + "Content-Type": "application/xml", + "xml-version": "1.0", + "encoding": "UTF-8" + } + }); +}; diff --git a/app/wikid.server.js b/app/wikid.server.js index 939ec8c..e4bc57b 100644 --- a/app/wikid.server.js +++ b/app/wikid.server.js @@ -703,14 +703,14 @@ const multiPartRequest = async ({ url, form, jwt }) => { return [response, errors, status]; } -const hotRequest = async ({ url, method, postData, jwt }) => { +export const hotRequest = async ({ url, method, postData, jwt }) => { let errors = null; let response = null; let status = 200; - const authHeaders = { + const authHeaders = !!jwt ? { "Authorization": `Bearer ${jwt}`, - }; + } : { }; const headers = { ...authHeaders,