-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathindex.tsx
More file actions
107 lines (101 loc) · 3 KB
/
Copy pathindex.tsx
File metadata and controls
107 lines (101 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import React from "react";
import clsx from "clsx";
import Translate, { translate } from "@docusaurus/Translate";
import {
PageMetadata,
HtmlClassNameProvider,
ThemeClassNames,
usePluralForm,
} from "@docusaurus/theme-common";
import Link from "@docusaurus/Link";
import BlogLayout from "@theme/BlogLayout";
import BlogListPaginator from "@theme/BlogListPaginator";
import SearchMetadata from "@theme/SearchMetadata";
import type { Props } from "@theme/BlogTagsPostsPage";
import BlogPostItems from "@theme/BlogPostItems";
import { pushGtmEvent } from "@site/src/utils/pushGtmEvent";
// Very simple pluralization: probably good enough for now
function useBlogPostsPlural() {
const { selectMessage } = usePluralForm();
return (count: number) =>
selectMessage(
count,
translate(
{
id: "theme.blog.post.plurals",
description:
'Pluralized label for "{count} posts". Use as much plural forms (separated by "|") as your language support (see https://www.unicode.org/cldr/cldr-aux/charts/34/supplemental/language_plural_rules.html)',
message: "One post|{count} posts",
},
{ count },
),
);
}
function useBlogTagsPostsPageTitle(tag: Props["tag"]): string {
const blogPostsPlural = useBlogPostsPlural();
return translate(
{
id: "theme.blog.tagTitle",
description: "The title of the page for a blog tag",
message: '{nPosts} tagged with "{tagName}"',
},
{ nPosts: blogPostsPlural(tag.count), tagName: tag.label },
);
}
function BlogTagsPostsPageMetadata({ tag }: Props): JSX.Element {
const title = useBlogTagsPostsPageTitle(tag);
return (
<>
<PageMetadata title={title} />
<SearchMetadata tag="blog_tags_posts" />
</>
);
}
function BlogTagsPostsPageContent({
tag,
items,
sidebar,
listMetadata,
}: Props): JSX.Element {
const title = useBlogTagsPostsPageTitle(tag);
React.useEffect(() => {
const pageViewData = {
event: "Initialize_dataLayer",
document_type: "Blog",
document_title: document.title,
article_author: undefined,
tags: undefined,
};
pushGtmEvent(pageViewData);
}, []);
return (
<BlogLayout sidebar={sidebar}>
<header className="margin-bottom--xl">
<h1>{title}</h1>
<Link href={tag.allTagsPath}>
<Translate
id="theme.tags.tagsPageLink"
description="The label of the link targeting the tag list page"
>
View All Tags
</Translate>
</Link>
</header>
<BlogPostItems items={items} />
<BlogListPaginator metadata={listMetadata} />
</BlogLayout>
);
}
export default function BlogTagsPostsPage(props: Props): JSX.Element {
return (
<HtmlClassNameProvider
className={clsx(
ThemeClassNames.wrapper.blogPages,
ThemeClassNames.page.blogTagPostListPage,
)}
>
<BlogTagsPostsPageMetadata {...props} />
<BlogTagsPostsPageContent {...props} />
</HtmlClassNameProvider>
);
}