You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

50 lines
1.8 KiB

/**
* Server-side loader for GitRepublic documentation
*/
import { readFile } from 'fs/promises';
import { join } from 'path';
import { fileURLToPath } from 'url';
import { existsSync } from 'fs';
import type { PageServerLoad } from './$types';
import logger from '$lib/services/logger.js';
export const load: PageServerLoad = async () => {
try {
let filePath: string = '';
let lastError: Error | null = null;
// Try method 1: Use process.cwd() (works in most cases)
try {
filePath = join(process.cwd(), 'docs', '34.md');
if (existsSync(filePath)) {
const content = await readFile(filePath, 'utf-8');
return { content };
}
throw new Error(`File not found at ${filePath}`);
} catch (err) {
lastError = err instanceof Error ? err : new Error(String(err));
// Try method 2: Use import.meta.url to find project root
try {
// Get the directory of this file, then go up to project root
const __filename = fileURLToPath(import.meta.url);
const __dirname = join(__filename, '..', '..', '..', '..');
filePath = join(__dirname, 'docs', '34.md');
if (existsSync(filePath)) {
const content = await readFile(filePath, 'utf-8');
return { content };
}
throw new Error(`File not found at ${filePath}`);
} catch (err2) {
lastError = err2 instanceof Error ? err2 : new Error(String(err2));
const attemptedPath = filePath || 'unknown';
logger.error({ error: lastError, attemptedPaths: [attemptedPath] }, 'Error loading NIP-34 documentation');
return { content: null, error: 'Failed to load NIP-34 documentation' };
}
}
} catch (error) {
logger.error({ error }, 'Error loading NIP-34 documentation');
return { content: null, error: 'Failed to load NIP-34 documentation' };
}
};