File tree Expand file tree Collapse file tree 1 file changed +20
-12
lines changed
src/app/categories/[slug] Expand file tree Collapse file tree 1 file changed +20
-12
lines changed Original file line number Diff line number Diff line change @@ -33,19 +33,27 @@ export async function generateMetadata({ params }) {
3333
3434
3535const CategoryPage = ( { params } ) => {
36- const allCategories = [ "all" ] ;
37- const blogs = allBlogs . filter ( ( blog ) => {
38- return blog . tags . some ( ( tag ) => {
39- const slugified = slug ( tag ) ;
40- if ( ! allCategories . includes ( slugified ) ) {
41- allCategories . push ( slugified ) ;
42- }
43- if ( params . slug === "all" ) {
44- return true ;
45- }
46- return slugified === params . slug ;
47- } ) ;
36+ // Separating logic to create list of categories from all blogs
37+ const allCategories = [ "all" ] ; // Initialize with 'all' category
38+ allBlogs . forEach ( blog => {
39+ blog . tags . forEach ( tag => {
40+ const slugified = slug ( tag ) ;
41+ if ( ! allCategories . includes ( slugified ) ) {
42+ allCategories . push ( slugified ) ;
43+ }
4844 } ) ;
45+ } ) ;
46+
47+ // Sort allCategories to ensure they are in alphabetical order
48+ allCategories . sort ( ) ;
49+
50+ // Step 2: Filter blogs based on the current category (params.slug)
51+ const blogs = allBlogs . filter ( blog => {
52+ if ( params . slug === "all" ) {
53+ return true ; // Include all blogs if 'all' category is selected
54+ }
55+ return blog . tags . some ( tag => slug ( tag ) === params . slug ) ;
56+ } ) ;
4957
5058 return (
5159 < article className = "mt-12 flex flex-col text-dark dark:text-light" >
You can’t perform that action at this time.
0 commit comments