Files
blog/scripts/newsletter/find-newsletter-number.js
T
tiennm99 8f4e1928d8 feat(tooling): run blog from Claude Code, OpenCode & Codex on shared engine
Extract newsletter scripts to a neutral scripts/newsletter/ engine and add
side-by-side support for all three AI coding tools off one source of truth.

- Move 9 scripts + substack config from .claude/skills/**/scripts to
  scripts/newsletter/ (history preserved); fix PROJECT_ROOT depth and
  cross-require/config paths; repoint all SKILL.md invocations
- Add canonical AGENTS.md; reduce CLAUDE.md to an @AGENTS.md import
- Add opencode.json (permissions, no MCP); skills auto-discovered in place
- Add codex/prompts/*.md (6 prompts) + copy installers (install.sh/.ps1)
- Add docs/multi-tool-usage.md (setup, per-tool invocation, teardown) + README pointer
2026-06-02 14:07:22 +07:00

75 lines
1.9 KiB
JavaScript

#!/usr/bin/env node
// Find the most recent newsletter number and return the next one
// Usage: node find-newsletter-number.js
// Outputs: The next newsletter number
const fs = require("fs");
const path = require("path");
const PROJECT_ROOT = path.resolve(__dirname, "../..");
const CONTENT_DIR = path.join(PROJECT_ROOT, "content", "post");
// Extract newsletter number from file content
function extractNewsletterNumber(filePath) {
try {
const content = fs.readFileSync(filePath, "utf-8");
const match = content.match(/Newsletter\s*#(\d+)/);
return match ? parseInt(match[1], 10) : 0;
} catch {
return 0;
}
}
// Scan all year/month/day directories for newsletter posts
function findMostRecentNewsletter() {
let maxNumber = 0;
// List year directories, sorted descending
let years;
try {
years = fs.readdirSync(CONTENT_DIR)
.filter((d) => /^\d{4}$/.test(d))
.sort((a, b) => b.localeCompare(a));
} catch {
return 0;
}
for (const year of years) {
const yearDir = path.join(CONTENT_DIR, year);
let months;
try {
months = fs.readdirSync(yearDir)
.filter((d) => /^\d{2}$/.test(d))
.sort((a, b) => b.localeCompare(a));
} catch {
continue;
}
for (const month of months) {
const monthDir = path.join(yearDir, month);
let days;
try {
days = fs.readdirSync(monthDir)
.filter((d) => /^\d{2}$/.test(d))
.sort((a, b) => b.localeCompare(a));
} catch {
continue;
}
for (const day of days) {
const filePath = path.join(monthDir, day, "index.md");
const num = extractNewsletterNumber(filePath);
if (num > maxNumber) maxNumber = num;
}
}
// Early exit: if we found a newsletter in this year, no need to go further back
if (maxNumber > 0) break;
}
return maxNumber;
}
const mostRecent = findMostRecentNewsletter();
console.log(mostRecent + 1);