Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom header and footer #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 140 additions & 100 deletions components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import * as config from '@/lib/config'
import { useDarkMode } from '@/lib/use-dark-mode'

import styles from './styles.module.css'
import { StaticLogo } from './StaticLogo'
import { footerLinks } from '@/lib/config'
import { useNotionContext } from 'react-notion-x'
import cs from 'classnames'

// TODO: merge the data and icons from PageSocial with the social links in Footer

Expand All @@ -33,109 +37,145 @@ export function FooterImpl() {
setHasMounted(true)
}, [])

const { components, mapPageUrl } = useNotionContext()

return (
<footer className={styles.footer}>
<div className={styles.copyright}>
Copyright {currentYear} {config.author}
</div>

<div className={styles.settings}>
{hasMounted && (
<a
className={styles.toggleDarkMode}
href='#'
role='button'
onClick={onToggleDarkMode}
title='Toggle dark mode'
>
{isDarkMode ? <IoMoonSharp /> : <IoSunnyOutline />}
</a>
)}
<div className={styles.footerSocial}>
<StaticLogo />

<div className={cs(styles.settings,styles.toggleDarkModeContainer)}>
{hasMounted && (
<a
className={styles.toggleDarkMode}
href='#'
role='button'
onClick={onToggleDarkMode}
title='Toggle dark mode'
>
{isDarkMode ? <IoMoonSharp /> : <IoSunnyOutline />}
</a>
)}
</div>

<div className={styles.social}>
{config.twitter && (
<a
className={styles.twitter}
href={`https://twitter.com/${config.twitter}`}
title={`Twitter @${config.twitter}`}
target='_blank'
rel='noopener noreferrer'
>
<FaTwitter />
</a>
)}

{config.mastodon && (
<a
className={styles.mastodon}
href={config.mastodon}
title={`Mastodon ${config.getMastodonHandle()}`}
rel='me'
>
<FaMastodon />
</a>
)}

{config.zhihu && (
<a
className={styles.zhihu}
href={`https://zhihu.com/people/${config.zhihu}`}
title={`Zhihu @${config.zhihu}`}
target='_blank'
rel='noopener noreferrer'
>
<FaZhihu />
</a>
)}

{config.github && (
<a
className={styles.github}
href={`https://github.com/${config.github}`}
title={`GitHub @${config.github}`}
target='_blank'
rel='noopener noreferrer'
>
<FaGithub />
</a>
)}

{config.linkedin && (
<a
className={styles.linkedin}
href={`https://www.linkedin.com/in/${config.linkedin}`}
title={`LinkedIn ${config.author}`}
target='_blank'
rel='noopener noreferrer'
>
<FaLinkedin />
</a>
)}

{config.newsletter && (
<a
className={styles.newsletter}
href={`${config.newsletter}`}
title={`Newsletter ${config.author}`}
target='_blank'
rel='noopener noreferrer'
>
<FaEnvelopeOpenText />
</a>
)}

{config.youtube && (
<a
className={styles.youtube}
href={`https://www.youtube.com/${config.youtube}`}
title={`YouTube ${config.author}`}
target='_blank'
rel='noopener noreferrer'
>
<FaYoutube />
</a>
)}
</div>
</div>

<div className={styles.social}>
{config.twitter && (
<a
className={styles.twitter}
href={`https://twitter.com/${config.twitter}`}
title={`Twitter @${config.twitter}`}
target='_blank'
rel='noopener noreferrer'
>
<FaTwitter />
</a>
)}

{config.mastodon && (
<a
className={styles.mastodon}
href={config.mastodon}
title={`Mastodon ${config.getMastodonHandle()}`}
rel='me'
>
<FaMastodon />
</a>
)}

{config.zhihu && (
<a
className={styles.zhihu}
href={`https://zhihu.com/people/${config.zhihu}`}
title={`Zhihu @${config.zhihu}`}
target='_blank'
rel='noopener noreferrer'
>
<FaZhihu />
</a>
)}

{config.github && (
<a
className={styles.github}
href={`https://github.com/${config.github}`}
title={`GitHub @${config.github}`}
target='_blank'
rel='noopener noreferrer'
>
<FaGithub />
</a>
)}

{config.linkedin && (
<a
className={styles.linkedin}
href={`https://www.linkedin.com/in/${config.linkedin}`}
title={`LinkedIn ${config.author}`}
target='_blank'
rel='noopener noreferrer'
>
<FaLinkedin />
</a>
)}

{config.newsletter && (
<a
className={styles.newsletter}
href={`${config.newsletter}`}
title={`Newsletter ${config.author}`}
target='_blank'
rel='noopener noreferrer'
>
<FaEnvelopeOpenText />
</a>
)}

{config.youtube && (
<a
className={styles.youtube}
href={`https://www.youtube.com/${config.youtube}`}
title={`YouTube ${config.author}`}
target='_blank'
rel='noopener noreferrer'
>
<FaYoutube />
</a>
)}
<div className="SiteInfo">
<div className={styles.siteInfoLinks}>
{footerLinks
?.map((link, index) => {
if (!link.pageId && !link.url) {
return null
}

if (link.pageId) {
return (
<components.PageLink
href={mapPageUrl(link.pageId)}
key={index}
className={cs(styles.navLink, 'breadcrumb', 'button')}
>
{link.title}
</components.PageLink>
)
} else {
return (
<components.Link
href={link.url}
key={index}
className={cs(styles.navLink, 'breadcrumb', 'button')}
>
{link.title}
</components.Link>
)
}
})
.filter(Boolean)}
</div>
<div className={styles.copyright}>© Copyright {currentYear}. All rights reserved.</div>
</div>
</footer>
)
Expand Down
6 changes: 4 additions & 2 deletions components/NotionPageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { isSearchEnabled, navigationLinks, navigationStyle } from '@/lib/config'
import { useDarkMode } from '@/lib/use-dark-mode'

