maybe docs works?
This commit is contained in:
parent
3ffd9ed38c
commit
1922ee58ec
1 changed files with 23 additions and 26 deletions
|
|
@ -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];
|
||||||
throw error(404, 'Documentation file not found');
|
|
||||||
}
|
if (!content) {
|
||||||
|
console.error(`Documentation file not found: ${slug}`);
|
||||||
const content = fs.readFileSync(filePath, 'utf-8');
|
// List available files for debugging
|
||||||
|
console.error('Available files:', Object.keys(docs));
|
||||||
return new Response(content, {
|
throw error(404, 'Documentation file not found');
|
||||||
headers: {
|
|
||||||
'Content-Type': 'text/markdown',
|
|
||||||
'Cache-Control': 'max-age=600' // Cache for 10 minutes
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
console.error(`Error reading documentation file: ${filePath}`, err);
|
|
||||||
throw error(500, JSON.stringify({ error: 'Error loading documentation', err: err }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new Response(content, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'text/markdown; charset=utf-8',
|
||||||
|
'Cache-Control': 'max-age=600', // Cache for 10 minutes
|
||||||
|
'Access-Control-Allow-Origin': '*' // Add CORS if needed
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue