Skip to content

Commit 78170bb

Browse files
committed
feat(blog): Use smaller headers + auto split headers on :
1 parent 768c46d commit 78170bb

2 files changed

Lines changed: 113 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from 'react';
2+
import clsx from 'clsx';
3+
import Title from '@theme-original/BlogPostItem/Header/Title';
4+
import type TitleType from '@theme/BlogPostItem/Header/Title';
5+
import type {WrapperProps} from '@docusaurus/types';
6+
import Link from '@docusaurus/Link';
7+
import {useBlogPost} from '@docusaurus/theme-common/internal';
8+
import styles from './styles.module.css';
9+
10+
type Props = WrapperProps<typeof TitleType>;
11+
12+
export default function TitleWrapper(props: Props): JSX.Element {
13+
const {isBlogPostPage, metadata, frontMatter} = useBlogPost();
14+
const splitEnabled =
15+
(frontMatter as {splitTitle?: boolean}).splitTitle !== false;
16+
17+
if (splitEnabled) {
18+
const title = metadata.title;
19+
const colonIdx = title.indexOf(':');
20+
if (colonIdx > 0 && colonIdx < title.length - 1) {
21+
const main = title.slice(0, colonIdx).trim();
22+
const secondary = title.slice(colonIdx + 1).trim();
23+
const TitleHeading = isBlogPostPage ? 'h1' : 'h2';
24+
const body = (
25+
<>
26+
<span className={styles.main}>{main}</span>
27+
<span className={styles.secondary}>{secondary}</span>
28+
</>
29+
);
30+
return (
31+
<TitleHeading
32+
className={clsx(
33+
styles.title,
34+
isBlogPostPage && styles.titlePost,
35+
props.className,
36+
)}>
37+
{isBlogPostPage ? (
38+
body
39+
) : (
40+
<Link to={metadata.permalink} className={styles.link}>
41+
{body}
42+
</Link>
43+
)}
44+
</TitleHeading>
45+
);
46+
}
47+
}
48+
49+
return <Title {...props} />;
50+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
.title {
2+
margin: 0 0 0.5rem;
3+
font-size: 1rem;
4+
line-height: 1.2;
5+
}
6+
7+
.link {
8+
text-decoration: none;
9+
color: inherit;
10+
display: block;
11+
}
12+
13+
.link:hover {
14+
text-decoration: none;
15+
}
16+
17+
/* Listing view (h2) */
18+
.main {
19+
display: block;
20+
font-size: 2rem;
21+
line-height: 1.2;
22+
color: var(--ifm-color-primary-darkest);
23+
}
24+
25+
.link:hover .main {
26+
color: var(--ifm-color-primary);
27+
}
28+
29+
.secondary {
30+
display: block;
31+
font-size: 1.25rem;
32+
font-weight: 500;
33+
line-height: 1.3;
34+
margin-top: 0.25rem;
35+
color: var(--ifm-color-emphasis-700);
36+
}
37+
38+
/* Individual post page (h1) */
39+
.titlePost .main {
40+
font-size: 2.5rem;
41+
line-height: 1.15;
42+
}
43+
44+
.titlePost .secondary {
45+
font-size: 1.5rem;
46+
line-height: 1.25;
47+
margin-top: 0.4rem;
48+
}
49+
50+
@media (max-width: 576px) {
51+
.main {
52+
font-size: 1.5rem;
53+
}
54+
.secondary {
55+
font-size: 1rem;
56+
}
57+
.titlePost .main {
58+
font-size: 2rem;
59+
}
60+
.titlePost .secondary {
61+
font-size: 1.25rem;
62+
}
63+
}

0 commit comments

Comments
 (0)