Browse Source

fix docs

Nostr-Signature: 4671648712f19537cbf0fd00cf19e254eae4a1ac9c1274ea396e62dac193b88c 573634b648634cbad10f2451776089ea21090d9407f715e83c577b4611ae6edc 49a3e89e312ec4caebfeacdaade3e4cc6d027ab9c50d8e6aa1998f120a81d8d51235ae397df6e42b9efca4147497b8881731dda6d58fee7d28d2ac07cec295ec
main
Silberengel 3 weeks ago
parent
commit
a59d6fe8a9
  1. 1
      nostr/commit-signatures.jsonl
  2. 103
      src/routes/api/openapi.json/+server.ts
  3. 34
      src/routes/docs/+page.server.ts
  4. 34
      src/routes/docs/nip-a3/+page.server.ts
  5. 34
      src/routes/docs/nip34/+page.server.ts
  6. 34
      src/routes/docs/nip34/spec/+page.server.ts

1
nostr/commit-signatures.jsonl

@ -43,3 +43,4 @@ @@ -43,3 +43,4 @@
{"kind":1640,"pubkey":"573634b648634cbad10f2451776089ea21090d9407f715e83c577b4611ae6edc","created_at":1771681068,"tags":[["author","Silberengel","silberengel7@protonmail.com"],["message","remove landing page search bar"]],"content":"Signed commit: remove landing page search bar","id":"71087b100ce14a1f2eb975be23450c62143ee11a8fd0429ec7440bfea1751741","sig":"695c704503ed1397f6871770ad55822a17a503bcfb71a0db7b3f2477cacb0e767b9f122075b0216f884e41e175c0ac9f9e3d743086a2aa34db4aa1207c900703"}
{"kind":1640,"pubkey":"573634b648634cbad10f2451776089ea21090d9407f715e83c577b4611ae6edc","created_at":1771682804,"tags":[["author","Silberengel","silberengel7@protonmail.com"],["message","repo page refactor"]],"content":"Signed commit: repo page refactor","id":"9ad7610ff7aa61d62d3772d6ae7c0589cda8ff95cd7a60b81c84ba879e0f9d8a","sig":"8918f36d426d352a6787543daaa044cf51855632e2257f29cc18bb87db31d61c877b525113e21045d3bc135376e1c0574454e28bd409d3135bcb80079bc11947"}
{"kind":1640,"pubkey":"573634b648634cbad10f2451776089ea21090d9407f715e83c577b4611ae6edc","created_at":1771688902,"tags":[["author","Silberengel","silberengel7@protonmail.com"],["message","refactor"]],"content":"Signed commit: refactor","id":"62b813f817173c9e35eb05088240f7ec50ecab697c8c6d4a5c19d47664ef3837","sig":"ca9c70fc7bf8b1bb1726461bb843127d1bddc4de96652cfc7497698a3f5c4dc4a8c3f5a7a240710db77afabeee2a3b7d594f75f42a0a8b28aeeef50f66b506c9"}
{"kind":1640,"pubkey":"573634b648634cbad10f2451776089ea21090d9407f715e83c577b4611ae6edc","created_at":1771690183,"tags":[["author","Silberengel","silberengel7@protonmail.com"],["message","get rid of tabs on repo page"]],"content":"Signed commit: get rid of tabs on repo page","id":"d34fb23385a23f479c683e76f5676356a11d63bcd0ecf71d25f1b85dbb0cfe57","sig":"1f6454f9961b9245d1e32f4a903ee9636201670491145d0185e95e7b7d33bf1027ac5b8e370070640e103740ab19e9915baa7755c6008fd32fe41e9cb86d33b8"}

103
src/routes/api/openapi.json/+server.ts

