This commit is contained in:
Oliver
2026-04-30 19:56:18 +00:00
parent a1976dfa65
commit 9d2ae7da3a
3 changed files with 12 additions and 3 deletions
+10 -1
View File
@@ -20,7 +20,7 @@ app.get('/api/tree', (req, res) => {
const items = entries.map(e => ({
name: e.name,
path: path.join(rel, e.name).replace(/\\/g,'/'),
type: e.isDirectory() ? 'dir' : (e.isFile() && e.name.endsWith('.md') ? 'file' : 'other')
type: e.isDirectory() ? 'dir' : (e.isFile() && (e.name.endsWith('.md') || e.name.endsWith('.html')) ? 'file' : 'other')
})).filter(i => i.type !== 'other'); // hide nonmd files
res.json(items);
});
@@ -32,6 +32,15 @@ app.get('/api/md', (req, res) => {
if (!rel) return res.status(400).json({error: 'path is required'});
const absPath = path.join(MD_ROOT, rel);
if (!absPath.startsWith(MD_ROOT)) return res.status(400).json({error: 'invalid path'});
// Serve HTML files by returning their raw content inside a JSON wrapper (compatible with client)
if (absPath.endsWith('.html')) {
return fs.readFile(absPath, 'utf8', (err, data) => {
if (err) return res.status(404).json({error: err.message});
// Return as JSON with an "html" field, same shape as markdown rendering
return res.json({html: data});
});
}
// For markdown files, render to HTML
fs.readFile(absPath, 'utf8', (err, data) => {
if (err) return res.status(404).json({error: err.message});
const html = md.render(data);