Skip to content

Commit c56f038

Browse files
authored
Refine blog post single view and author styling (#5188)
1 parent b0f0083 commit c56f038

3 files changed

Lines changed: 88 additions & 10 deletions

File tree

website/src/css/customTheme.scss

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,43 @@ html[data-theme="dark"] .homepage {
754754

755755
/* Blog */
756756

757+
// Compact multi-author blog grid: two columns (one on the smallest screens),
758+
// capped to a narrow width on desktop rather than spanning the content.
759+
.col--6[class*="authorCol"] {
760+
--ifm-avatar-intro-margin: 0.7rem;
761+
762+
flex: 0 0 50%;
763+
764+
@media (max-width: 768px) {
765+
flex: 0 0 100%;
766+
}
767+
768+
[class*="authorImage"] {
769+
--ifm-avatar-photo-size: 1.75rem;
770+
}
771+
772+
[class*="authorName"] {
773+
font-size: 0.9rem;
774+
}
775+
776+
[class*="authorTitle"] {
777+
font-size: 0.75rem;
778+
779+
// Don't truncate long titles.
780+
display: block;
781+
overflow: visible;
782+
line-clamp: none;
783+
-webkit-line-clamp: none;
784+
}
785+
}
786+
787+
// Cap the grid on desktop only; tablet keeps the full-width two columns.
788+
@media (min-width: 997px) {
789+
.row:has(> [class*="authorCol"]) {
790+
max-width: 560px;
791+
}
792+
}
793+
757794
.avatar__name {
758795
font-weight: 600;
759796
display: inline-flex;

website/src/theme/BlogLayout/index.tsx

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,52 @@ import type {Props} from '@theme/BlogLayout';
99

1010
import React from 'react';
1111
import clsx from 'clsx';
12+
import {useLocation} from '@docusaurus/router';
1213
import Layout from '@theme/Layout';
1314
import BlogSidebar from '@theme/BlogSidebar';
1415
import DocsSecondaryNav from '@site/src/components/DocsSecondaryNav';
1516

17+
import styles from './styles.module.css';
18+
19+
// Individual posts live under a dated path; the index, pagination, tags,
20+
// archive and authors routes are the list-style pages that keep the sidebar.
21+
function useIsBlogPost() {
22+
const {pathname} = useLocation();
23+
return (
24+
pathname !== '/blog' &&
25+
pathname !== '/blog/' &&
26+
!pathname.startsWith('/blog/page/') &&
27+
!pathname.startsWith('/blog/tags') &&
28+
!pathname.startsWith('/blog/archive') &&
29+
!pathname.startsWith('/blog/authors')
30+
);
31+
}
32+
1633
// Ejected from @docusaurus/theme-classic to render the shared secondary nav
1734
// full-width below the main navbar, above the blog content.
1835
export default function BlogLayout(props: Props) {
1936
const {sidebar, toc, children, ...layoutProps} = props;
20-
const hasSidebar = sidebar && sidebar.items.length > 0;
37+
const isBlogPost = useIsBlogPost();
38+
// Individual posts drop the recent-posts sidebar and center their content.
39+
const showSidebar = !isBlogPost && sidebar && sidebar.items.length > 0;
40+
41+
let mainClassName;
42+
if (isBlogPost) {
43+
mainClassName = clsx('col', styles.blogPostMain);
44+
} else if (showSidebar) {
45+
mainClassName = clsx('col', 'col--7');
46+
} else {
47+
mainClassName = clsx('col', 'col--9', 'col--offset-1');
48+
}
2149

2250
return (
2351
<Layout {...layoutProps}>
2452
<DocsSecondaryNav />
2553
<div className="container margin-vert--lg">
2654
<div className="row">
27-
<BlogSidebar sidebar={sidebar} />
28-
<main
29-
className={clsx('col', {
30-
'col--7': hasSidebar,
31-
'col--9 col--offset-1': !hasSidebar,
32-
})}>
33-
{children}
34-
</main>
35-
{toc && <div className="col col--2">{toc}</div>}
55+
{showSidebar && <BlogSidebar sidebar={sidebar} />}
56+
<main className={mainClassName}>{children}</main>
57+
{toc && <div className={clsx('col', styles.tocColumn)}>{toc}</div>}
3658
</div>
3759
</div>
3860
</Layout>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
.blogPostMain {
9+
max-width: 800px;
10+
padding-block: 24px;
11+
margin-inline: auto;
12+
}
13+
14+
@media (min-width: 997px) {
15+
.tocColumn {
16+
flex: 0 0 200px;
17+
max-width: 200px;
18+
}
19+
}

0 commit comments

Comments
 (0)