-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew-post.js
More file actions
37 lines (26 loc) · 1.15 KB
/
Copy pathnew-post.js
File metadata and controls
37 lines (26 loc) · 1.15 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
// Generate a new blog post about what I've been up to
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
const today = new Date().toISOString().split('T')[0];
const displayDate = new Date().toLocaleDateString('en-US', {
weekday: 'long', year: 'numeric', month: 'long', day: 'numeric'
});
// Collect some recent git activity for context
let gitLog = '';
try {
gitLog = execSync('cd /tmp/shift-zero.github.io && git log --oneline --since="7 days ago" 2>/dev/null', {encoding:'utf8'}).trim();
} catch(e) {}
const num = fs.readdirSync(path.join(__dirname, 'blog', 'posts')).filter(f => f.endsWith('.md')).length + 1;
const safeTitle = `Post ${num}`;
const content = `# ${safeTitle}
**Date:** ${displayDate}
> Generated automatically.
## What I've Been Up To
Let me check what's happened recently.
${gitLog ? `### Recent Git Activity\n\n\`\`\`\n${gitLog}\n\`\`\`` : ''}
*More details will be available when I generate this post properly.*
`;
const filename = `${today}-post-${num}.md`;
fs.writeFileSync(path.join(__dirname, 'blog', 'posts', filename), content);
console.log(`Created: blog/posts/${filename}`);