Skip to content

Commit 3fc9f06

Browse files
committed
Merge branch 'pr/325'
2 parents 3b3490e + 2833a93 commit 3fc9f06

File tree

4 files changed

+77
-18
lines changed

4 files changed

+77
-18
lines changed

components/NotionPageHeader.tsx

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import * as React from 'react'
2-
3-
import * as types from 'notion-types'
4-
import { IoMoonSharp } from '@react-icons/all-files/io5/IoMoonSharp'
5-
import { IoSunnyOutline } from '@react-icons/all-files/io5/IoSunnyOutline'
62
import cs from 'classnames'
7-
import { Breadcrumbs, Header, Search, useNotionContext } from 'react-notion-x'
3+
import { IoSunnyOutline } from '@react-icons/all-files/io5/IoSunnyOutline'
4+
import { IoMoonSharp } from '@react-icons/all-files/io5/IoMoonSharp'
5+
import { Header, Breadcrumbs, Search, useNotionContext } from 'react-notion-x'
6+
import * as types from 'notion-types'
7+
import Image from 'next/image'
88

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

1219
import styles from './styles.module.css'
1320

@@ -33,6 +40,48 @@ const ToggleThemeButton = () => {
3340
)
3441
}
3542

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 <div style={{ padding: 12, display: 'flex' }}>{props.children}</div>
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+
3685
export const NotionPageHeader: React.FC<{
3786
block: types.CollectionViewPageBlock | types.PageBlock
3887
}> = ({ block }) => {
@@ -45,7 +94,11 @@ export const NotionPageHeader: React.FC<{
4594
return (
4695
<header className='notion-header'>
4796
<div className='notion-nav-header'>
48-
<Breadcrumbs block={block} rootOnly={true} />
97+
{customHeaderLogo ? (
98+
<HeaderLogo block={block} />
99+
) : (
100+
<Breadcrumbs block={block} rootOnly={true} />
101+
)}
49102

50103
<div className='notion-nav-header-rhs breadcrumbs'>
51104
{navigationLinks

lib/config.ts

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

65-
export const getMastodonHandle = (): string | null => {
66-
if (!mastodon) {
67-
return null
68-
}
69-
70-
// Since Mastodon is decentralized, handles include the instance domain name.
71-
// e.g. @example@mastodon.social
72-
const url = new URL(mastodon)
73-
return `${url.pathname.slice(1)}@${url.hostname}`
74-
}
65+
// default logo values
66+
export const customHeaderLogo: string | null = getSiteConfig(
67+
'customHeaderLogo',
68+
null
69+
)
70+
export const customHeaderLogoDark: string | null = getSiteConfig(
71+
'customHeaderLogoDark',
72+
null
73+
)
7574

7675
// default notion values for site-wide consistency (optional; may be overridden on a per-page basis)
7776
export const defaultPageIcon: string | null = getSiteConfig(

lib/site-config.ts

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

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

site.config.ts

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

27+
// Custom logo - this will replace the breadcrumbs - Feature requires navigationStyle: 'custom'
28+
// customHeaderLogo: 'https://transitivebullsh.it/logo.png',
29+
// customHeaderLogoDark: 'https://transitivebullsh.it/logo-dark.png', // optional
30+
2731
// default notion icon and cover images for site-wide consistency (optional)
2832
// page-specific values will override these site-wide defaults
2933
defaultPageIcon: null,

0 commit comments

Comments
 (0)