diff --git a/package.json b/package.json index b617df0..16246e6 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "scripts": { "dev": "astro dev", "start": "astro dev", - "build": "astro check && astro build", + "prebuild": "node scripts/generate-redirects.js", + "build": "npm run prebuild && astro check && astro build", "preview": "astro preview", "astro": "astro" }, diff --git a/public/_redirects b/public/_redirects new file mode 100644 index 0000000..920215e --- /dev/null +++ b/public/_redirects @@ -0,0 +1,17 @@ +# redirects for pretty URLs - generated automatically + +/2024-01-06-why-does-every-guest-house-room-have-a-tv-screen /blog/2024-01-06-why-does-every-guest-house-room-have-a-tv-screen 301 +/2025-06-21-crowdsourcing-exam-problems /blog/2025-06-21-crowdsourcing-exam-problems 301 +/2025-07-05-hypothetical-grading-policy /blog/2025-07-05-hypothetical-grading-policy 301 +/2025-07-09-math-human-flourishing-struggle /blog/2025-07-09-math-human-flourishing-struggle 301 +/2025-07-17-teacher-training-initiative /blog/2025-07-17-teacher-training-initiative 301 +/2025-07-21-capacities-pkm /blog/2025-07-21-capacities-pkm 301 +/2025-08-07-nptel-underrated /blog/2025-08-07-nptel-underrated 301 +/2025-08-16-interactive-fiction-textbooks /blog/2025-08-16-interactive-fiction-textbooks 301 +/2025-08-27-vibecoding-manim-slides /blog/2025-08-27-vibecoding-manim-slides 301 +/2025-08-29-grok-a-book-new-editions /blog/2025-08-29-grok-a-book-new-editions 301 +/2025-09-05-pocket-shutdown /blog/2025-09-05-pocket-shutdown 301 +/2025-09-23-ten-years-iitgn /blog/2025-09-23-ten-years-iitgn 301 +/2025-11-17-iisc-time-tracking /blog/2025-11-17-iisc-time-tracking 301 +/2026-02-20-value-of-things-comment /blog/2026-02-20-value-of-things-comment 301 +/2026-02-25-mattermost-for-openclaw /blog/2026-02-25-mattermost-for-openclaw 301 diff --git a/scripts/generate-redirects.js b/scripts/generate-redirects.js new file mode 100644 index 0000000..b00dbdc --- /dev/null +++ b/scripts/generate-redirects.js @@ -0,0 +1,27 @@ +// Generate _redirects file for pretty URLs +import fs from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const contentDir = path.join(__dirname, '../src/content/blog'); + +const redirects = [ + '# redirects for pretty URLs - generated automatically', + '' +]; + +// Read all blog post directories +const entries = fs.readdirSync(contentDir, { withFileTypes: true }); +for (const entry of entries) { + if (entry.isDirectory()) { + const slug = entry.name; + redirects.push(`/${slug} /blog/${slug} 301`); + } +} + +// Write _redirects file +const outputPath = path.join(__dirname, '../public/_redirects'); +fs.writeFileSync(outputPath, redirects.join('\n') + '\n'); + +console.log(`Generated ${redirects.length - 2} redirects`); diff --git a/src/pages/[...id].astro b/src/pages/[...id].astro deleted file mode 100644 index 14d6df8..0000000 --- a/src/pages/[...id].astro +++ /dev/null @@ -1,16 +0,0 @@ ---- -export const prerender = true; -import { getCollection } from 'astro:content'; - -export async function getStaticPaths() { - const posts = await getCollection('blog'); - - return posts.map((post) => ({ - params: { id: post.id }, - props: { slug: post.id }, - })); -} - -const { slug } = Astro.props; -return Astro.redirect(`/blog/${slug}`, 301); ----