diff options
| -rw-r--r-- | src/core/components/Seo.jsx | 66 | ||||
| -rw-r--r-- | src/pages/sitemap/blogs.xml.js | 37 | ||||
| -rw-r--r-- | src/pages/sitemap/brands.xml.js | 37 | ||||
| -rw-r--r-- | src/pages/sitemap/categories-brand.xml.js | 41 | ||||
| -rw-r--r-- | src/pages/sitemap/categories-brand/[page].js | 50 | ||||
| -rw-r--r-- | src/pages/sitemap/categories.xml.js | 47 | ||||
| -rw-r--r-- | src/pages/sitemap/products.xml.js | 2 | ||||
| -rw-r--r-- | src/pages/sitemap/products/[page].js | 2 |
8 files changed, 128 insertions, 154 deletions
diff --git a/src/core/components/Seo.jsx b/src/core/components/Seo.jsx index 66da395b..24d8c545 100644 --- a/src/core/components/Seo.jsx +++ b/src/core/components/Seo.jsx @@ -1,64 +1,32 @@ -import { useRouter } from 'next/router'; import { NextSeo } from 'next-seo'; +import { useRouter } from 'next/router'; -const Seo = (props) => { +const Seo = ({ ...props }) => { const router = useRouter(); - 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, - ]; + const { additionalMetaTags = [], openGraph = [], title = '' } = props; return ( <NextSeo defaultTitle='Indoteknik.com: B2B Industrial Supply & Solution' - canonical={resolvedCanonical} - description={description} - {...restProps} + canonical={process.env.NEXT_PUBLIC_SELF_HOST + router.asPath} + description={title} + {...props} openGraph={{ siteName: 'Indoteknik.com', ...openGraph, }} - additionalMetaTags={mergedAdditionalMetaTags} + additionalMetaTags={[ + { + property: 'fb:app_id', + content: '270830718811', + }, + { + property: 'fb:page_id', + content: '101759953569', + }, + ...additionalMetaTags, + ]} /> ); }; diff --git a/src/pages/sitemap/blogs.xml.js b/src/pages/sitemap/blogs.xml.js index 7f41ad0f..628dc710 100644 --- a/src/pages/sitemap/blogs.xml.js +++ b/src/pages/sitemap/blogs.xml.js @@ -1,31 +1,32 @@ -import { createSlug } from '@/core/utils/slug' -import blogsApi from '@/lib/blog/api/blogsApi' -import { create } from 'xmlbuilder' +import { createSlug } from '@/core/utils/slug'; +import blogsApi from '@/lib/blog/api/blogsApi'; +import { create } from 'xmlbuilder'; export async function getServerSideProps({ res }) { - const baseUrl = process.env.SELF_HOST + '/blog/' - const blogs = await blogsApi({ limit: 0, offset: 0 }) + const baseUrl = process.env.SELF_HOST + '/blog/'; + const blogs = await blogsApi({ limit: 0, offset: 0 }); 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-30'; blogs.blogs.forEach((blog) => { - const url = sitemap.ele('url') - url.ele('loc', createSlug(baseUrl, blog.title, blog.id)) - url.ele('lastmod', date.toISOString().slice(0, 10)) - url.ele('changefreq', 'weekly') - url.ele('priority', '0.6') - }) + const url = sitemap.ele('url'); + url.ele('loc', createSlug(baseUrl, blog.title, blog.id)); + url.ele('lastmod', date); + url.ele('changefreq', 'weekly'); + url.ele('priority', '0.6'); + }); - 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; } diff --git a/src/pages/sitemap/brands.xml.js b/src/pages/sitemap/brands.xml.js index 65a84e97..c2199d85 100644 --- a/src/pages/sitemap/brands.xml.js +++ b/src/pages/sitemap/brands.xml.js @@ -1,31 +1,32 @@ -import { create } from 'xmlbuilder' -import { createSlug } from '@/core/utils/slug' -import odooApi from '@/core/api/odooApi' +import { create } from 'xmlbuilder'; +import { createSlug } from '@/core/utils/slug'; +import odooApi from '@/core/api/odooApi'; export async function getServerSideProps({ res }) { - const baseUrl = process.env.SELF_HOST + '/shop/brands/' - const brands = await odooApi('GET', `/api/v1/manufacture?limit=0`) + const baseUrl = process.env.SELF_HOST + '/shop/brands/'; + const brands = await odooApi('GET', `/api/v1/manufacture?limit=0`); 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-30'; brands.manufactures.forEach((brand) => { - const url = sitemap.ele('url') - url.ele('loc', createSlug(baseUrl, brand.name, brand.id)) - url.ele('lastmod', date.toISOString().slice(0, 10)) - url.ele('changefreq', 'daily') - url.ele('priority', '1.0') - }) + const url = sitemap.ele('url'); + url.ele('loc', createSlug(baseUrl, brand.name, brand.id)); + url.ele('lastmod', date); + url.ele('changefreq', 'daily'); + url.ele('priority', '1.0'); + }); - 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; } diff --git a/src/pages/sitemap/categories-brand.xml.js b/src/pages/sitemap/categories-brand.xml.js index b23363e9..faf67b9f 100644 --- a/src/pages/sitemap/categories-brand.xml.js +++ b/src/pages/sitemap/categories-brand.xml.js @@ -1,35 +1,36 @@ -import productSearchApi from '@/lib/product/api/productSearchApi' -import { create } from 'xmlbuilder' -import _ from 'lodash-contrib' -import axios from 'axios' +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/categories-brand' - const limit = 500 + const baseUrl = process.env.SELF_HOST + '/sitemap/categories-brand'; + const limit = 500; const categories = await axios( `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/url-category_brand?limit=${limit}` - ) - const pageCount = Math.ceil(categories.data.response.numFound / limit) - const pages = Array.from({ length: pageCount }, (_, i) => i + 1) + ); + const pageCount = Math.ceil(categories.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 = 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)) - }) + const sitemap = sitemapIndex.ele('sitemap'); + sitemap.ele('loc', `${baseUrl}/${page}.xml`); + sitemap.ele('lastmod', date); + }); - 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/categories-brand/[page].js b/src/pages/sitemap/categories-brand/[page].js index 6b55e426..4d28ab04 100644 --- a/src/pages/sitemap/categories-brand/[page].js +++ b/src/pages/sitemap/categories-brand/[page].js @@ -1,43 +1,45 @@ - -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' +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 baseUrl = process.env.SELF_HOST + '/shop/product/'; + const { page } = query; + const limit = 500; const categories = await axios( - `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/url-category_brand?limit=${limit}&page=${page.replace( + `${ + process.env.NEXT_PUBLIC_SELF_HOST + }/api/shop/url-category_brand?limit=${limit}&page=${page.replace( '.xml', '' )}` - ) + ); 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-30'; categories.data.response.docs.forEach((product) => { - const url = sitemap.ele('url') + 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') - }) + url.ele('loc', loc); + url.ele('lastmod', date); + 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; } diff --git a/src/pages/sitemap/categories.xml.js b/src/pages/sitemap/categories.xml.js index 1c684576..357a2072 100644 --- a/src/pages/sitemap/categories.xml.js +++ b/src/pages/sitemap/categories.xml.js @@ -1,41 +1,42 @@ -import { create } from 'xmlbuilder' -import { createSlug } from '@/core/utils/slug' -import odooApi from '@/core/api/odooApi' +import { create } from 'xmlbuilder'; +import { createSlug } from '@/core/utils/slug'; +import odooApi from '@/core/api/odooApi'; export async function getServerSideProps({ res }) { - const categories = await odooApi('GET', '/api/v1/category/tree') + const categories = await odooApi('GET', '/api/v1/category/tree'); const sitemap = create('urlset', { encoding: 'utf-8' }).att( 'xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9' - ) + ); categories.forEach((category) => { - addUrlToSitemap(sitemap, category.name, category.id) + addUrlToSitemap(sitemap, category.name, category.id); category.childs.forEach((child1Category) => { - addUrlToSitemap(sitemap, child1Category.name, child1Category.id) + addUrlToSitemap(sitemap, child1Category.name, child1Category.id); child1Category.childs.forEach((child2Category) => { - addUrlToSitemap(sitemap, child2Category.name, child2Category.id) - }) - }) - }) + addUrlToSitemap(sitemap, child2Category.name, child2Category.id); + }); + }); + }); - 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: {} }; } function addUrlToSitemap(sitemap, name, id) { - const baseUrl = process.env.SELF_HOST + '/shop/category/' - const date = new Date() - const url = sitemap.ele('url') - url.ele('loc', createSlug(baseUrl, name, id)) - url.ele('lastmod', date.toISOString().slice(0, 10)) - url.ele('changefreq', 'weekly') - url.ele('priority', '0.6') + const baseUrl = process.env.SELF_HOST + '/shop/category/'; + // const date = new Date() + const date = '2025-10-30'; + const url = sitemap.ele('url'); + url.ele('loc', createSlug(baseUrl, name, id)); + url.ele('lastmod', date); + url.ele('changefreq', 'weekly'); + url.ele('priority', '0.6'); } export default function SitemapProducts() { - return null + return null; } diff --git a/src/pages/sitemap/products.xml.js b/src/pages/sitemap/products.xml.js index 4757a735..0269ec59 100644 --- a/src/pages/sitemap/products.xml.js +++ b/src/pages/sitemap/products.xml.js @@ -15,7 +15,7 @@ export async function getServerSideProps({ res }) { ); // const date = new Date() - const date = '2025-10-29'; + const date = '2025-10-30'; pages.forEach((page) => { const sitemap = sitemapIndex.ele('sitemap'); sitemap.ele('loc', `${baseUrl}/${page}.xml`); diff --git a/src/pages/sitemap/products/[page].js b/src/pages/sitemap/products/[page].js index 46256ad0..421c08e3 100644 --- a/src/pages/sitemap/products/[page].js +++ b/src/pages/sitemap/products/[page].js @@ -21,7 +21,7 @@ export async function getServerSideProps({ query, res }) { ); // const date = new Date() - const date = '2025-10-29'; + const date = '2025-10-30'; products.response.products.forEach((product) => { const url = sitemap.ele('url'); url.ele('loc', createSlug(baseUrl, product.name, product.id)); |
