From 7cdb4cef31577818682b63ccbe01b53dd08a9207 Mon Sep 17 00:00:00 2001 From: Mqdd Date: Thu, 11 Dec 2025 09:31:51 +0700 Subject: sitemap done --- src/pages/sitemap/searchkey.xml.js | 37 ++++++++++++++++++++++++++++++ src/pages/sitemap/searchkey/[page].js | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/pages/sitemap/searchkey.xml.js create mode 100644 src/pages/sitemap/searchkey/[page].js (limited to 'src/pages/sitemap') diff --git a/src/pages/sitemap/searchkey.xml.js b/src/pages/sitemap/searchkey.xml.js new file mode 100644 index 00000000..488337d3 --- /dev/null +++ b/src/pages/sitemap/searchkey.xml.js @@ -0,0 +1,37 @@ +import productSearchApi from '@/lib/product/api/productSearchApi'; +import { create } from 'xmlbuilder'; +import _ from 'lodash-contrib'; +import axios from 'axios'; + +export async function getServerSideProps({ res }) { + const baseUrl = process.env.SELF_HOST + '/sitemap/searchkey'; + const limit = 500; + const keywords = await axios( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/searchkey?limit=${limit}&all=1` + ); + // console.log(keywords); + const pageCount = Math.ceil(keywords.data.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 = '2025-10-30'; + 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; +} diff --git a/src/pages/sitemap/searchkey/[page].js b/src/pages/sitemap/searchkey/[page].js new file mode 100644 index 00000000..cee53f5e --- /dev/null +++ b/src/pages/sitemap/searchkey/[page].js @@ -0,0 +1,42 @@ +import productSearchApi from '@/lib/product/api/productSearchApi'; +import { create } from 'xmlbuilder'; +import _ from 'lodash-contrib'; +import { createSlug } from '@/core/utils/slug'; +import axios from 'axios'; + +export async function getServerSideProps({ query, res }) { + // const baseUrl = process.env.SELF_HOST + '/shop/product/'; + const { page } = query; + const limit = 500; + const keywords = await axios( + `${ + process.env.NEXT_PUBLIC_SELF_HOST + }/api/shop/searchkey?limit=${limit}&page=${page.replace('.xml', '')}&all=1` + ); + + const sitemap = create('urlset', { encoding: 'utf-8' }).att( + 'xmlns', + 'http://www.sitemaps.org/schemas/sitemap/0.9' + ); + + const date = new Date(); + // const date = '2025-10-30'; + keywords.data.response.docs.forEach((product) => { + const url = sitemap.ele('url'); + const loc = product.url_s; + url.ele('loc', loc); + url.ele('lastmod', date.toISOString().slice(0, 10)); + url.ele('changefreq', 'daily'); + url.ele('priority', '0.8'); + }); + + res.setHeader('Content-Type', 'text/xml'); + res.write(sitemap.end()); + res.end(); + + return { props: {} }; +} + +export default function SitemapProducts() { + return null; +} -- cgit v1.2.3 From aa31de678b152aabeb5c4ac19e3d63bfe7f785f5 Mon Sep 17 00:00:00 2001 From: Mqdd Date: Fri, 19 Dec 2025 15:12:18 +0700 Subject: increase limit xml --- src/pages/sitemap/searchkey.xml.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pages/sitemap') diff --git a/src/pages/sitemap/searchkey.xml.js b/src/pages/sitemap/searchkey.xml.js index 488337d3..e4ca2434 100644 --- a/src/pages/sitemap/searchkey.xml.js +++ b/src/pages/sitemap/searchkey.xml.js @@ -5,7 +5,7 @@ import axios from 'axios'; export async function getServerSideProps({ res }) { const baseUrl = process.env.SELF_HOST + '/sitemap/searchkey'; - const limit = 500; + const limit = 1000; const keywords = await axios( `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/searchkey?limit=${limit}&all=1` ); -- cgit v1.2.3 From 3e67e48da0ea88f011f1d7d7390758ab2ad40339 Mon Sep 17 00:00:00 2001 From: Mqdd Date: Wed, 18 Feb 2026 15:51:13 +0700 Subject: cr renca --- src/pages/sitemap/searchkey.xml.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/pages/sitemap') diff --git a/src/pages/sitemap/searchkey.xml.js b/src/pages/sitemap/searchkey.xml.js index e4ca2434..b34baa8b 100644 --- a/src/pages/sitemap/searchkey.xml.js +++ b/src/pages/sitemap/searchkey.xml.js @@ -5,16 +5,16 @@ import axios from 'axios'; export async function getServerSideProps({ res }) { const baseUrl = process.env.SELF_HOST + '/sitemap/searchkey'; - const limit = 1000; + const limit = 5000; const keywords = await axios( - `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/searchkey?limit=${limit}&all=1` + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/searchkey?limit=${limit}&all=1`, ); // console.log(keywords); const pageCount = Math.ceil(keywords.data.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' + 'http://www.sitemaps.org/schemas/sitemap/0.9', ); const date = new Date(); -- cgit v1.2.3