Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt committed Jan 7, 2024
1 parent fb3d5f3 commit 2ebd3cc
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
14 changes: 14 additions & 0 deletions app/api/sitemap.server.jsx
Original file line number Diff line number Diff line change
@@ -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;
65 changes: 65 additions & 0 deletions app/routes/[sitemap.xml].jsx
Original file line number Diff line number Diff line change
@@ -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 = `
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://www.wikid.app/</loc>
<priority>1.0</priority>
<changefreq>always</changefreq>
</url>
<url>
<loc>https://www.wikid.app/signup</loc>
<priority>1.0</priority>
<changefreq>monthly</changefreq>
</url>
<url>
<loc>https://www.wikid.app/login</loc>
<priority>1.0</priority>
<changefreq>monthly</changefreq>
</url>
<url>
<loc>https://www.wikid.app/terms</loc>
<priority>1.0</priority>
<changefreq>monthly</changefreq>
</url>
${data.communities.map(community => `
<url>
<loc>https://www.wikid.app/c/${community.handle}</loc>
<priority>1.0</priority>
<changefreq>always</changefreq>
</url>
${community.channels.map(channel => `
<url>
<loc>https://www.wikid.app/c/${community.handle}/${channel.handle}</loc>
<priority>1.0</priority>
<changefreq>always</changefreq>
</url>
`)}
`)}
</urlset>
`;

return new Response(content, {
status: 200,
headers: {
"Content-Type": "application/xml",
"xml-version": "1.0",
"encoding": "UTF-8"
}
});
};
6 changes: 3 additions & 3 deletions app/wikid.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2ebd3cc

Please sign in to comment.