UNPKG

morphbox

Version:

Docker-based AI sandbox for development with Claude integration

144 lines (133 loc) 5.5 kB
import { e as error } from './index-3BbzJtgI.js'; import { existsSync, readFileSync } from 'fs'; import { join } from 'path'; function markdownToHtml(markdown) { let html = markdown; html = html.replace(/^# (.*$)/gm, "<h1>$1</h1>"); html = html.replace(/^## (.*$)/gm, "<h2>$1</h2>"); html = html.replace(/^### (.*$)/gm, "<h3>$1</h3>"); html = html.replace(/^#### (.*$)/gm, "<h4>$1</h4>"); html = html.replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>"); html = html.replace(/\*(.*?)\*/g, "<em>$1</em>"); html = html.replace(/```(\w+)?\n([\s\S]*?)```/g, '<pre><code class="language-$1">$2</code></pre>'); html = html.replace(/`(.*?)`/g, "<code>$1</code>"); html = html.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>'); html = html.replace(/^[\s]*\*[\s]+(.*$)/gm, "<li>$1</li>"); html = html.replace(/^[\s]*\-[\s]+(.*$)/gm, "<li>$1</li>"); html = html.replace(/(<li>.*<\/li>)/gs, "<ul>$1</ul>"); html = html.replace(/\n\n/g, "</p><p>"); html = "<p>" + html + "</p>"; html = html.replace(/<p><\/p>/g, ""); html = html.replace(/<p>(<h[1-6]>)/g, "$1"); html = html.replace(/(<\/h[1-6]>)<\/p>/g, "$1"); html = html.replace(/<p>(<ul>)/g, "$1"); html = html.replace(/(<\/ul>)<\/p>/g, "$1"); html = html.replace(/<p>(<pre>)/g, "$1"); html = html.replace(/(<\/pre>)<\/p>/g, "$1"); return html; } function extractFrontmatter(content) { const frontmatterRegex = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/; const match = content.match(frontmatterRegex); if (match) { const yamlData = match[1]; const markdownContent = match[2]; const metadata = {}; yamlData.split("\n").forEach((line) => { const [key, ...valueParts] = line.split(":"); if (key && valueParts.length > 0) { const value = valueParts.join(":").trim().replace(/^["']|["']$/g, ""); metadata[key.trim()] = value; } }); return { metadata, content: markdownContent }; } return { metadata: {}, content }; } function generateTableOfContents(markdown) { const headers = []; const headerRegex = /^(#{1,6})\s+(.*)$/gm; let match; while ((match = headerRegex.exec(markdown)) !== null) { const level = match[1].length; const title = match[2]; const id = title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, ""); headers.push({ title, id, level }); } return headers; } const load = async ({ params }) => { const slug = params.slug; const contentDir = join(process.cwd(), "src", "content", "docs"); if (!slug) { throw error(404, "Page not found"); } const possiblePaths = [ join(contentDir, `${slug}.md`), join(contentDir, slug, "index.md"), join(contentDir, slug, "README.md") ]; let markdownPath = null; for (const path of possiblePaths) { if (existsSync(path)) { markdownPath = path; break; } } if (!markdownPath) { const placeholderContent = `# ${slug.split("/").pop()?.replace(/-/g, " ") || "Documentation"} This documentation page is coming soon. We're working on comprehensive documentation for all MorphBox features. ## What you can do now: - [Return to documentation home](/docs) - [Check out the installation guide](/docs/getting-started/installation) - [Learn about authentication](/docs/user-guide/authentication) ## Contributing Help us improve this documentation by contributing to the project: - [Development Setup](/docs/contributing/development) - [GitHub Repository](https://github.com/morphbox/morphbox) Thank you for your patience as we build out the complete documentation!`; const html = markdownToHtml(placeholderContent); const toc = generateTableOfContents(placeholderContent); return { title: slug.split("/").pop()?.replace(/-/g, " ") || "Documentation", description: `Documentation for ${slug}`, content: html, tableOfContents: toc, slug, lastModified: (/* @__PURE__ */ new Date()).toISOString(), isPlaceholder: true }; } try { const fileContent = readFileSync(markdownPath, "utf-8"); const { metadata, content } = extractFrontmatter(fileContent); const html = markdownToHtml(content); const toc = generateTableOfContents(content); return { title: metadata.title || slug.split("/").pop()?.replace(/-/g, " ") || "Documentation", description: metadata.description || `Documentation for ${slug}`, content: html, tableOfContents: toc, slug, lastModified: metadata.lastModified || (/* @__PURE__ */ new Date()).toISOString(), isPlaceholder: false, metadata }; } catch (err) { console.error("Error reading documentation file:", err); throw error(500, "Failed to load documentation"); } }; var _page_server_ts = /*#__PURE__*/Object.freeze({ __proto__: null, load: load }); const index = 5; let component_cache; const component = async () => component_cache ??= (await import('./_page.svelte-BlyTrorw.js')).default; const server_id = "src/routes/docs/[...slug]/+page.server.ts"; const imports = ["_app/immutable/nodes/5.43T3OQQk.js","_app/immutable/chunks/BtEme46p.js","_app/immutable/chunks/D0QH3NT1.js","_app/immutable/chunks/BmmFXip8.js","_app/immutable/chunks/IHki7fMi.js","_app/immutable/chunks/CySlB0Vo.js","_app/immutable/chunks/DLsnNbNa.js"]; const stylesheets = ["_app/immutable/assets/5.DkJvrRWy.css"]; const fonts = []; export { component, fonts, imports, index, _page_server_ts as server, server_id, stylesheets }; //# sourceMappingURL=5-D0g9kAP3.js.map