summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-10-30 09:11:20 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-10-30 09:11:20 +0700
commit95716fc233157c9cc2c33d59f218b1fadf39f0f7 (patch)
treea6ba62dbddec6cf34e55afa2479d680091437161
parent30fed8b12bcfd7f117716cb75254bca99f5a43cb (diff)
parent7c210b2cd93df0b46d88d47fe2bca84d45fda92b (diff)
Merge branch 'new-release' of https://bitbucket.org/altafixco/next-indoteknik into cr_prod_card
merge
-rw-r--r--src/core/components/Seo.jsx78
-rw-r--r--src/pages/sitemap/products.xml.js41
-rw-r--r--src/pages/sitemap/products/[page].js50
3 files changed, 103 insertions, 66 deletions
diff --git a/src/core/components/Seo.jsx b/src/core/components/Seo.jsx
index 0e224c19..66da395b 100644
--- a/src/core/components/Seo.jsx
+++ b/src/core/components/Seo.jsx
@@ -1,34 +1,66 @@
-import { NextSeo } from 'next-seo'
-import { useRouter } from 'next/router'
+import { useRouter } from 'next/router';
+import { NextSeo } from 'next-seo';
-const Seo = ({ ...props }) => {
- const router = useRouter()
+const Seo = (props) => {
+ const router = useRouter();
- const { additionalMetaTags = [], openGraph = [], title = '' } = props
+ const {
+ canonical,
+ description,
+ additionalMetaTags = [],
+ openGraph = {},
+ ...restProps
+ } = props;
+
+ const origin = (process.env.NEXT_PUBLIC_SELF_HOST || '').replace(/\/+$/, '');
+
+ const asPath = router.asPath || '';
+
+ const [cleanPath] = asPath.split('?');
+
+ const queryObj = router.query || {};
+
+ const isSearchPage = cleanPath.startsWith('/search');
+
+ const buildFallbackCanonical = () => {
+ if (isSearchPage) {
+ const q = queryObj.q;
+ if (q) {
+ return origin + cleanPath + `?q=${encodeURIComponent(String(q))}`;
+ }
+ return origin + cleanPath;
+ }
+
+ return origin + cleanPath;
+ };
+
+ const resolvedCanonical = canonical || buildFallbackCanonical();
+
+ const mergedAdditionalMetaTags = [
+ {
+ property: 'fb:app_id',
+ content: '270830718811',
+ },
+ {
+ property: 'fb:page_id',
+ content: '101759953569',
+ },
+ ...additionalMetaTags,
+ ];
return (
<NextSeo
defaultTitle='Indoteknik.com: B2B Industrial Supply & Solution'
- canonical={process.env.NEXT_PUBLIC_SELF_HOST + router.asPath}
- description={title}
- {...props}
+ canonical={resolvedCanonical}
+ description={description}
+ {...restProps}
openGraph={{
siteName: 'Indoteknik.com',
- ...openGraph
+ ...openGraph,
}}
- additionalMetaTags={[
- {
- property: 'fb:app_id',
- content: '270830718811'
- },
- {
- property: 'fb:page_id',
- content: '101759953569'
- },
- ...additionalMetaTags
- ]}
+ additionalMetaTags={mergedAdditionalMetaTags}
/>
- )
-}
+ );
+};
-export default Seo
+export default Seo;
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;
}
diff --git a/src/pages/sitemap/products/[page].js b/src/pages/sitemap/products/[page].js
index 3419489b..42fd5fc7 100644
--- a/src/pages/sitemap/products/[page].js
+++ b/src/pages/sitemap/products/[page].js
@@ -1,38 +1,42 @@
-import productSearchApi from '@/lib/product/api/productSearchApi'
-import { create } from 'xmlbuilder'
-import _ from 'lodash-contrib'
-import { createSlug } from '@/core/utils/slug'
+import productSearchApi from '@/lib/product/api/productSearchApi';
+import { create } from 'xmlbuilder';
+import _ from 'lodash-contrib';
+import { createSlug } from '@/core/utils/slug';
export async function getServerSideProps({ query, res }) {
- const baseUrl = process.env.SELF_HOST + '/shop/product/'
- const { page } = query
- const limit = 2500
- const queries = { limit, page: page.replace('.xml', ''),
+ const baseUrl = process.env.SELF_HOST + '/shop/product/';
+ const { page } = query;
+ const limit = 2500;
+ const queries = {
+ limit,
+ page: page.replace('.xml', ''),
'-publish_b': false,
product_rating_f: '[8 TO *]',
- price_tier1_v2_f: '[1 TO *]', }
- const products = await productSearchApi({ query: _.toQuery(queries) })
+ price_tier1_v2_f: '[1 TO *]',
+ };
+ const products = await productSearchApi({ query: _.toQuery(queries) });
const sitemap = create('urlset', { 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';
products.response.products.forEach((product) => {
- const url = sitemap.ele('url')
- url.ele('loc', createSlug(baseUrl, product.name, product.id))
- url.ele('lastmod', date.toISOString().slice(0, 10))
- url.ele('changefreq', 'daily')
- url.ele('priority', '0.8')
- })
+ const url = sitemap.ele('url');
+ url.ele('loc', createSlug(baseUrl, product.name, product.id));
+ 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()
+ res.setHeader('Content-Type', 'text/xml');
+ res.write(sitemap.end());
+ res.end();
- return { props: {} }
+ return { props: {} };
}
export default function SitemapProducts() {
- return null
+ return null;
}