summaryrefslogtreecommitdiff
path: root/src/pages/google_merchant/products/index.js
blob: 38b37d2949d490e163c880e7a445e15ae15680c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import productSearchApi from '@/lib/product/api/productSearchApi'
import _ from 'lodash-contrib'

export async function getServerSideProps() {
  const limit = 5000
  const queries = {
    limit: 1,
    priceFrom: 1,
    fq: 'image_s:["" TO *]'
  }
  const products = await productSearchApi({ query: _.toQuery(queries) })
  const pageTotal = Math.ceil(products.response.numFound / limit)

  return { props: { pageTotal } }
}

export default function GoogleMerchantPage({ pageTotal }) {
  const numberArray = Array.from({ length: pageTotal }, (_, index) => index)
  return (
    <div className='grid grid-cols-1 gap-y-3 p-4'>
      <h1 className='text-h-lg font-semibold'>Google Merchant:</h1>
      {numberArray.map((number) => (
        <a
          key={number}
          href={`/google_merchant/products/${number + 1}.xml`}
          className='block font-medium text-indigo-600'
          target='_blank'
          rel='noreferrer'
        >
          Page {number + 1}
        </a>
      ))}
    </div>
  )
}