refactor: migrate route from post/... to blog/...
This commit is contained in:
parent
03ce3caefd
commit
414cd7d3d7
12 changed files with 18 additions and 9 deletions
|
@ -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'
|
||||
|
|
|
@ -192,7 +192,7 @@ const domain = Astro.url.host
|
|||
|
||||
const searchItems = results.map(item => `
|
||||
<div class="search-result">
|
||||
<a href="/post/${item.slug}" tabindex="0">
|
||||
<a href="/blog/${item.slug}" tabindex="0">
|
||||
<span class="result-title">${item.title}</span><br />
|
||||
<span class="result-date">${new Date(item.pubDate).toISOString().split('T')[0]|| '' } —
|
||||
<em>${item.description || ''}</em></span>
|
||||
|
|
|
@ -20,7 +20,7 @@ posts.sort((a, b) => new Date(b.data.pubDate).getTime() - new Date(a.data.pubDat
|
|||
{posts.map((post) => (
|
||||
<p>
|
||||
<span class="list-date">{new Date(post.data.pubDate).toISOString().split('T')[0]}</span>
|
||||
<a href={`/post/${post.slug}`}>{post.data.title}</a>
|
||||
<a href={`/blog/${post.slug}`}>{post.data.title}</a>
|
||||
</p>
|
||||
))}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ if (matchedImage && !customFeaturedImage) {
|
|||
}
|
||||
const firstImageURL = await ExtractFirstImage(Content)
|
||||
|
||||
const cover = customFeaturedImage || matchedImage_src?.src || firstImageURL || `/post/${slug}/featured.png` || '';
|
||||
const cover = customFeaturedImage || matchedImage_src?.src || firstImageURL || `/blog/${slug}/featured.png` || '';
|
||||
---
|
||||
|
||||
<Layout
|
||||
|
@ -61,7 +61,7 @@ const cover = customFeaturedImage || matchedImage_src?.src || firstImageURL || `
|
|||
<ReplyViaEmail title={entry.data.title} email={authorInfo.email} />
|
||||
<br>
|
||||
<a href="/blog">← Back to posts</a>
|
||||
{noscript && <h2>Comments</h2> <Comments path={`post/${slug}`} />}
|
||||
{noscript && <h2>Comments</h2> <Comments path={`blog/${slug}`} />}
|
||||
</div>
|
||||
|
||||
</Layout>
|
|
@ -28,7 +28,7 @@ const { posts } = Astro.props;
|
|||
{posts.map((post: any) =>
|
||||
<p>
|
||||
<span class="list-date">{new Date(post.data.pubDate).toISOString().split('T')[0]}</span>
|
||||
<a href={`/post/${post.slug}`}>{post.data.title}</a>
|
||||
<a href={`/blog/${post.slug}`}>{post.data.title}</a>
|
||||
</p>
|
||||
)}
|
||||
</ul>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ const { posts } = Astro.props;
|
|||
{posts.map((post: any) =>
|
||||
<p>
|
||||
<span class="list-date">{new Date(post.data.pubDate).toISOString().split('T')[0]}</span>
|
||||
<a href={`/post/${post.slug}`}>{post.data.title}</a>
|
||||
<a href={`/blog/${post.slug}`}>{post.data.title}</a>
|
||||
</p>
|
||||
)}
|
||||
</ul>
|
||||
|
|
|
@ -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, {
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
{
|
||||
"trailingSlash": "auto",
|
||||
"routes": [
|
||||
{
|
||||
"route": "/post/*",
|
||||
"redirect": "/blog/*",
|
||||
"statusCode": 302
|
||||
},
|
||||
{
|
||||
"route": "/*",
|
||||
"headers": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue