-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.js
More file actions
51 lines (40 loc) · 1.55 KB
/
Copy pathbuild.js
File metadata and controls
51 lines (40 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const fs = require('fs');
const path = require('path');
const outputDir = '.'; // Output to the root directory for GitHub Pages
// Copy static files
const staticFiles = [
'index.html',
'js/include-html.js',
'js/data/sample-text.js',
'js/data/benchmarks.js',
'js/main.js',
'components/navbar.html',
'components/footer.html'
];
staticFiles.forEach(file => {
const sourcePath = path.join(__dirname, file);
const destPath = path.join(outputDir, file);
// Create directories if they don't exist
fs.mkdirSync(path.dirname(destPath), { recursive: true });
fs.copyFileSync(sourcePath, destPath);
});
// Process blog posts
const postsDir = path.join(__dirname, 'posts');
const template = fs.readFileSync(path.join(__dirname, 'templates', 'blog-post.html'), 'utf8');
fs.readdirSync(postsDir).forEach(file => {
const content = fs.readFileSync(path.join(postsDir, file), 'utf8');
const [_, frontMatter, markdown] = content.split('---');
const metadata = parseFrontMatter(frontMatter);
let html = template
.replace('{{TITLE}}', metadata.title)
.replace('{{DESCRIPTION}}', metadata.description)
.replace('{{CONTENT}}', convertMarkdownToHtml(markdown));
fs.writeFileSync(path.join(outputDir, `${path.parse(file).name}.html`), html);
});
// Implement parseFrontMatter and convertMarkdownToHtml functions
function parseFrontMatter(frontMatter) {
// Implement front matter parsing logic
}
function convertMarkdownToHtml(markdown) {
// Implement Markdown to HTML conversion logic
}