@@ -9,30 +9,52 @@ import type {Props} from '@theme/BlogLayout';
99
1010import React from 'react' ;
1111import clsx from 'clsx' ;
12+ import { useLocation } from '@docusaurus/router' ;
1213import Layout from '@theme/Layout' ;
1314import BlogSidebar from '@theme/BlogSidebar' ;
1415import 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.
1835export 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 >
0 commit comments