-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from zankhq/feat/blog-paths
Refactor dynamic page paths and localize blog posts
- Loading branch information
Showing
16 changed files
with
235 additions
and
241 deletions.
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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
import i18next, { changeLanguage } from "i18next"; | ||
import { getCollection } from "astro:content"; | ||
import Layout from "@layouts/Layout.astro"; | ||
import Container from "@components/container.astro"; | ||
import Posts from "@components/blog/posts.astro"; | ||
import Sectionhead from "@components/sectionhead.astro"; | ||
import Pagination from "@components/blog/pagination.astro"; | ||
changeLanguage("en"); | ||
export async function getStaticPaths() {changeLanguage('en') | ||
const posts = await getCollection("blog", ({ data }) => { | ||
return !data.draft && data.publishDate < new Date(); | ||
}); | ||
const localizedPosts = posts.filter((page) => { | ||
const [lang, ...slug] = page.slug.split("/"); | ||
return lang === i18next.language; | ||
}); | ||
const categories = new Set(); | ||
localizedPosts.map((post) => { | ||
typeof post.data.category === "string" && categories.add(post.data.category.toLowerCase()); | ||
}); | ||
return Array.from(categories).map((category) => { | ||
return { | ||
params: { category: category }, | ||
props: { | ||
posts: localizedPosts.filter((post) => typeof post.data.category === "string"), | ||
category: category, | ||
lang: i18next.language, | ||
}, | ||
}; | ||
}); | ||
} | ||
// Get the post directly from the prop on render | ||
const { posts, category, lang } = Astro.props; | ||
--- | ||
|
||
<Layout title="Blog"> | ||
<Container> | ||
<Sectionhead> | ||
<Fragment slot="title">#{category}</Fragment> | ||
<Fragment slot="desc">We write about building startups and thoughts going on our mind.</Fragment> | ||
</Sectionhead> | ||
<Posts posts={posts} /> | ||
</Container> | ||
</Layout> |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
import i18next, { changeLanguage } from "i18next"; | ||
import { getCollection } from "astro:content"; | ||
import Layout from "@layouts/Layout.astro"; | ||
import Container from "@components/container.astro"; | ||
import Posts from "@components/blog/posts.astro"; | ||
import Sectionhead from "@components/sectionhead.astro"; | ||
import Pagination from "@components/blog/pagination.astro"; | ||
changeLanguage("en"); | ||
export async function getStaticPaths() {changeLanguage('en') | ||
const posts = await getCollection("blog", ({ data }) => { | ||
return !data.draft && data.publishDate < new Date(); | ||
}); | ||
const localizedPosts = posts.filter((page) => { | ||
const [lang, ...slug] = page.slug.split("/"); | ||
return lang === i18next.language; | ||
}); | ||
const tags = new Set(); | ||
localizedPosts.map((post) => { | ||
Array.isArray(post.data.tags) && post.data.tags.map((tag) => tags.add(tag.toLowerCase())); | ||
}); | ||
return Array.from(tags).map((tag) => { | ||
return { | ||
params: { tag: tag }, | ||
props: { | ||
posts: localizedPosts.filter((post) => Array.isArray(post.data.tags) && post.data.tags.find((elem) => elem.toLowerCase() === tag)), | ||
tag: tag, | ||
lang: i18next.language, | ||
}, | ||
}; | ||
}); | ||
} | ||
// Get the post directly from the prop on render | ||
const { posts, tag, lang } = Astro.props; | ||
--- | ||
|
||
<Layout title="Blog"> | ||
<Container> | ||
<Sectionhead> | ||
<Fragment slot="title">#{tag}</Fragment> | ||
<Fragment slot="desc">We write about building startups and thoughts going on our mind.</Fragment> | ||
</Sectionhead> | ||
<Posts posts={posts} /> | ||
</Container> | ||
</Layout> |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.