Merge pull request 'fix(front-end): seo improvemnts' (#52) from dev into main
Reviewed-on: #52
This commit was merged in pull request #52.
This commit is contained in:
@@ -236,13 +236,12 @@ export class ProductDetailComponent {
|
|||||||
this.selectedVariantId.set(null);
|
this.selectedVariantId.set(null);
|
||||||
this.setSelectedImageAssetId(null);
|
this.setSelectedImageAssetId(null);
|
||||||
this.modelFile.set(null);
|
this.modelFile.set(null);
|
||||||
this.error.set(
|
const isNotFound = error?.status === 404;
|
||||||
error?.status === 404 ? 'SHOP.NOT_FOUND' : 'SHOP.LOAD_ERROR',
|
this.error.set(isNotFound ? 'SHOP.NOT_FOUND' : 'SHOP.LOAD_ERROR');
|
||||||
);
|
this.setResponseStatus(isNotFound ? 404 : 503);
|
||||||
if (error?.status === 404) {
|
if (this.shouldApplyFallbackSeo(error)) {
|
||||||
this.setResponseStatus(404);
|
this.applyFallbackSeo();
|
||||||
}
|
}
|
||||||
this.applyFallbackSeo();
|
|
||||||
return of(null);
|
return of(null);
|
||||||
}),
|
}),
|
||||||
finalize(() => this.loading.set(false)),
|
finalize(() => this.loading.set(false)),
|
||||||
@@ -598,6 +597,14 @@ export class ProductDetailComponent {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private shouldApplyFallbackSeo(error: { status?: number } | null): boolean {
|
||||||
|
if (error?.status === 404) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !this.isBrowser;
|
||||||
|
}
|
||||||
|
|
||||||
private materialLabelForVariant(
|
private materialLabelForVariant(
|
||||||
variant: ShopProductVariantOption | null,
|
variant: ShopProductVariantOption | null,
|
||||||
): string {
|
): string {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule, isPlatformBrowser } from '@angular/common';
|
||||||
import {
|
import {
|
||||||
|
PLATFORM_ID,
|
||||||
RESPONSE_INIT,
|
RESPONSE_INIT,
|
||||||
afterNextRender,
|
afterNextRender,
|
||||||
Component,
|
Component,
|
||||||
@@ -61,6 +62,7 @@ export class ShopPageComponent {
|
|||||||
private readonly router = inject(Router);
|
private readonly router = inject(Router);
|
||||||
private readonly translate = inject(TranslateService);
|
private readonly translate = inject(TranslateService);
|
||||||
private readonly seoService = inject(SeoService);
|
private readonly seoService = inject(SeoService);
|
||||||
|
private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
||||||
private readonly responseInit = inject(RESPONSE_INIT, { optional: true });
|
private readonly responseInit = inject(RESPONSE_INIT, { optional: true });
|
||||||
readonly languageService = inject(LanguageService);
|
readonly languageService = inject(LanguageService);
|
||||||
private readonly shopRouteService = inject(ShopRouteService);
|
private readonly shopRouteService = inject(ShopRouteService);
|
||||||
@@ -113,17 +115,16 @@ export class ShopPageComponent {
|
|||||||
catalog: this.shopService.getProductCatalog(categorySlug ?? null),
|
catalog: this.shopService.getProductCatalog(categorySlug ?? null),
|
||||||
}).pipe(
|
}).pipe(
|
||||||
catchError((error) => {
|
catchError((error) => {
|
||||||
|
const isNotFound = error?.status === 404;
|
||||||
this.categories.set([]);
|
this.categories.set([]);
|
||||||
this.categoryNodes.set([]);
|
this.categoryNodes.set([]);
|
||||||
this.selectedCategory.set(null);
|
this.selectedCategory.set(null);
|
||||||
this.products.set([]);
|
this.products.set([]);
|
||||||
this.error.set(
|
this.error.set(isNotFound ? 'SHOP.NOT_FOUND' : 'SHOP.LOAD_ERROR');
|
||||||
error?.status === 404 ? 'SHOP.NOT_FOUND' : 'SHOP.LOAD_ERROR',
|
this.setResponseStatus(isNotFound ? 404 : 503);
|
||||||
);
|
if (this.shouldApplyErrorSeo(error)) {
|
||||||
if (error?.status === 404) {
|
this.applyErrorSeo();
|
||||||
this.setResponseStatus(404);
|
|
||||||
}
|
}
|
||||||
this.applyErrorSeo();
|
|
||||||
return of(null);
|
return of(null);
|
||||||
}),
|
}),
|
||||||
finalize(() => this.loading.set(false)),
|
finalize(() => this.loading.set(false)),
|
||||||
@@ -376,6 +377,14 @@ export class ShopPageComponent {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private shouldApplyErrorSeo(error: { status?: number } | null): boolean {
|
||||||
|
if (error?.status === 404) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !this.isBrowser;
|
||||||
|
}
|
||||||
|
|
||||||
private setResponseStatus(status: number): void {
|
private setResponseStatus(status: number): void {
|
||||||
if (this.responseInit) {
|
if (this.responseInit) {
|
||||||
this.responseInit.status = status;
|
this.responseInit.status = status;
|
||||||
|
|||||||
Reference in New Issue
Block a user