summaryrefslogtreecommitdiff
path: root/src/pages/sitemap/products.xml.js
diff options
context:
space:
mode:
authorHATEC\SPVDEV001 <tri.susilo@altama.co.id>2023-04-10 10:05:12 +0700
committerHATEC\SPVDEV001 <tri.susilo@altama.co.id>2023-04-10 10:05:12 +0700
commit13f6c6ad2a98efcc12b4e00b28699b584257c089 (patch)
tree6898b0b56889302b0abacbbfc104ea183bbfcefe /src/pages/sitemap/products.xml.js
parent0f7846a32deec5cb400d9e73c2f2127b5de1cffd (diff)
parent4b25b3e36c459b34f075550ca6e61b1d8f2643ce (diff)
Merge branch 'master' into development_tri/condition_page_detail_product
# Conflicts: # src/lib/product/components/Product/ProductDesktop.jsx
Diffstat (limited to 'src/pages/sitemap/products.xml.js')
-rw-r--r--src/pages/sitemap/products.xml.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/pages/sitemap/products.xml.js b/src/pages/sitemap/products.xml.js
new file mode 100644
index 00000000..e5fc8029
--- /dev/null
+++ b/src/pages/sitemap/products.xml.js
@@ -0,0 +1,30 @@
+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 sitemapIndex = create('sitemapindex', { encoding: 'UTF-8' })
+
+ const date = new Date()
+ pages.forEach((page) => {
+ 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()
+
+ return { props: {} }
+}
+
+export default function SitemapProducts() {
+ return null
+}