2021-07-08 00:15:27 +00:00
import { NextSeo } from 'next-seo'
import { useRouter } from 'next/router'
2023-07-25 00:50:55 +00:00
import removeMd from 'remove-markdown'
2024-03-20 00:37:31 +00:00
import { numWithUnits } from '@/lib/format'
2021-07-08 00:15:27 +00:00
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 = { {
2023-07-25 14:14:45 +00:00
title ,
2022-02-05 17:29:41 +00:00
description : desc ,
images : [
{
2023-07-15 16:17:16 +00:00
url : 'https://capture.stacker.news' + router . asPath
2022-02-05 17:29:41 +00:00
}
] ,
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 ) {
2023-07-25 00:50:55 +00:00
desc = removeMd ( item . text )
2021-07-08 00:15:27 +00:00
if ( desc ) {
desc = desc . replace ( /\s+/g , ' ' )
}
} else {
2023-08-08 21:04:06 +00:00
desc = ` @ ${ item . user . name } stacked ${ numWithUnits ( item . sats ) } ${ item . url ? ` posting ${ item . url } ` : 'with this discussion' } `
2021-09-10 21:13:52 +00:00
}
if ( item . ncomments ) {
2023-08-08 21:31:43 +00:00
desc += ` [ ${ numWithUnits ( item . ncomments , { unitSingular : 'comment' , unitPlural : 'comments' } )} `
2021-09-10 21:13:52 +00:00
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 ) {
2023-11-10 01:05:35 +00:00
desc = ` @ ${ user . name } has [ ${ user . optional . stacked ? ` ${ user . optional . stacked } stacked, ` : '' } ${ numWithUnits ( user . nitems , { unitSingular : 'item' , unitPlural : 'items' } )}] `
2021-07-08 00:15:27 +00:00
}
return (
< NextSeo
title = { fullTitle }
description = { desc }
openGraph = { {
title : fullTitle ,
description : desc ,
images : [
{
2023-07-15 16:17:16 +00:00
url : 'https://capture.stacker.news' + pathNoQuery
2021-07-08 00:15:27 +00:00
}
] ,
site _name : 'Stacker News'
} }
twitter = { {
site : '@stacker_news' ,
cardType : 'summary_large_image'
} }
/ >
)
}