From 414cd7d3d7d1a387873caee44f6ea7f9068ffabe Mon Sep 17 00:00:00 2001
From: grassblock
Date: Sun, 29 Jun 2025 22:08:06 +0800
Subject: [PATCH] refactor: migrate route from post/... to blog/...
---
astro.config.mjs | 4 ++++
src/components/Search.astro | 2 +-
src/pages/blog.astro | 2 +-
src/pages/{post => blog}/[...slug].astro | 4 ++--
src/pages/{post => blog}/[...slug].txt.js | 0
src/pages/{post => blog}/[slug]/featured.png.js | 0
src/pages/categories/[...category].astro | 2 +-
src/pages/llms.txt.js | 2 +-
src/pages/rss.xml.js | 2 +-
src/pages/tags/[...tag].astro | 2 +-
src/pages/twtxt.txt.js | 2 +-
staticwebapp.config.json | 5 +++++
12 files changed, 18 insertions(+), 9 deletions(-)
rename src/pages/{post => blog}/[...slug].astro (95%)
rename src/pages/{post => blog}/[...slug].txt.js (100%)
rename src/pages/{post => blog}/[slug]/featured.png.js (100%)
diff --git a/astro.config.mjs b/astro.config.mjs
index 5b7752d..b778f5c 100644
--- a/astro.config.mjs
+++ b/astro.config.mjs
@@ -11,6 +11,10 @@ export default defineConfig({
site: 'https://terminal-blog.example.com',
base: '/',
trailingSlash: 'ignore',
+ redirects: {
+ // for the old routes still can be accessed
+ "/post/[...slug]": "/blog/[...slug]"
+ },
build: {
format: 'directory'
diff --git a/src/components/Search.astro b/src/components/Search.astro
index 8fbb5aa..6b0c794 100644
--- a/src/components/Search.astro
+++ b/src/components/Search.astro
@@ -192,7 +192,7 @@ const domain = Astro.url.host
const searchItems = results.map(item => `
{new Date(post.data.pubDate).toISOString().split('T')[0]}
- {post.data.title}
+ {post.data.title}
${new Date(item.pubDate).toISOString().split('T')[0]|| '' } —
${item.description || ''}
diff --git a/src/pages/blog.astro b/src/pages/blog.astro
index 44f6b9a..458c02f 100644
--- a/src/pages/blog.astro
+++ b/src/pages/blog.astro
@@ -20,7 +20,7 @@ posts.sort((a, b) => new Date(b.data.pubDate).getTime() - new Date(a.data.pubDat
{posts.map((post) => (
← Back to posts
- {noscript && Comments
Comments
{new Date(post.data.pubDate).toISOString().split('T')[0]} - {post.data.title} + {post.data.title}
)} diff --git a/src/pages/llms.txt.js b/src/pages/llms.txt.js index b917536..396352b 100644 --- a/src/pages/llms.txt.js +++ b/src/pages/llms.txt.js @@ -29,7 +29,7 @@ async function generateMarkdownSection(collectionName, sectionTitle, baseUrl) { for (const item of sortedItems) { const { title, description, slug } = getMetaData(item); - markdown += `\n- [${title}](${baseUrl}/post/${slug}): ${description}`; + markdown += `\n- [${title}](${baseUrl}/blog/${slug}): ${description}`; } return markdown; diff --git a/src/pages/rss.xml.js b/src/pages/rss.xml.js index bdef740..28a90d4 100644 --- a/src/pages/rss.xml.js +++ b/src/pages/rss.xml.js @@ -58,7 +58,7 @@ export async function GET(context) { title: post.data.title, description: post.data.description || '', pubDate: post.data.pubDate, - link: `${baseUrl}/post/${post.slug}`, + link: `${baseUrl}/blog/${post.slug}`, content, }); diff --git a/src/pages/tags/[...tag].astro b/src/pages/tags/[...tag].astro index 3b834c1..bbff160 100644 --- a/src/pages/tags/[...tag].astro +++ b/src/pages/tags/[...tag].astro @@ -24,7 +24,7 @@ const { posts } = Astro.props; {posts.map((post: any) =>{new Date(post.data.pubDate).toISOString().split('T')[0]} - {post.data.title} + {post.data.title}
)} diff --git a/src/pages/twtxt.txt.js b/src/pages/twtxt.txt.js index aa915c8..54f6845 100644 --- a/src/pages/twtxt.txt.js +++ b/src/pages/twtxt.txt.js @@ -6,7 +6,7 @@ export async function GET(context) { posts.sort((a, b) => new Date(b.data.pubDate).getTime() - new Date(a.data.pubDate).getTime()); const twtxt = posts.map(post => ( - `${new Date(post.data.pubDate).toISOString()}\t${post.data.title} ${context.site}post/${post.slug}` + `${new Date(post.data.pubDate).toISOString()}\t${post.data.title} ${context.site}blog/${post.slug}` )).join('\n'); return new Response(twtxt, { diff --git a/staticwebapp.config.json b/staticwebapp.config.json index c56f2f2..80f5f51 100644 --- a/staticwebapp.config.json +++ b/staticwebapp.config.json @@ -1,6 +1,11 @@ { "trailingSlash": "auto", "routes": [ + { + "route": "/post/*", + "redirect": "/blog/*", + "statusCode": 302 + }, { "route": "/*", "headers": {