-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
50 lines (41 loc) · 1.57 KB
/
Copy pathbuild.js
File metadata and controls
50 lines (41 loc) · 1.57 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
import { readFileSync, writeFileSync, mkdirSync } from 'fs';
import { marked } from 'marked';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
// Read markdown content files
const heroMd = readFileSync('content/hero.md', 'utf-8');
const workMd = readFileSync('content/work.md', 'utf-8');
const contactMd = readFileSync('content/contact.md', 'utf-8');
// Convert markdown to HTML
const heroHtml = marked.parse(heroMd);
const workHtml = marked.parse(workMd);
const contactHtml = marked.parse(contactMd);
// Read HTML template
const template = readFileSync('static/template.html', 'utf-8');
// Replace placeholders with rendered content
const finalHtml = template
.replace('{{HERO_CONTENT}}', heroHtml)
.replace('{{WORK_CONTENT}}', workHtml)
.replace('{{CONTACT_CONTENT}}', contactHtml);
// Create dist directory if it doesn't exist
mkdirSync('dist', { recursive: true });
// Write final HTML to dist
writeFileSync('dist/index.html', finalHtml);
// Copy static assets
import { cpSync } from 'fs';
cpSync('static/style.css', 'dist/style.css');
// Copy img directory if it exists
try {
cpSync('static/img', 'dist/img', { recursive: true });
console.log('✓ Build complete! Output: dist/index.html');
console.log('✓ Copied style.css and img/');
} catch (err) {
if (err.code === 'ENOENT') {
console.log('✓ Build complete! Output: dist/index.html');
console.log('✓ Copied style.css');
console.log(' (No img/ directory to copy)');
} else {
throw err;
}
}