Skip to content

Commit c8c9e33

Browse files
committed
Add custom logo to header
1 parent 1fdecd6 commit c8c9e33

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed

components/NotionPageHeader.tsx

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@ import { IoSunnyOutline } from '@react-icons/all-files/io5/IoSunnyOutline'
44
import { IoMoonSharp } from '@react-icons/all-files/io5/IoMoonSharp'
55
import { Header, Breadcrumbs, Search, useNotionContext } from 'react-notion-x'
66
import * as types from 'notion-types'
7+
import Image from 'next/image'
78

89
import { useDarkMode } from 'lib/use-dark-mode'
9-
import { navigationStyle, navigationLinks, isSearchEnabled } from 'lib/config'
10+
import {
11+
navigationStyle,
12+
navigationLinks,
13+
isSearchEnabled,
14+
customHeaderLogo,
15+
customHeaderLogoDark,
16+
rootNotionPageId
17+
} from 'lib/config'
1018

1119
import styles from './styles.module.css'
1220

@@ -32,6 +40,48 @@ const ToggleThemeButton = () => {
3240
)
3341
}
3442

43+
export const HeaderLogo: React.FC<{
44+
block: types.CollectionViewPageBlock | types.PageBlock
45+
}> = ({ block }) => {
46+
const { components, mapPageUrl } = useNotionContext()
47+
48+
const { isDarkMode } = useDarkMode()
49+
50+
const LinkWrapper = (props: {
51+
currentPage: string
52+
children: JSX.Element
53+
}) => {
54+
if (props.currentPage !== '/') {
55+
return (
56+
<components.PageLink
57+
href={mapPageUrl(rootNotionPageId)}
58+
key={0}
59+
className={cs(styles.navLink, 'breadcrumb', 'button')}
60+
>
61+
{props.children}
62+
</components.PageLink>
63+
)
64+
}
65+
return props.children
66+
}
67+
68+
return (
69+
<LinkWrapper currentPage={mapPageUrl(block.id)}>
70+
<Image
71+
src={
72+
isDarkMode && customHeaderLogoDark
73+
? customHeaderLogoDark
74+
: customHeaderLogo
75+
}
76+
width='100%'
77+
height='100%'
78+
objectFit='contain'
79+
alt='logo'
80+
/>
81+
</LinkWrapper>
82+
)
83+
}
84+
3585
export const NotionPageHeader: React.FC<{
3686
block: types.CollectionViewPageBlock | types.PageBlock
3787
}> = ({ block }) => {
@@ -44,7 +94,11 @@ export const NotionPageHeader: React.FC<{
4494
return (
4595
<header className='notion-header'>
4696
<div className='notion-nav-header'>
47-
<Breadcrumbs block={block} rootOnly={true} />
97+
{customHeaderLogo ? (
98+
<HeaderLogo block={block} />
99+
) : (
100+
<Breadcrumbs block={block} rootOnly={true} />
101+
)}
48102

49103
<div className='notion-nav-header-rhs breadcrumbs'>
50104
{navigationLinks

lib/config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ export const linkedin: string | null = getSiteConfig('linkedin', null)
6161
export const newsletter: string | null = getSiteConfig('newsletter', null)
6262
export const zhihu: string | null = getSiteConfig('zhihu', null)
6363

64+
// default logo values
65+
export const customHeaderLogo: string | null = getSiteConfig(
66+
'customHeaderLogo',
67+
null
68+
)
69+
export const customHeaderLogoDark: string | null = getSiteConfig(
70+
'customHeaderLogoDark',
71+
null
72+
)
73+
6474
// default notion values for site-wide consistency (optional; may be overridden on a per-page basis)
6575
export const defaultPageIcon: string | null = getSiteConfig(
6676
'defaultPageIcon',

lib/site-config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export interface SiteConfig {
1717
youtube?: string
1818
zhihu?: string
1919

20+
customHeaderLogo?: string | null
21+
customHeaderLogoDark?: string | null
22+
2023
defaultPageIcon?: string | null
2124
defaultPageCover?: string | null
2225
defaultPageCoverPosition?: number | null

site.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export default siteConfig({
2323
// newsletter: '#', // optional newsletter URL
2424
// youtube: '#', // optional youtube channel name or `channel/UCGbXXXXXXXXXXXXXXXXXXXXXX`
2525

26+
// Custom logo - this will replace the breadcrumbs
27+
// customHeaderLogo: 'https://cdn.logo.com/hotlink-ok/logo-social.png',
28+
// customHeaderLogoDark: 'https://alexchaveriat-com.vercel.app/logo-dark.png',
29+
2630
// default notion icon and cover images for site-wide consistency (optional)
2731
// page-specific values will override these site-wide defaults
2832
defaultPageIcon: null,

0 commit comments

Comments
 (0)