-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into Upgrade-to-Astro-4.0
- Loading branch information
Showing
2 changed files
with
14 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
import getPosts from "./getPosts"; | ||
import getTags from "./getTags"; | ||
|
||
export default async function getRedirects(): Promise<Record<string, string>> { | ||
const posts = await getPosts(); | ||
const tags = await getTags(); | ||
|
||
return posts.reduce<Record<string, string>>((acc, post) => { | ||
const postRedirects = posts.reduce<Record<string, string>>((acc, post) => { | ||
if (!post.redirects.length) return acc; | ||
post.redirects.forEach((r) => { | ||
acc[`/${r}`] = `/${post.slug}`; | ||
}); | ||
return acc; | ||
}, {}); | ||
|
||
const tagRedirects = tags.reduce<Record<string, string>>((acc, tag) => { | ||
if (tag.redirect) { | ||
acc[`/tags/${tag.redirect}`] = `/tags/${tag.name}`; | ||
} | ||
return acc; | ||
}, {}); | ||
|
||
return { ...postRedirects, ...tagRedirects }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters