-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_regex.js
More file actions
53 lines (46 loc) · 1.56 KB
/
patch_regex.js
File metadata and controls
53 lines (46 loc) · 1.56 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
52
53
const fs = require('fs');
const genScript = `
const fs = require('fs');
const path = require('path');
const blogsDir = path.join(__dirname, '../blogs');
const outputFile = path.join(__dirname, '../blogs.json');
if (!fs.existsSync(blogsDir)) {
fs.mkdirSync(blogsDir);
// Create a dummy blog post
fs.writeFileSync(path.join(blogsDir, 'welcome.md'), \`---
title: "The Future of Edge AI"
date: "Oct 24, 2024"
tag: "Edge AI"
readTime: "5 min"
---
This is a post about Edge AI running directly on GAPbot hardware.\`);
}
const files = fs.readdirSync(blogsDir).filter(f => f.endsWith('.md'));
const blogs = [];
files.forEach(file => {
const content = fs.readFileSync(path.join(blogsDir, file), 'utf8');
// Simple frontmatter parser
const match = content.match(/---\\n([\\s\\S]*?)\\n---/);
let meta = {};
if (match) {
const lines = match[1].split('\\n');
lines.forEach(line => {
const [key, ...val] = line.split(':');
if (key && val) {
meta[key.trim()] = val.join(':').replace(/"/g, '').trim();
}
});
}
blogs.push({
title: meta.title || 'Untitled',
date: meta.date || new Date().toISOString().split('T')[0],
tag: meta.tag || 'Update',
readTime: meta.readTime || '3 min',
excerpt: content.replace(/---\\n([\\s\\S]*?)\\n---/, '').substring(0, 100).trim() + '...',
link: '#' // In a real setup, link to a generated HTML page
});
});
fs.writeFileSync(outputFile, JSON.stringify(blogs, null, 2));
console.log('Generated blogs.json from markdown files.');
`;
fs.writeFileSync('scripts/generate_blog_json.js', genScript);