add search SEO and capture
This commit is contained in:
parent
80b8744b8e
commit
8c2a4dc76a
|
@ -2,6 +2,33 @@ import { NextSeo } from 'next-seo'
|
|||
import { useRouter } from 'next/router'
|
||||
import RemoveMarkdown from 'remove-markdown'
|
||||
|
||||
export function SeoSearch () {
|
||||
const router = useRouter()
|
||||
const title = `${router.query.q} \\ stacker news`
|
||||
const desc = `SN search: ${router.query.q}`
|
||||
|
||||
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'
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export default function Seo ({ item, user }) {
|
||||
const router = useRouter()
|
||||
const pathNoQuery = router.asPath.split('?')[0]
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
"next-plausible": "^2.1.3",
|
||||
"next-seo": "^4.24.0",
|
||||
"nextjs-progressbar": "^0.0.13",
|
||||
"node-s3-url-encode": "^0.0.4",
|
||||
"page-metadata-parser": "^1.1.4",
|
||||
"pageres": "^6.2.3",
|
||||
"pg-boss": "^7.0.2",
|
||||
|
@ -7826,6 +7827,11 @@
|
|||
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.76.tgz",
|
||||
"integrity": "sha512-9/IECtNr8dXNmPWmFXepT0/7o5eolGesHUa3mtr0KlgnCvnZxwh2qensKL42JJY2vQKC3nIBXetFAqR+PW1CmA=="
|
||||
},
|
||||
"node_modules/node-s3-url-encode": {
|
||||
"version": "0.0.4",
|
||||
"resolved": "https://registry.npmjs.org/node-s3-url-encode/-/node-s3-url-encode-0.0.4.tgz",
|
||||
"integrity": "sha1-VWD8abweqQ46THhB8jPSAHU3hQM="
|
||||
},
|
||||
"node_modules/nodemailer": {
|
||||
"version": "6.6.5",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.6.5.tgz",
|
||||
|
@ -18583,6 +18589,11 @@
|
|||
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.76.tgz",
|
||||
"integrity": "sha512-9/IECtNr8dXNmPWmFXepT0/7o5eolGesHUa3mtr0KlgnCvnZxwh2qensKL42JJY2vQKC3nIBXetFAqR+PW1CmA=="
|
||||
},
|
||||
"node-s3-url-encode": {
|
||||
"version": "0.0.4",
|
||||
"resolved": "https://registry.npmjs.org/node-s3-url-encode/-/node-s3-url-encode-0.0.4.tgz",
|
||||
"integrity": "sha1-VWD8abweqQ46THhB8jPSAHU3hQM="
|
||||
},
|
||||
"nodemailer": {
|
||||
"version": "6.6.5",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.6.5.tgz",
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
"next-plausible": "^2.1.3",
|
||||
"next-seo": "^4.24.0",
|
||||
"nextjs-progressbar": "^0.0.13",
|
||||
"node-s3-url-encode": "^0.0.4",
|
||||
"page-metadata-parser": "^1.1.4",
|
||||
"pageres": "^6.2.3",
|
||||
"pg-boss": "^7.0.2",
|
||||
|
|
|
@ -4,7 +4,9 @@ class MyDocument extends Document {
|
|||
render () {
|
||||
return (
|
||||
<Html>
|
||||
<Head />
|
||||
<Head>
|
||||
<link rel='preload' href='/Lightningvolt-xoqm.ttf' as='font' type='font/ttf' crossOrigin='' />
|
||||
</Head>
|
||||
<body>
|
||||
<script src='/darkmode.js' />
|
||||
<Main />
|
||||
|
|
|
@ -2,6 +2,7 @@ import path from 'path'
|
|||
import AWS from 'aws-sdk'
|
||||
import {PassThrough} from 'stream'
|
||||
const { spawn } = require('child_process')
|
||||
const encodeS3URI = require('node-s3-url-encode')
|
||||
|
||||
const bucketName = 'sn-capture'
|
||||
const bucketRegion = 'us-east-1'
|
||||
|
@ -17,18 +18,20 @@ AWS.config.update({
|
|||
export default async function handler (req, res) {
|
||||
return new Promise(resolve => {
|
||||
const joinedPath = path.join(...(req.query.path || []))
|
||||
const s3Path = s3PathPrefix + (joinedPath === '.' ? '_' : joinedPath)
|
||||
const url = process.env.SELF_URL + '/' + joinedPath
|
||||
const searchQ = req.query.q ? `?q=${req.query.q}` : ''
|
||||
const s3PathPUT = s3PathPrefix + (joinedPath === '.' ? '_' : joinedPath) + searchQ
|
||||
const s3PathGET = s3PathPrefix + (joinedPath === '.' ? '_' : joinedPath) + encodeS3URI(searchQ)
|
||||
const url = process.env.SELF_URL + '/' + joinedPath + searchQ
|
||||
const aws = new AWS.S3({apiVersion: '2006-03-01'})
|
||||
|
||||
// check to see if we have a recent version of the object
|
||||
aws.headObject({
|
||||
Bucket: bucketName,
|
||||
Key: s3Path,
|
||||
Key: s3PathPUT,
|
||||
IfModifiedSince : new Date(new Date().getTime() - 15*60000)
|
||||
}).promise().then(() => {
|
||||
// this path is cached so return it
|
||||
res.writeHead(302, { Location: bucketUrl + s3Path }).end()
|
||||
res.writeHead(302, { Location: bucketUrl + s3PathGET }).end()
|
||||
resolve()
|
||||
}).catch(() => {
|
||||
// we don't have it cached, so capture it and cache it
|
||||
|
@ -42,7 +45,7 @@ export default async function handler (req, res) {
|
|||
const pass = new PassThrough()
|
||||
aws.upload({
|
||||
Bucket: bucketName,
|
||||
Key: s3Path,
|
||||
Key: s3PathPUT,
|
||||
ACL: 'public-read',
|
||||
Body: pass,
|
||||
ContentType: contentType
|
||||
|
|
|
@ -3,6 +3,7 @@ import { getGetServerSideProps } from '../api/ssrApollo'
|
|||
import { ITEM_SEARCH } from '../fragments/items'
|
||||
import SearchItems from '../components/search-items'
|
||||
import { useRouter } from 'next/router'
|
||||
import { SeoSearch } from '../components/seo'
|
||||
|
||||
export const getServerSideProps = getGetServerSideProps(ITEM_SEARCH, null, null, 'q')
|
||||
|
||||
|
@ -10,7 +11,8 @@ export default function Index ({ data: { search: { items, cursor } } }) {
|
|||
const router = useRouter()
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<Layout noSeo>
|
||||
<SeoSearch />
|
||||
<SearchItems
|
||||
items={items} cursor={cursor} variables={{ q: router.query?.q }}
|
||||
/>
|
||||
|
|
Loading…
Reference in New Issue