UNPKG

htmldocs

Version:

<h1 align="center"> <img src="https://github.com/user-attachments/assets/655fa7f9-98e7-42ee-8cd0-bb9193f100e9" alt="htmldocs" width="100%" /> </h1>

27 lines (23 loc) 798 B
"use server"; import path from 'node:path'; import fs from 'node:fs'; import { DOCUMENT_SCHEMAS_DIR } from '../../utils/paths'; import { JSONSchema7Definition } from 'json-schema'; import logger from '~/lib/logger'; export async function getDocumentSchema(documentPath: string): Promise<JSONSchema7Definition | null> { const baseName = path.basename(documentPath, path.extname(documentPath)); const schemaPath = path.join( DOCUMENT_SCHEMAS_DIR, baseName, `${baseName}.schema.json` ); try { if (fs.existsSync(schemaPath)) { const rawSchema = JSON.parse(await fs.promises.readFile(schemaPath, 'utf-8')); return rawSchema?.definitions?.ComponentProps || null; } } catch (error) { logger.warn('Failed to load schema:', error); } return null; }