maybe docs works?

This commit is contained in:
Luna 2025-09-24 05:09:46 +02:00
parent 3ffd9ed38c
commit 1922ee58ec

View file

@ -1,14 +1,10 @@
import { error } from '@sveltejs/kit'; import { error } from '@sveltejs/kit';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
// Get the directory path // Import all markdown files at build time
const __filename = fileURLToPath(import.meta.url); const docs = import.meta.glob('$lib/taDocs/*.md', {
const __dirname = path.dirname(__filename); as: 'raw',
eager: true
// Path to markdown files });
const DOCS_PATH = path.resolve(__dirname, '../../../../lib/taDocs');
export async function GET({ params }) { export async function GET({ params }) {
const { slug } = params; const { slug } = params;
@ -18,23 +14,24 @@ export async function GET({ params }) {
throw error(400, 'Invalid documentation file requested'); throw error(400, 'Invalid documentation file requested');
} }
const filePath = path.join(DOCS_PATH, slug); // Create the import path that matches our glob pattern
const importPath = `/src/lib/taDocs/${slug}`;
try { // Find the matching document
if (!fs.existsSync(filePath)) { const content = docs[importPath];
if (!content) {
console.error(`Documentation file not found: ${slug}`);
// List available files for debugging
console.error('Available files:', Object.keys(docs));
throw error(404, 'Documentation file not found'); throw error(404, 'Documentation file not found');
} }
const content = fs.readFileSync(filePath, 'utf-8');
return new Response(content, { return new Response(content, {
headers: { headers: {
'Content-Type': 'text/markdown', 'Content-Type': 'text/markdown; charset=utf-8',
'Cache-Control': 'max-age=600' // Cache for 10 minutes 'Cache-Control': 'max-age=600', // Cache for 10 minutes
'Access-Control-Allow-Origin': '*' // Add CORS if needed
} }
}); });
} catch (err) {
console.error(`Error reading documentation file: ${filePath}`, err);
throw error(500, JSON.stringify({ error: 'Error loading documentation', err: err }));
}
} }