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',
|
site: 'https://terminal-blog.example.com',
|
||||||
base: '/',
|
base: '/',
|
||||||
trailingSlash: 'ignore',
|
trailingSlash: 'ignore',
|
||||||
|
redirects: {
|
||||||
|
// for the old routes still can be accessed
|
||||||
|
"/post/[...slug]": "/blog/[...slug]"
|
||||||
|
},
|
||||||
|
|
||||||
build: {
|
build: {
|
||||||
format: 'directory'
|
format: 'directory'
|
||||||
|
|
|
@ -192,7 +192,7 @@ const domain = Astro.url.host
|
||||||
|
|
||||||
const searchItems = results.map(item => `
|
const searchItems = results.map(item => `
|
||||||
<div class="search-result">
|
<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-title">${item.title}</span><br />
|
||||||
<span class="result-date">${new Date(item.pubDate).toISOString().split('T')[0]|| '' } —
|
<span class="result-date">${new Date(item.pubDate).toISOString().split('T')[0]|| '' } —
|
||||||
<em>${item.description || ''}</em></span>
|
<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) => (
|
{posts.map((post) => (
|
||||||
<p>
|
<p>
|
||||||
<span class="list-date">{new Date(post.data.pubDate).toISOString().split('T')[0]}</span>
|
<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>
|
</p>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ if (matchedImage && !customFeaturedImage) {
|
||||||
}
|
}
|
||||||
const firstImageURL = await ExtractFirstImage(Content)
|
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
|
<Layout
|
||||||
|
@ -61,7 +61,7 @@ const cover = customFeaturedImage || matchedImage_src?.src || firstImageURL || `
|
||||||
<ReplyViaEmail title={entry.data.title} email={authorInfo.email} />
|
<ReplyViaEmail title={entry.data.title} email={authorInfo.email} />
|
||||||
<br>
|
<br>
|
||||||
<a href="/blog">← Back to posts</a>
|
<a href="/blog">← Back to posts</a>
|
||||||
{noscript && <h2>Comments</h2> <Comments path={`post/${slug}`} />}
|
{noscript && <h2>Comments</h2> <Comments path={`blog/${slug}`} />}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</Layout>
|
</Layout>
|
|
@ -28,7 +28,7 @@ const { posts } = Astro.props;
|
||||||
{posts.map((post: any) =>
|
{posts.map((post: any) =>
|
||||||
<p>
|
<p>
|
||||||
<span class="list-date">{new Date(post.data.pubDate).toISOString().split('T')[0]}</span>
|
<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>
|
</p>
|
||||||
)}
|
)}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -29,7 +29,7 @@ async function generateMarkdownSection(collectionName, sectionTitle, baseUrl) {
|
||||||
|
|
||||||
for (const item of sortedItems) {
|
for (const item of sortedItems) {
|
||||||
const { title, description, slug } = getMetaData(item);
|
const { title, description, slug } = getMetaData(item);
|
||||||
markdown += `\n- [${title}](${baseUrl}/post/${slug}): ${description}`;
|
markdown += `\n- [${title}](${baseUrl}/blog/${slug}): ${description}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return markdown;
|
return markdown;
|
||||||
|
|
|
@ -58,7 +58,7 @@ export async function GET(context) {
|
||||||
title: post.data.title,
|
title: post.data.title,
|
||||||
description: post.data.description || '',
|
description: post.data.description || '',
|
||||||
pubDate: post.data.pubDate,
|
pubDate: post.data.pubDate,
|
||||||
link: `${baseUrl}/post/${post.slug}`,
|
link: `${baseUrl}/blog/${post.slug}`,
|
||||||
content,
|
content,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ const { posts } = Astro.props;
|
||||||
{posts.map((post: any) =>
|
{posts.map((post: any) =>
|
||||||
<p>
|
<p>
|
||||||
<span class="list-date">{new Date(post.data.pubDate).toISOString().split('T')[0]}</span>
|
<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>
|
</p>
|
||||||
)}
|
)}
|
||||||
</ul>
|
</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());
|
posts.sort((a, b) => new Date(b.data.pubDate).getTime() - new Date(a.data.pubDate).getTime());
|
||||||
|
|
||||||
const twtxt = posts.map(post => (
|
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');
|
)).join('\n');
|
||||||
|
|
||||||
return new Response(twtxt, {
|
return new Response(twtxt, {
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
{
|
{
|
||||||
"trailingSlash": "auto",
|
"trailingSlash": "auto",
|
||||||
"routes": [
|
"routes": [
|
||||||
|
{
|
||||||
|
"route": "/post/*",
|
||||||
|
"redirect": "/blog/*",
|
||||||
|
"statusCode": 302
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"route": "/*",
|
"route": "/*",
|
||||||
"headers": {
|
"headers": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue