diff --git a/app.js b/app.js index 03b1218..762eda6 100644 --- a/app.js +++ b/app.js @@ -319,6 +319,28 @@ app.get('/rss', (req, res) => { res.send(rssFeed); }); +// Route to return all blog content in plain text JSON format +app.get('/json', (req, res) => { + const blogFiles = fs.readdirSync(path.join(__dirname, 'markdown')).filter(file => file.endsWith('.md')); + + const blogPosts = blogFiles.map(file => { + const title = file.replace('.md', '').replace(/-/g, ' '); + const slug = titleToSlug(title); + const markdownContent = fs.readFileSync(path.join(__dirname, 'markdown', file), 'utf-8'); + + // Strip all formatting and return plain text + const plainTextContent = markdownContent.replace(/[#*>\-`_~[\]]/g, '').replace(/\n+/g, ' ').trim(); + + return { + title, + slug, + content: plainTextContent + }; + }); + + res.json(blogPosts); +}); + // Create a URL object from the environment variable const blog_URL = new URL(process.env.BLOG_URL);