2021-07-08 00:15:27 +00:00
|
|
|
import { NextSeo } from 'next-seo'
|
|
|
|
import { useRouter } from 'next/router'
|
|
|
|
import RemoveMarkdown from 'remove-markdown'
|
|
|
|
|
2022-02-17 17:23:43 +00:00
|
|
|
export function SeoSearch ({ sub }) {
|
2022-02-05 17:29:41 +00:00
|
|
|
const router = useRouter()
|
2022-02-17 17:23:43 +00:00
|
|
|
const subStr = sub ? ` ~${sub}` : ''
|
2022-05-18 21:09:44 +00:00
|
|
|
const title = `${router.query.q || 'search'} \\ stacker news${subStr}`
|
|
|
|
const desc = `SN${subStr} search: ${router.query.q || ''}`
|
2022-02-05 17:29:41 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<NextSeo
|
|
|
|
title={title}
|
|
|
|
description={desc}
|
|
|
|
openGraph={{
|
|
|
|
title: title,
|
|
|
|
description: desc,
|
|
|
|
images: [
|
|
|
|
{
|
|
|
|
url: 'https://stacker.news/api/capture' + router.asPath
|
|
|
|
}
|
|
|
|
],
|
|
|
|
site_name: 'Stacker News'
|
|
|
|
}}
|
|
|
|
twitter={{
|
|
|
|
site: '@stacker_news',
|
|
|
|
cardType: 'summary_large_image'
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-02-17 17:23:43 +00:00
|
|
|
// for a sub we need
|
|
|
|
// item seo
|
|
|
|
// index page seo
|
|
|
|
// recent page seo
|
|
|
|
|
|
|
|
export default function Seo ({ sub, item, user }) {
|
2021-07-08 00:15:27 +00:00
|
|
|
const router = useRouter()
|
|
|
|
const pathNoQuery = router.asPath.split('?')[0]
|
|
|
|
const defaultTitle = pathNoQuery.slice(1)
|
2022-02-17 17:23:43 +00:00
|
|
|
const snStr = `stacker news${sub ? ` ~${sub}` : ''}`
|
2021-07-08 00:15:27 +00:00
|
|
|
let fullTitle = `${defaultTitle && `${defaultTitle} \\ `}stacker news`
|
2021-08-17 18:15:24 +00:00
|
|
|
let desc = "It's like Hacker News but we pay you Bitcoin."
|
2021-07-08 00:15:27 +00:00
|
|
|
if (item) {
|
|
|
|
if (item.title) {
|
2022-02-17 17:23:43 +00:00
|
|
|
fullTitle = `${item.title} \\ ${snStr}`
|
2021-07-08 00:15:27 +00:00
|
|
|
} else if (item.root) {
|
2022-02-17 17:23:43 +00:00
|
|
|
fullTitle = `reply on: ${item.root.title} \\ ${snStr}`
|
2021-07-08 00:15:27 +00:00
|
|
|
}
|
2022-02-17 17:23:43 +00:00
|
|
|
// at least for now subs (ie the only one is jobs) will always have text
|
2021-07-08 00:15:27 +00:00
|
|
|
if (item.text) {
|
|
|
|
desc = RemoveMarkdown(item.text)
|
|
|
|
if (desc) {
|
|
|
|
desc = desc.replace(/\s+/g, ' ')
|
|
|
|
}
|
|
|
|
} else {
|
2022-01-20 23:04:12 +00:00
|
|
|
desc = `@${item.user.name} stacked ${item.sats} sats ${item.url ? `posting ${item.url}` : 'with this discussion'}`
|
2021-09-10 21:13:52 +00:00
|
|
|
}
|
|
|
|
if (item.ncomments) {
|
|
|
|
desc += ` [${item.ncomments} comments`
|
|
|
|
if (item.boost) {
|
|
|
|
desc += `, ${item.boost} boost`
|
|
|
|
}
|
|
|
|
desc += ']'
|
|
|
|
} else if (item.boost) {
|
|
|
|
desc += ` [${item.boost} boost]`
|
2021-07-08 00:15:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (user) {
|
2021-12-30 22:02:18 +00:00
|
|
|
desc = `@${user.name} has [${user.stacked} stacked, ${user.nitems} posts, ${user.ncomments} comments]`
|
2021-07-08 00:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<NextSeo
|
|
|
|
title={fullTitle}
|
|
|
|
description={desc}
|
|
|
|
openGraph={{
|
|
|
|
title: fullTitle,
|
|
|
|
description: desc,
|
|
|
|
images: [
|
|
|
|
{
|
|
|
|
url: 'https://stacker.news/api/capture' + pathNoQuery
|
|
|
|
}
|
|
|
|
],
|
|
|
|
site_name: 'Stacker News'
|
|
|
|
}}
|
|
|
|
twitter={{
|
|
|
|
site: '@stacker_news',
|
|
|
|
cardType: 'summary_large_image'
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|