import styles from './styles.module.css'
import { StaticLogo } from './StaticLogo'

function ToggleThemeButton() {
const [hasMounted, setHasMounted] = React.useState(false)
Expand Down Expand Up @@ -46,8 +47,9 @@ export function NotionPageHeader({
return (
<header className='notion-header'>
<div className='notion-nav-header'>
<Breadcrumbs block={block} rootOnly={true} />

<div className="notion-nav-header-rhs breadcrumbs">
<StaticLogo />
</div>
<div className='notion-nav-header-rhs breadcrumbs'>
{navigationLinks
?.map((link, index) => {
Expand Down
28 changes: 28 additions & 0 deletions components/StaticLogo.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.logo {
height: 75%;
margin-right: 5px;
border-radius: 50%;
display: flex;
}

.logo img {
max-height: 50px;
max-width: 50px;
object-fit: contain;
}
.logo > * {
display: inline-flex;
font-weight: 500;
padding-right: 0.1em;
font-size: 2em;
align-items: center;
justify-content: center;
white-space: nowrap;
text-overflow: ellipsis;
}

@media only screen and (max-width: 660px) {
.logo {
justify-content: center;
}
}
13 changes: 13 additions & 0 deletions components/StaticLogo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as config from '@/lib/config'
import cs from 'classnames'

import styles from './StaticLogo.module.css'

export function StaticLogo() {
return (
<a className={cs(styles.logo, styles.link)} href={config.host} rel="home" title="Logo">
<img src="/favicon.png"/>
<span>{config.name}</span>
</a>
)
}
37 changes: 36 additions & 1 deletion components/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,31 @@
max-width: 1100px;
margin: auto auto 0;
padding: 8px;
}

.footerSocial {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}

.siteInfoLinks {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}

.siteInfoLinks a {
margin: 0.5em;
text-align: center;
}

.copyright {
font-size: 80%;
padding: 0.5em;
text-align: center;
}

.settings,
Expand Down Expand Up @@ -124,11 +139,31 @@
border-top: 1px solid var(--fg-color-0);
}

@media only screen and (max-width: 566px) {
@media only screen and (min-width: 661px) {
/* Position the dark mode / light mode button in the middle of the screen no matter what */
.footer .toggleDarkModeContainer {
position: absolute;
left: 50%;
transform: translateX(-50%);
z-index: 1; /* Ensure the centered item overlays the others */
}
}

@media only screen and (max-width: 660px) {
.footer {
flex-direction: column;
}

.footer .footerSocial {
flex-direction: column-reverse;
}

.footer .link {
display: flex;
align-items: center;
justify-content: center;
}

.footer > div {
margin-top: 1em;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ export const navigationLinks: Array<NavigationLink | null> = getSiteConfig(
null
)

export const footerLinks: Array<NavigationLink | null> = getSiteConfig(
'footerLinks',
null
)

// Optional site search
export const isSearchEnabled: boolean = getSiteConfig('isSearchEnabled', true)

Expand Down
Loading
Loading