@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
import { json, error } from '@sveltejs/kit';
import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { readFileSync } from 'fs';
import { readFileSync, existsSync } from 'fs';
import { join } from 'path';
import { fileURLToPath } from 'url';
// Cache the spec in production
// Cache the spec
let cachedSpec: any = null;
export const GET: RequestHandler = async () => {
try {
// Use cached spec if available (in production)
if (cachedSpec && typeof process !== 'undefined' && process.env.NODE_ENV === 'production') {
// Return cached spec if available
if (cachedSpec) {
return json(cachedSpec, {
headers: {
'Content-Type': 'application/json',
@ -19,58 +19,79 @@ export const GET: RequestHandler = async () => { @@ -19,58 +19,79 @@ export const GET: RequestHandler = async () => {
});
}
// Try to read the file using different path resolution methods
let openApiSpec: any = null;
let lastError: Error | null = null;
// Method 1: Try using fileURLToPath (works in most cases)
try {
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const specPath = join(__dirname, 'openapi.json');
openApiSpec = JSON.parse(readFileSync(specPath, 'utf-8'));
} catch (err) {
lastError = err instanceof Error ? err : new Error(String(err));
// Method 2: Try using process.cwd() (fallback for build environments)
// Try to import directly first (works in most build scenarios)
try {
if (typeof process !== 'undefined' && process.cwd) {
const specPath = join(process.cwd(), 'src/routes/api/openapi.json/openapi.json');
openApiSpec = JSON.parse(readFileSync(specPath, 'utf-8'));
// @ts-ignore - Dynamic import for JSON
const imported = await import('./openapi.json?raw');
const fileContent = typeof imported.default === 'string' ? imported.default : String(imported.default || imported);
cachedSpec = JSON.parse(fileContent);
return json(cachedSpec, {
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'public, max-age=3600'
}
});
} catch (importErr) {
// Fallback to file system read
console.log('Direct import failed, trying file system read:', importErr);
}
} catch (err2) {
lastError = err2 instanceof Error ? err2 : new Error(String(err2));
// Method 3: Try relative to import.meta.url parent
// Otherwise, try reading from file system
let specPath: string;
let lastError: Error | null = null;
// Try method 1: Use import.meta.url (works in most cases)
try {
const __filename = fileURLToPath(import.meta.url);
const __dirname = join(__filename, '..');
const specPath = join(__dirname, 'openapi.json');
openApiSpec = JSON.parse(readFileSync(specPath, 'utf-8'));
} catch (err3) {
lastError = err3 instanceof Error ? err3 : new Error(String(err3));
throw new Error(`Failed to locate openapi.json file. Tried multiple paths. Last error: ${lastError.message}`);
}
}
}
if (!openApiSpec) {
throw new Error('Failed to load OpenAPI specification');
specPath = join(__dirname, 'openapi.json');
console.log('Trying path:', specPath);
if (existsSync(specPath)) {
const fileContent = readFileSync(specPath, 'utf-8');
cachedSpec = JSON.parse(fileContent);
return json(cachedSpec, {
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'public, max-age=3600'
}
// Cache for production
if (typeof process !== 'undefined' && process.env.NODE_ENV === 'production') {
cachedSpec = openApiSpec;
});
}
throw new Error(`File not found at ${specPath}`);
} catch (err) {
lastError = err instanceof Error ? err : new Error(String(err));
console.log('Method 1 failed:', lastError.message);
return json(openApiSpec, {
// Try method 2: Use process.cwd() (fallback for production builds)
try {
if (typeof process !== 'undefined' && process.cwd) {
specPath = join(process.cwd(), 'src/routes/api/openapi.json/openapi.json');
console.log('Trying path:', specPath);
if (existsSync(specPath)) {
const fileContent = readFileSync(specPath, 'utf-8');
cachedSpec = JSON.parse(fileContent);
return json(cachedSpec, {
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'public, max-age=3600'
}
});
}
throw new Error(`File not found at ${specPath}`);
} else {
throw lastError;
}
} catch (err2) {
lastError = err2 instanceof Error ? err2 : new Error(String(err2));
console.log('Method 2 failed:', lastError.message);
throw new Error(`Failed to locate openapi.json. Tried multiple paths. Last error: ${lastError.message}`);
}
}
} catch (err) {
const errorMessage = err instanceof Error ? err.message : String(err);
console.error('Error reading openapi.json:', errorMessage);
return error(500, `Failed to load OpenAPI specification: ${errorMessage}`);
return json(
{ error: 'Failed to load OpenAPI specification', details: errorMessage },
{ status: 500 }
);
}
};

34
src/routes/docs/+page.server.ts

@ -4,15 +4,45 @@ @@ -4,15 +4,45 @@
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 {
// Read tutorial documentation from docs/tutorial.md
const filePath = join(process.cwd(), 'docs', 'tutorial.md');
let filePath: string = '';
let lastError: Error | null = null;
// Try method 1: Use process.cwd() (works in most cases)
try {
filePath = join(process.cwd(), 'docs', 'tutorial.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', 'tutorial.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 documentation');
return { content: null, error: 'Failed to load documentation' };
}
}
} catch (error) {
logger.error({ error }, 'Error loading documentation');
return { content: null, error: 'Failed to load documentation' };

34
src/routes/docs/nip-a3/+page.server.ts

@ -4,15 +4,45 @@ @@ -4,15 +4,45 @@
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 {
// Read NIP-A3 documentation from docs/NIP-A3.md
const filePath = join(process.cwd(), 'docs', 'NIP-A3.md');
let filePath: string = '';
let lastError: Error | null = null;
// Try method 1: Use process.cwd() (works in most cases)
try {
filePath = join(process.cwd(), 'docs', 'NIP-A3.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', 'NIP-A3.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-A3 documentation');
return { content: null, error: 'Failed to load NIP-A3 documentation' };
}
}
} catch (error) {
logger.error({ error }, 'Error loading NIP-A3 documentation');
return { content: null, error: 'Failed to load NIP-A3 documentation' };

34
src/routes/docs/nip34/+page.server.ts

@ -4,15 +4,45 @@ @@ -4,15 +4,45 @@
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 {
// Read NIP-34 documentation from docs/34.md
const filePath = join(process.cwd(), 'docs', '34.md');
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' };

34
src/routes/docs/nip34/spec/+page.server.ts

@ -4,15 +4,45 @@ @@ -4,15 +4,45 @@
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 {
// Read NIP-34 specification from docs/34.md
const filePath = join(process.cwd(), 'docs', '34.md');
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 specification');
return { content: null, error: 'Failed to load NIP-34 specification' };
}
}
} catch (error) {
logger.error({ error }, 'Error loading NIP-34 specification');
return { content: null, error: 'Failed to load NIP-34 specification' };

Loading…
Cancel
Save