Skip to content

Commit e885d80

Browse files
committed
handle og images for tag and category list pages
1 parent 7d9e521 commit e885d80

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/constants/metadata.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,19 @@ export const PAGE_METADATA = {
3636
'lists/blog/tags': {
3737
title: 'Tags',
3838
},
39+
'lists/blog/tags/tag': {
40+
title: 'Tag',
41+
},
3942
// 'src/pages/blog/tags/[tag]/[...page].astro' // dynamic tag param
4043
'lists/blog/explore': {
4144
title: 'Explore',
4245
},
4346
'lists/blog/categories': {
4447
title: 'Categories',
4548
},
49+
'lists/blog/categories/category': {
50+
title: 'Category',
51+
},
4652
// src/pages/blog/categories/[category]/[...page].astro
4753
'lists/projects': {
4854
title: 'Projects',

src/pages/blog/categories/[category]/[...page].astro

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Link from '@/components/Link.astro';
66
import PostList from '@/components/PostList.astro';
77
import { ROUTES } from '@/constants/routes';
88
import { CONFIG } from '@/config';
9+
import { getPageMetadata } from '@/utils/metadata';
910
import { pickPaginationPropsFromPage } from '@/utils/pagination';
1011
import { capitalizeFirstLetter } from '@/utils/strings';
1112
@@ -32,8 +33,10 @@ export async function getStaticPaths({ paginate }: GetStaticPathsOptions) {
3233
const { page } = Astro.props;
3334
const { category } = Astro.params;
3435
36+
const defaultMetadata = getPageMetadata('lists/blog/categories/category');
37+
3538
const title = capitalizeFirstLetter(category);
36-
const metadata: Metadata = { title };
39+
const metadata: Metadata = { ...defaultMetadata, title };
3740
3841
const paginationProps = pickPaginationPropsFromPage(page);
3942
const layoutProps = { metadata, paginationProps };

src/pages/blog/tags/[tag]/[...page].astro

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Link from '@/components/Link.astro';
66
import PostList from '@/components/PostList.astro';
77
import { ROUTES } from '@/constants/routes';
88
import { CONFIG } from '@/config';
9+
import { getPageMetadata } from '@/utils/metadata';
910
import { pickPaginationPropsFromPage } from '@/utils/pagination';
1011
1112
import type { Metadata } from '@/types/common';
@@ -31,9 +32,11 @@ export async function getStaticPaths({ paginate }: GetStaticPathsOptions) {
3132
const { page } = Astro.props;
3233
const { tag } = Astro.params;
3334
34-
// todo: dynamic param for metadata
3535
const title = `#${tag}`;
36-
const metadata: Metadata = { title };
36+
37+
// dynamic param for metadata
38+
const defaultMetadata = getPageMetadata('lists/blog/tags/tag');
39+
const metadata: Metadata = { ...defaultMetadata, title };
3740
3841
const paginationProps = pickPaginationPropsFromPage(page);
3942
const layoutProps = { metadata, paginationProps };

0 commit comments

Comments
 (0)