import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const rootDir = path.join(__dirname, '..'); // Site tree from main.js const SITE_TREE = [ { "id": "vyla", "title": "Ecosystem", "path": "/start-here/introduction", "groups": [ { "title": "Start here", "items": [ { "title": "Introduction", "file": "/start-here/introduction.md", "path": "/start-here/introduction", "hasMedia": true }, { "title": "Architecture", "file": "/start-here/architecture.md", "path": "/start-here/architecture" } ] }, { "title": "Products", "items": [ { "title": "Vyla Home", "file": "/products/home.md", "path": "/products/home", "hasMedia": true }, { "title": "Vyla Go", "file": "/products/go.md", "path": "/products/go", "hasMedia": true }, { "title": "Vyla TV", "file": "/products/tv.md", "path": "/products/tv", "hasMedia": true } ] } ] }, { "id": "sdk", "title": "SDK", "path": "/sdk", "groups": [ { "title": "Getting Started", "items": [ { "title": "SDK Overview", "file": "/sdk/vyla-sdk/index.md", "path": "/sdk", "hasMedia": true }, { "title": "SDK Quickstart", "file": "/sdk/vyla-sdk/quickstart.md", "path": "/sdk/vyla-sdk/quickstart" } ] }, { "title": "Reference", "items": [ { "title": "API Reference", "file": "/sdk/vyla-sdk/reference.md", "path": "/sdk/vyla-sdk/reference" } ] }, { "title": "Development", "items": [ { "title": "Contributing Sources", "file": "/sdk/vyla-sdk/contributing.md", "path": "/sdk/vyla-sdk/contributing", "hasMedia": true } ] } ] }, { "id": "stream-api", "title": "Stream API", "path": "/stream-api/overview", "groups": [ { "title": "Overview", "items": [ { "title": "Stream API Overview", "file": "/stream-api/overview/index.md", "path": "/stream-api/overview" } ] }, { "title": "Reference", "items": [ { "title": "Paths & Playback", "file": "/stream-api/reference/paths.md", "path": "/stream-api/reference/paths" }, { "title": "Media Data", "file": "/stream-api/reference/media-data.md", "path": "/stream-api/reference/media-data", "hasMedia": true }, { "title": "Operations & Health", "file": "/stream-api/reference/operations.md", "path": "/stream-api/reference/operations" } ] }, { "title": "Deployment", "items": [ { "title": "Self Hosting", "file": "/stream-api/deployment/self-hosting.md", "path": "/stream-api/deployment/self-hosting" } ] } ] }, { "id": "resources", "title": "Resources", "path": "/misc/project/support-us", "groups": [ { "title": "Support Vyla", "items": [ { "title": "Support Us", "file": "/misc/project/support-us.md", "path": "/misc/project/support-us", "hasMedia": true } ] }, { "title": "Help & Questions", "items": [ { "title": "FAQ", "file": "/resources/faq.md", "path": "/resources/faq" } ] }, { "title": "Project", "items": [ { "title": "Project Story", "file": "/misc/project/story.md", "path": "/misc/project/story" }, { "title": "Changelog", "file": "/misc/project/changelog.md", "path": "/misc/project/changelog" }, { "title": "Credits", "file": "/misc/project/credit.md", "path": "/misc/project/credit" }, { "title": "DMCA Policy", "file": "/misc/project/DMCA.md", "path": "/misc/project/dmca" } ] } ] } ]; function generateStaticHtml(route, mdContent) { const isHome = route.item.path === '/'; const pageTitle = isHome ? "Vyla Entertainment - Free & Decentralized Media Platform" : `${route.item.title} - Vyla Docs`; const pageUrl = `https://vyla.cc${route.item.path}`; // Extract description from markdown let desc = ""; if (mdContent) { const firstPara = mdContent.match(/^#\s+[^\n]+\n+([^\n#]+)/m); if (firstPara) { desc = firstPara[1].replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").trim().substring(0, 160); } } if (!desc) { desc = isHome ? "Vyla Entertainment is a community-built, decentralized media platform and developer ecosystem." : `${route.item.title} guide and developer documentation for the Vyla Ecosystem.`; } const jsonLd = JSON.stringify({ "@context": "https://schema.org", "@graph": [ { "@type": isHome ? "WebSite" : "TechArticle", "@id": pageUrl + (isHome ? "#website" : "#article"), "url": pageUrl, "name": isHome ? "Vyla Entertainment" : route.item.title, "headline": isHome ? "Vyla Entertainment" : route.item.title, "description": desc, "inLanguage": "en-US", "publisher": { "@id": "https://vyla.cc/#organization" } }, { "@type": "BreadcrumbList", "@id": pageUrl + "#breadcrumb", "itemListElement": [ { "@type": "ListItem", "position": 1, "name": "Home", "item": "https://vyla.cc/" }, !isHome ? { "@type": "ListItem", "position": 2, "name": route.tab.title, "item": "https://vyla.cc" + route.tab.path } : null, !isHome ? { "@type": "ListItem", "position": 3, "name": route.item.title, "item": pageUrl } : null ].filter(Boolean) } ] }); return ` ${pageTitle}
`; } function resolveRoute(pathname) { const path = pathname || '/'; if (!path.startsWith('/')) return '/' + path; const cleanPath = path.replace(/\/+$/, '') || '/'; if (cleanPath === '/') { return { tab: SITE_TREE[0], group: { title: 'Vyla' }, item: { title: 'Home', path: '/' } }; } for (const tab of SITE_TREE) { for (const grp of tab.groups) { for (const item of grp.items) { const itemPath = item.path.replace(/\/+$/, '') || '/'; if (itemPath.toLowerCase() === cleanPath.toLowerCase()) { return { tab, group: grp, item }; } } } } return null; } async function buildStaticPages() { console.log('==> Building static pages for SEO...'); const pages = []; // Add home page pages.push({ route: { tab: SITE_TREE[0], group: { title: 'Vyla' }, item: { title: 'Home', path: '/' } }, outputPath: path.join(rootDir, 'index.html') }); // Add all pages from SITE_TREE for (const tab of SITE_TREE) { for (const grp of tab.groups) { for (const item of grp.items) { const route = { tab, group: grp, item }; const cleanPath = item.path.replace(/^\//, '').replace(/\/$/, '') || 'index'; const outputPath = path.join(rootDir, cleanPath + '.html'); // Create directory if needed const dir = path.dirname(outputPath); if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); } pages.push({ route, outputPath }); } } } // Generate HTML for each page for (const { route, outputPath } of pages) { try { const html = generateStaticHtml(route, null); fs.writeFileSync(outputPath, html, 'utf-8'); console.log(` Generated: ${outputPath}`); } catch (err) { console.error(` Error generating ${outputPath}:`, err.message); } } console.log(`==> Generated ${pages.length} static pages`); } buildStaticPages().catch(console.error);