diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-10-30 08:56:23 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-10-30 08:56:23 +0700 |
| commit | 7c210b2cd93df0b46d88d47fe2bca84d45fda92b (patch) | |
| tree | f256d1c2da703b173c80cdbbd36b2d0ba1b1d96a /src/pages/sitemap/products.xml.js | |
| parent | 182ebd7c22d8e7591ec32296b96b516145324d94 (diff) | |
<Miqdad> try fix sitemap
Diffstat (limited to 'src/pages/sitemap/products.xml.js')
| -rw-r--r-- | src/pages/sitemap/products.xml.js | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/src/pages/sitemap/products.xml.js b/src/pages/sitemap/products.xml.js index a2067308..9a96eedb 100644 --- a/src/pages/sitemap/products.xml.js +++ b/src/pages/sitemap/products.xml.js @@ -1,33 +1,34 @@ -import productSearchApi from '@/lib/product/api/productSearchApi' -import { create } from 'xmlbuilder' -import _ from 'lodash-contrib' +import productSearchApi from '@/lib/product/api/productSearchApi'; +import { create } from 'xmlbuilder'; +import _ from 'lodash-contrib'; export async function getServerSideProps({ res }) { - const baseUrl = process.env.SELF_HOST + '/sitemap/products' - const limit = 2500 - const query = { limit } - const products = await productSearchApi({ query: _.toQuery(query) }) - const pageCount = Math.ceil(products.response.numFound / limit) - const pages = Array.from({ length: pageCount }, (_, i) => i + 1) + const baseUrl = process.env.SELF_HOST + '/sitemap/products'; + const limit = 2500; + const query = { limit }; + const products = await productSearchApi({ query: _.toQuery(query) }); + const pageCount = Math.ceil(products.response.numFound / limit); + const pages = Array.from({ length: pageCount }, (_, i) => i + 1); const sitemapIndex = create('sitemapindex', { encoding: 'UTF-8' }).att( 'xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9' - ) + ); - const date = new Date() + // const date = new Date() + const date = '2025-10-29'; pages.forEach((page) => { - const sitemap = sitemapIndex.ele('sitemap') - sitemap.ele('loc', `${baseUrl}/${page}.xml`) - sitemap.ele('lastmod', date.toISOString().slice(0, 10)) - }) + const sitemap = sitemapIndex.ele('sitemap'); + sitemap.ele('loc', `${baseUrl}/${page}.xml`); + sitemap.ele('lastmod', date.toISOString().slice(0, 10)); + }); - res.setHeader('Content-Type', 'text/xml') - res.write(sitemapIndex.end()) - res.end() + res.setHeader('Content-Type', 'text/xml'); + res.write(sitemapIndex.end()); + res.end(); - return { props: {} } + return { props: {} }; } export default function SitemapProducts() { - return null + return null; } |
