Skip to content

Commit 45576b9

Browse files
committed
Refine blog post single view and author styling
1 parent 3d833c7 commit 45576b9

3 files changed

Lines changed: 78 additions & 9 deletions

File tree

website/src/css/customTheme.scss

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

755755
/* Blog */
756756

757+
// Compact multi-author blog grid: three-up at the widest (fixed-width) layout,
758+
// two-up on smaller desktops, one-up on mobile.
759+
.col--6[class*="authorCol"] {
760+
--ifm-avatar-intro-margin: 0.7rem;
761+
762+
flex: 0 0 33.3333%;
763+
764+
// 1416px is where the site header locks to a fixed width.
765+
@media (max-width: 1416px) {
766+
flex: 0 0 50%;
767+
}
768+
769+
@media (max-width: 768px) {
770+
flex: 0 0 100%;
771+
}
772+
773+
[class*="authorImage"] {
774+
--ifm-avatar-photo-size: 1.75rem;
775+
}
776+
777+
[class*="authorName"] {
778+
font-size: 0.9rem;
779+
}
780+
781+
[class*="authorTitle"] {
782+
font-size: 0.75rem;
783+
784+
// Don't truncate long titles.
785+
display: block;
786+
overflow: visible;
787+
line-clamp: none;
788+
-webkit-line-clamp: none;
789+
}
790+
}
791+
757792
.avatar__name {
758793
font-weight: 600;
759794
display: inline-flex;

website/src/theme/BlogLayout/index.tsx

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,51 @@ 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', 'col--7', 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>
55+
{showSidebar && <BlogSidebar sidebar={sidebar} />}
56+
<main className={mainClassName}>{children}</main>
3557
{toc && <div className="col col--2">{toc}</div>}
3658
</div>
3759
</div>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
/* Center the post content in the space left of the TOC now that the recent-
9+
posts sidebar is gone, while keeping its column width. */
10+
.blogPostMain {
11+
margin-inline: auto;
12+
}

0 commit comments

Comments
 (0)