feat(blog): enhance metadata generation and blog fetching by city context

This commit is contained in:
hamed
2026-07-19 09:02:14 +03:30
parent 88782e70c2
commit 4d7b87ee1a
5 changed files with 46 additions and 12 deletions
+9 -6
View File
@@ -175,14 +175,18 @@ function getSpecialtyUrls(baseUrl) {
}
// هر پست فقط در sitemap دامنهٔ canonical خودش: پست شهریافته → دامنهٔ آن شهر،
// پست سراسری (بدون شهر) → دامنهٔ اصلی.
async function getBlogUrls(baseUrl, scope, currentDomain) {
// پست سراسری (یا شهرِ بدون دامنهٔ اختصاصی) → دامنهٔ اصلی.
//
// تطبیق با شناسهٔ شهرِ scope انجام می‌شود نه با رشتهٔ دامنه: scope خودش از subdomain
// استخراج شده، پس با پورت و TLD متفاوت (محیط محلی) هم درست کار می‌کند.
async function getBlogUrls(baseUrl, scope) {
const blogs = await fetchAllPages('/api/v1/blogs');
return blogs
.filter((b) => b?.slug || b?.uuid)
.filter((b) => {
const cityDomain = findDomainByCityId(extractEntityCityId(b));
return cityDomain ? cityDomain === currentDomain : scope.isRoot;
const cityId = extractEntityCityId(b);
if (!findDomainByCityId(cityId)) return scope.isRoot;
return !scope.isRoot && Number(scope.matchedCity?.id) === Number(cityId);
})
.map((b) =>
withLastModified(
@@ -201,12 +205,11 @@ export default async function sitemap() {
const domain = await getCurrentDomain();
const baseUrl = getBaseUrl(domain);
const scope = getCityScope(domain);
const normalizedDomain = domain.toLowerCase().replace(/^www\./, '').split(':')[0];
const [doctorUrls, clinicUrls, blogUrls] = await Promise.all([
getDoctorUrls(baseUrl, scope),
getClinicUrls(baseUrl, scope),
getBlogUrls(baseUrl, scope, normalizedDomain),
getBlogUrls(baseUrl, scope),
]);
const allUrls = [