mirror of
https://github.com/LukeHagar/website.git
synced 2025-12-06 04:22:07 +00:00
fix: build time improving threads
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { createRequire } from 'node:module'
|
||||
|
||||
/**
|
||||
* @returns {Promise<import('express').RequestHandler>}
|
||||
*/
|
||||
@@ -5,9 +7,14 @@ export async function sitemap() {
|
||||
const manifest = await import('../build/server/manifest.js');
|
||||
const prerendered = manifest.prerendered;
|
||||
|
||||
const routes = [
|
||||
...prerendered,
|
||||
...collectThreads()
|
||||
];
|
||||
|
||||
const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
${[...prerendered].filter(route => !route.endsWith('.json')).map(route => `<url>
|
||||
${[...routes].filter(route => !route.endsWith('.json')).map(route => `<url>
|
||||
<loc>https://appwrite.io${route}</loc>
|
||||
</url>
|
||||
`).join('')}
|
||||
@@ -20,4 +27,10 @@ export async function sitemap() {
|
||||
}
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
function collectThreads() {
|
||||
const threads = createRequire(import.meta.url)('../build/prerendered/threads/data.json');
|
||||
|
||||
return threads.map(id => `/threads/${id}`);
|
||||
}
|
||||
@@ -5,7 +5,7 @@ export const prerender = 'auto';
|
||||
|
||||
export const entries = async () => {
|
||||
const ids = [];
|
||||
for await (const thread of iterateAllThreads()) {
|
||||
for await (const thread of iterateAllThreads(100)) {
|
||||
ids.push({ id: thread.$id });
|
||||
}
|
||||
|
||||
|
||||
14
src/routes/threads/data.json/+server.ts
Normal file
14
src/routes/threads/data.json/+server.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { iterateAllThreads } from '../helpers';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { json } from '@sveltejs/kit';
|
||||
|
||||
export const prerender = true;
|
||||
|
||||
export const GET: RequestHandler = async () => {
|
||||
const ids = [];
|
||||
for await (const thread of iterateAllThreads()) {
|
||||
ids.push(thread.$id);
|
||||
}
|
||||
|
||||
return json(ids);
|
||||
};
|
||||
@@ -112,7 +112,7 @@ export async function getThreadMessages(threadId: string) {
|
||||
);
|
||||
}
|
||||
|
||||
export async function* iterateAllThreads() {
|
||||
export async function* iterateAllThreads(total: number|undefined = undefined) {
|
||||
let offset = 0;
|
||||
const limit = 100;
|
||||
while (true) {
|
||||
@@ -131,5 +131,9 @@ export async function* iterateAllThreads() {
|
||||
}
|
||||
|
||||
offset += limit;
|
||||
|
||||
if (total !== undefined && offset >= total) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export interface DiscordMessage extends Pick<Models.Document, '$id'> {
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
export interface DiscordThread extends Pick<Models.Document, '$id'> {
|
||||
export interface DiscordThread extends Models.Document {
|
||||
discord_id: string;
|
||||
author: string;
|
||||
tags?: string[];
|
||||
|
||||
Reference in New Issue
Block a user