Update: 2026-07-31 03:00:06
This commit is contained in:
+125
@@ -0,0 +1,125 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
// Ensure marked and highlight.js are installed
|
||||
try {
|
||||
require.resolve('marked');
|
||||
require.resolve('highlight.js');
|
||||
} catch (e) {
|
||||
console.log("Installing marked and highlight.js...");
|
||||
execSync('npm install marked highlight.js', { stdio: 'inherit' });
|
||||
}
|
||||
|
||||
const { marked } = require('marked');
|
||||
const hljs = require('highlight.js');
|
||||
|
||||
marked.setOptions({
|
||||
highlight: function(code, lang) {
|
||||
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
|
||||
return hljs.highlight(code, { language }).value;
|
||||
},
|
||||
langPrefix: 'hljs language-',
|
||||
gfm: true,
|
||||
breaks: true
|
||||
});
|
||||
|
||||
const docsDir = __dirname;
|
||||
const indexFile = path.join(docsDir, 'index.html');
|
||||
|
||||
// Read the viewer template
|
||||
const template = `<!DOCTYPE html>
|
||||
<html lang="ar" dir="rtl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{TITLE}} - Siro Docs</title>
|
||||
<meta name="theme-color" content="#0f172a">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css">
|
||||
<link rel="stylesheet" href="../style.css">
|
||||
<link rel="stylesheet" href="../viewer.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="bg-animation">
|
||||
<div class="glow-orb orb-1"></div>
|
||||
<div class="glow-orb orb-2"></div>
|
||||
<div class="glow-orb orb-3"></div>
|
||||
</div>
|
||||
|
||||
<nav class="glass-nav viewer-nav">
|
||||
<div class="nav-brand">
|
||||
<a href="../index.html" class="back-link">
|
||||
<i class="fa-solid fa-arrow-right"></i>
|
||||
<span>العودة للرئيسية</span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="nav-links">
|
||||
<span class="doc-path-display">{{TITLE}}</span>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main class="viewer-container">
|
||||
<article class="markdown-body glass-panel">
|
||||
{{CONTENT}}
|
||||
</article>
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<div class="footer-content">
|
||||
<p>© 2026 Siro Platform.</p>
|
||||
</div>
|
||||
</footer>
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
function traverseDir(dir) {
|
||||
const files = fs.readdirSync(dir);
|
||||
files.forEach(file => {
|
||||
const fullPath = path.join(dir, file);
|
||||
if (fs.statSync(fullPath).isDirectory()) {
|
||||
traverseDir(fullPath);
|
||||
} else if (fullPath.endsWith('.md') && !fullPath.includes('node_modules')) {
|
||||
console.log(`Processing: ${fullPath}`);
|
||||
const markdown = fs.readFileSync(fullPath, 'utf8');
|
||||
const htmlContent = marked.parse(markdown);
|
||||
|
||||
const title = path.basename(fullPath);
|
||||
const finalHtml = template
|
||||
.replace(/{{TITLE}}/g, title)
|
||||
.replace('{{CONTENT}}', htmlContent);
|
||||
|
||||
const htmlPath = fullPath.replace(/\.md$/, '.html');
|
||||
fs.writeFileSync(htmlPath, finalHtml);
|
||||
console.log(`Generated: ${htmlPath}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 1. Generate HTML files for all MD files
|
||||
const dirsToProcess = ['01_overview', '02_journeys_and_tutorials', '03_pricing', '04_features', '05_transit_mawasalati', '06_investors', '07_marketing', '08_security', '10_food_orders'];
|
||||
|
||||
dirsToProcess.forEach(dir => {
|
||||
const fullPath = path.join(docsDir, dir);
|
||||
if (fs.existsSync(fullPath)) {
|
||||
traverseDir(fullPath);
|
||||
}
|
||||
});
|
||||
|
||||
// 2. Update index.html to point to .html files instead of viewer.html?doc=...
|
||||
let indexHtml = fs.readFileSync(indexFile, 'utf8');
|
||||
indexHtml = indexHtml.replace(/href="viewer\.html\?doc=([^"]+)\.md"/g, 'href="$1.html"');
|
||||
fs.writeFileSync(indexFile, indexHtml);
|
||||
console.log('Updated index.html links to point to static .html files.');
|
||||
|
||||
// 3. Remove viewer.html since it's no longer needed
|
||||
const viewerHtml = path.join(docsDir, 'viewer.html');
|
||||
if (fs.existsSync(viewerHtml)) {
|
||||
fs.unlinkSync(viewerHtml);
|
||||
console.log('Deleted viewer.html');
|
||||
}
|
||||
|
||||
console.log('Build complete!');
|
||||
Reference in New Issue
Block a user