Skip to content

Commit bcaaea6

Browse files
committed
title and description SEO replacements
- inject title, description and favicon on HEAD via DomainProvider - wip: replace title and desc for SEO only if we're on a custom domain and if they're present - wip: replace SnIcon Brand with domain logo upload - wip: replace favicon for notification with bland domain favicon logo upload
1 parent 01e5c89 commit bcaaea6

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

components/nav/common.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,19 @@ import { useWalletIndicator } from '@/wallets/indicator'
2626
import SwitchAccountList, { nextAccount, useAccounts } from '@/components/account'
2727
import { useShowModal } from '@/components/modal'
2828
import { numWithUnits } from '@/lib/format'
29+
import { useDomain } from '@/components/territory-domains'
2930

3031
export function Brand ({ className }) {
32+
// wip-branding: temporary logo branding concept
33+
const { domain } = useDomain()
34+
const branding = domain?.branding
35+
3136
return (
3237
<Link href='/' passHref legacyBehavior>
3338
<Navbar.Brand className={classNames(styles.brand, className)}>
34-
<SnIcon width={36} height={36} />
39+
{branding?.logoId
40+
? <img src={branding.logoId} alt={branding.title} style={{ width: '36px', height: '36px' }} />
41+
: <SnIcon width={36} height={36} />}
3542
</Navbar.Brand>
3643
</Link>
3744
)
@@ -119,12 +126,24 @@ export function NavSelect ({ sub: subName, className, size }) {
119126
}
120127

121128
export function NavNotifications ({ className }) {
129+
// wip-branding: temporary favicon branding concept
130+
const { domain } = useDomain()
131+
const branding = domain?.branding
132+
122133
const hasNewNotes = useHasNewNotes()
123134

124135
return (
125136
<>
126137
<Head>
127-
<link rel='shortcut icon' href={hasNewNotes ? '/favicon-notify.png' : '/favicon.png'} />
138+
<link
139+
rel='shortcut icon'
140+
// wip-branding: temporary favicon branding, doesn't support custom favicon with hasNewNotes
141+
href={hasNewNotes && !branding?.faviconId
142+
? '/favicon-notify.png'
143+
: branding?.faviconId
144+
? branding.faviconId
145+
: '/favicon.png'}
146+
/>
128147
</Head>
129148
<Link href='/notifications' passHref legacyBehavior>
130149
<Nav.Link eventKey='notifications' className={classNames('position-relative', className)}>

components/seo.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ import { NextSeo } from 'next-seo'
22
import { useRouter } from 'next/router'
33
import removeMd from 'remove-markdown'
44
import { numWithUnits } from '@/lib/format'
5+
import { useDomain } from '@/components/territory-domains'
56

67
export function SeoSearch ({ sub }) {
78
const router = useRouter()
8-
const subStr = sub ? ` ~${sub}` : ''
9-
const title = `${router.query.q || 'search'} \\ stacker news${subStr}`
10-
const desc = `SN${subStr} search: ${router.query.q || ''}`
9+
const { domain } = useDomain()
10+
11+
// wip-branding: temporary branding concept
12+
// if it's a territory with a custom domain, we don't want to show the sub in the title
13+
const subStr = sub && !domain ? ` ~${sub}` : ''
14+
const title = `${router.query.q || 'search'} \\ ${domain?.branding?.title || 'stacker news'}${subStr}`
15+
const desc = `${domain?.branding?.title || 'SN'}${subStr} search: ${router.query.q || ''}`
1116

1217
return (
1318
<NextSeo
@@ -21,7 +26,7 @@ export function SeoSearch ({ sub }) {
2126
url: 'https://capture.stacker.news' + router.asPath
2227
}
2328
],
24-
site_name: 'Stacker News'
29+
site_name: domain?.branding?.title || 'Stacker News'
2530
}}
2631
twitter={{
2732
site: '@stacker_news',
@@ -40,9 +45,13 @@ export default function Seo ({ sub, item, user }) {
4045
const router = useRouter()
4146
const pathNoQuery = router.asPath.split('?')[0]
4247
const defaultTitle = pathNoQuery.slice(1)
43-
const snStr = `stacker news${sub ? ` ~${sub}` : ''}`
44-
let fullTitle = `${defaultTitle && `${defaultTitle} \\ `}stacker news`
45-
let desc = "It's like Hacker News but we pay you Bitcoin."
48+
const { domain } = useDomain()
49+
// wip-branding: temporary branding concept
50+
// on custom domains, replace stacker news with the domain title if it exists,
51+
// also don't show sub in the title
52+
const snStr = `${domain?.branding?.title || 'stacker news'}${sub && !domain ? ` ~${sub}` : ''}`
53+
let fullTitle = `${defaultTitle && `${defaultTitle} \\ `}${domain?.branding?.title || 'stacker news'}`
54+
let desc = domain?.branding?.description || "It's like Hacker News but we pay you Bitcoin."
4655
if (item) {
4756
if (item.title) {
4857
fullTitle = `${item.title} \\ ${snStr}`
@@ -84,7 +93,7 @@ export default function Seo ({ sub, item, user }) {
8493
url: 'https://capture.stacker.news' + pathNoQuery
8594
}
8695
],
87-
site_name: 'Stacker News'
96+
site_name: domain?.branding?.title || 'Stacker News'
8897
}}
8998
twitter={{
9099
site: '@stacker_news',

components/territory-domains.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import ClipboardLine from '@/svgs/clipboard-line.svg'
1111
import RefreshLine from '@/svgs/refresh-line.svg'
1212
import styles from './item.module.css'
1313
import TerritoryBrandingForm from './territory-branding'
14+
import Head from 'next/head'
1415

1516
// Domain context for custom domains
1617
const DomainContext = createContext({
@@ -58,6 +59,12 @@ export const DomainProvider = ({ domain: ssrDomain, children }) => {
5859

5960
return (
6061
<DomainContext.Provider value={{ domain }}>
62+
{domain?.branding &&
63+
<Head>
64+
{domain.branding.title && <title>{domain.branding.title}</title>}
65+
{domain.branding.description && <meta name='description' content={domain.branding.description} />}
66+
{domain.branding.faviconId && <link rel='shortcut icon' href={domain.branding.faviconId} />}
67+
</Head>}
6168
{children}
6269
</DomainContext.Provider>
6370
)

0 commit comments

Comments
 (0)