Skip to content

Commit c38d25c

Browse files
1 parent 45b20d9 commit c38d25c

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

components/Footer.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import styles from './styles.module.css'
1313
// TODO: merge the data and icons from PageSocial with the social links in Footer
1414

1515
export const FooterImpl: React.FC = () => {
16+
const [hasMounted, setHasMounted] = React.useState(false)
1617
const darkMode = useDarkMode(false, { classNameDark: 'dark-mode' })
1718

1819
const onToggleDarkMode = React.useCallback(
@@ -23,19 +24,25 @@ export const FooterImpl: React.FC = () => {
2324
[darkMode]
2425
)
2526

27+
React.useEffect(() => {
28+
setHasMounted(true)
29+
}, [])
30+
2631
return (
2732
<footer className={styles.footer}>
2833
<div className={styles.copyright}>Copyright 2022 {config.author}</div>
2934

3035
<div className={styles.settings}>
31-
<a
32-
className={styles.toggleDarkMode}
33-
href='#'
34-
role='button'
35-
onClick={onToggleDarkMode}
36-
>
37-
{darkMode.value ? <IoMoonSharp /> : <IoSunnyOutline />}
38-
</a>
36+
{hasMounted && (
37+
<a
38+
className={styles.toggleDarkMode}
39+
href='#'
40+
role='button'
41+
onClick={onToggleDarkMode}
42+
>
43+
{darkMode.value ? <IoMoonSharp /> : <IoSunnyOutline />}
44+
</a>
45+
)}
3946
</div>
4047

4148
<div className={styles.social}>

lib/notion.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pMap from 'p-map'
2+
import pMemoize from 'p-memoize'
23
import { ExtendedRecordMap, SearchParams, SearchResults } from 'notion-types'
34
import { mergeRecordMaps } from 'notion-utils'
45

@@ -12,16 +13,14 @@ import {
1213
navigationLinks
1314
} from './config'
1415

15-
export async function getPage(pageId: string): Promise<ExtendedRecordMap> {
16-
let recordMap = await notion.getPage(pageId)
17-
18-
if (navigationStyle !== 'default') {
16+
const getNavigationLinkPages = pMemoize(
17+
async (): Promise<ExtendedRecordMap[]> => {
1918
const navigationLinkPageIds = (navigationLinks || [])
2019
.map((link) => link.pageId)
2120
.filter(Boolean)
2221

23-
if (navigationLinkPageIds.length) {
24-
const navigationLinkRecordMaps: ExtendedRecordMap[] = await pMap(
22+
if (navigationStyle !== 'default' && navigationLinkPageIds.length) {
23+
return pMap(
2524
navigationLinkPageIds,
2625
async (navigationLinkPageId) =>
2726
notion.getPage(navigationLinkPageId, {
@@ -33,7 +32,22 @@ export async function getPage(pageId: string): Promise<ExtendedRecordMap> {
3332
concurrency: 4
3433
}
3534
)
35+
}
36+
37+
return []
38+
}
39+
)
40+
41+
export async function getPage(pageId: string): Promise<ExtendedRecordMap> {
42+
let recordMap = await notion.getPage(pageId)
43+
44+
if (navigationStyle !== 'default') {
45+
// ensure that any pages linked to in the custom navigation header have
46+
// their block info fully resolved in the page record map so we know
47+
// the page title, slug, etc.
48+
const navigationLinkRecordMaps = await getNavigationLinkPages()
3649

50+
if (navigationLinkRecordMaps?.length) {
3751
recordMap = navigationLinkRecordMaps.reduce(
3852
(map, navigationLinkRecordMap) =>
3953
mergeRecordMaps(map, navigationLinkRecordMap),

site.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ export default siteConfig({
4545
// }
4646
pageUrlOverrides: null,
4747

48+
// whether to use the default notion navigation style or a custom one with links to
49+
// important pages
50+
// navigationStyle: 'default'
4851
navigationStyle: 'custom',
4952
navigationLinks: [
5053
{

0 commit comments

Comments
 (0)