"use strict"; import { ERROR_SERVER, NO_PRODUCTS_IN_THIS_CATEGORY } from './constants.js'; import { showErrorMessage } from './utils.js'; /* ===================================== ЗАЩИТА ШАБЛОНА brand.html ===================================== */ (function () { const path = window.location.pathname; if (path !== '/brand.html') return; const params = new URLSearchParams(window.location.search); const brand = params.get('brand'); if (!brand) { const meta = document.createElement('meta'); meta.name = 'robots'; meta.content = 'noindex, nofollow'; document.head.appendChild(meta); window.location.replace('/'); } })(); /* ===================================== ОСНОВНОЙ КОД ===================================== */ document.addEventListener('DOMContentLoaded', () => { const cardsContainer = document.querySelector('.cards'); const brandTitle = document.getElementById('brand-name'); const errorContainer = document.querySelector('.error-message'); const getBrandFromURL = () => { const params = new URLSearchParams(window.location.search); return params.get('brand'); }; const loadProducts = async () => { try { const response = await fetch('/data/products.json'); if (!response.ok) throw new Error(ERROR_SERVER); const products = await response.json(); const brand = getBrandFromURL(); if (!brand) return; const decodedBrand = decodeURIComponent(brand); setCanonicalForBrand(decodedBrand); optimizeBrandSEO(decodedBrand); brandTitle.textContent = decodedBrand; const filteredProducts = products.filter( product => product.fabric === decodedBrand ); if (!filteredProducts.length) { showErrorMessage(NO_PRODUCTS_IN_THIS_CATEGORY, errorContainer); return; } renderProducts(filteredProducts); } catch (error) { showErrorMessage(ERROR_SERVER, errorContainer); console.error(error); } }; const renderProducts = (products) => { cardsContainer.innerHTML = products.map(product => `