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 fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
// Get the directory path
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Path to markdown files
const DOCS_PATH = path.resolve(__dirname, '../../../../lib/taDocs');
// Import all markdown files at build time
const docs = import.meta.glob('$lib/taDocs/*.md', {
as: 'raw',
eager: true
});
export async function GET({ params }) {
const { slug } = params;
@ -18,23 +14,24 @@ export async function GET({ params }) {
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 {
if (!fs.existsSync(filePath)) {
// Find the matching document
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');
}
const content = fs.readFileSync(filePath, 'utf-8');
return new Response(content, {
headers: {
'Content-Type': 'text/markdown',
'Cache-Control': 'max-age=600' // Cache for 10 minutes
'Content-Type': 'text/markdown; charset=utf-8',
'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 }));
}
}