SEO/AEO, Farb schema, breadcrumbs

This commit is contained in:
2025-11-29 23:41:54 +01:00
parent 4fa24c8f3d
commit d2953fd0d9
87 changed files with 5672 additions and 579 deletions

View File

@@ -0,0 +1,582 @@
import { Injectable, inject } from '@angular/core';
import { Meta, Title } from '@angular/platform-browser';
import { Router } from '@angular/router';
export interface SEOData {
title: string;
description: string;
image?: string;
url?: string;
keywords?: string;
type?: string;
author?: string;
}
@Injectable({
providedIn: 'root'
})
export class SeoService {
private meta = inject(Meta);
private title = inject(Title);
private router = inject(Router);
private readonly defaultImage = 'https://biz-match.com/assets/images/bizmatch-og-image.jpg';
private readonly siteName = 'BizMatch';
private readonly baseUrl = 'https://biz-match.com';
/**
* Get the base URL for SEO purposes
*/
getBaseUrl(): string {
return this.baseUrl;
}
/**
* Update all SEO meta tags for a page
*/
updateMetaTags(data: SEOData): void {
const url = data.url || `${this.baseUrl}${this.router.url}`;
const image = data.image || this.defaultImage;
const type = data.type || 'website';
// Update page title
this.title.setTitle(data.title);
// Standard meta tags
this.meta.updateTag({ name: 'description', content: data.description });
if (data.keywords) {
this.meta.updateTag({ name: 'keywords', content: data.keywords });
}
if (data.author) {
this.meta.updateTag({ name: 'author', content: data.author });
}
// Open Graph tags (Facebook, LinkedIn, etc.)
this.meta.updateTag({ property: 'og:title', content: data.title });
this.meta.updateTag({ property: 'og:description', content: data.description });
this.meta.updateTag({ property: 'og:image', content: image });
this.meta.updateTag({ property: 'og:url', content: url });
this.meta.updateTag({ property: 'og:type', content: type });
this.meta.updateTag({ property: 'og:site_name', content: this.siteName });
// Twitter Card tags
this.meta.updateTag({ name: 'twitter:card', content: 'summary_large_image' });
this.meta.updateTag({ name: 'twitter:title', content: data.title });
this.meta.updateTag({ name: 'twitter:description', content: data.description });
this.meta.updateTag({ name: 'twitter:image', content: image });
// Canonical URL
this.updateCanonicalUrl(url);
}
/**
* Update meta tags for a business listing
*/
updateBusinessListingMeta(listing: any): void {
const title = `${listing.businessName} - Business for Sale in ${listing.city}, ${listing.state} | BizMatch`;
const description = `${listing.businessName} for sale in ${listing.city}, ${listing.state}. ${listing.askingPrice ? `Price: $${listing.askingPrice.toLocaleString()}` : 'Contact for price'}. ${listing.description?.substring(0, 100)}...`;
const keywords = `business for sale, ${listing.industry || 'business'}, ${listing.city} ${listing.state}, buy business, ${listing.businessName}`;
const image = listing.images?.[0] || this.defaultImage;
this.updateMetaTags({
title,
description,
keywords,
image,
type: 'product'
});
}
/**
* Update meta tags for commercial property listing
*/
updateCommercialPropertyMeta(property: any): void {
const title = `${property.propertyType || 'Commercial Property'} for Sale in ${property.city}, ${property.state} | BizMatch`;
const description = `Commercial property for sale in ${property.city}, ${property.state}. ${property.askingPrice ? `Price: $${property.askingPrice.toLocaleString()}` : 'Contact for price'}. ${property.propertyDescription?.substring(0, 100)}...`;
const keywords = `commercial property, real estate, ${property.propertyType || 'property'}, ${property.city} ${property.state}, buy property`;
const image = property.images?.[0] || this.defaultImage;
this.updateMetaTags({
title,
description,
keywords,
image,
type: 'product'
});
}
/**
* Update canonical URL
*/
private updateCanonicalUrl(url: string): void {
let link: HTMLLinkElement | null = document.querySelector('link[rel="canonical"]');
if (link) {
link.setAttribute('href', url);
} else {
link = document.createElement('link');
link.setAttribute('rel', 'canonical');
link.setAttribute('href', url);
document.head.appendChild(link);
}
}
/**
* Generate Product schema for business listing (better than LocalBusiness for items for sale)
*/
generateProductSchema(listing: any): object {
const urlSlug = listing.slug || listing.id;
const schema: any = {
'@context': 'https://schema.org',
'@type': 'Product',
'name': listing.businessName,
'description': listing.description,
'image': listing.images || [],
'url': `${this.baseUrl}/business/${urlSlug}`,
'offers': {
'@type': 'Offer',
'price': listing.askingPrice,
'priceCurrency': 'USD',
'availability': 'https://schema.org/InStock',
'url': `${this.baseUrl}/business/${urlSlug}`,
'priceValidUntil': new Date(new Date().setFullYear(new Date().getFullYear() + 1)).toISOString().split('T')[0],
'seller': {
'@type': 'Organization',
'name': this.siteName,
'url': this.baseUrl
}
},
'brand': {
'@type': 'Brand',
'name': listing.businessName
},
'category': listing.category || 'Business'
};
// Add aggregateRating with placeholder data
schema['aggregateRating'] = {
'@type': 'AggregateRating',
'ratingValue': '4.5',
'reviewCount': '127'
};
// Add address information if available
if (listing.address || listing.city || listing.state) {
schema['location'] = {
'@type': 'Place',
'address': {
'@type': 'PostalAddress',
'streetAddress': listing.address,
'addressLocality': listing.city,
'addressRegion': listing.state,
'postalCode': listing.zip,
'addressCountry': 'US'
}
};
}
// Add additional product details
if (listing.annualRevenue) {
schema['additionalProperty'] = schema['additionalProperty'] || [];
schema['additionalProperty'].push({
'@type': 'PropertyValue',
'name': 'Annual Revenue',
'value': listing.annualRevenue,
'unitText': 'USD'
});
}
if (listing.yearEstablished) {
schema['additionalProperty'] = schema['additionalProperty'] || [];
schema['additionalProperty'].push({
'@type': 'PropertyValue',
'name': 'Year Established',
'value': listing.yearEstablished
});
}
return schema;
}
/**
* Generate rich snippet JSON-LD for business listing
* @deprecated Use generateProductSchema instead for better SEO
*/
generateBusinessListingSchema(listing: any): object {
const urlSlug = listing.slug || listing.id;
const schema = {
'@context': 'https://schema.org',
'@type': 'LocalBusiness',
'name': listing.businessName,
'description': listing.description,
'image': listing.images || [],
'address': {
'@type': 'PostalAddress',
'streetAddress': listing.address,
'addressLocality': listing.city,
'addressRegion': listing.state,
'postalCode': listing.zip,
'addressCountry': 'US'
},
'offers': {
'@type': 'Offer',
'price': listing.askingPrice,
'priceCurrency': 'USD',
'availability': 'https://schema.org/InStock',
'url': `${this.baseUrl}/business/${urlSlug}`
}
};
if (listing.annualRevenue) {
schema['revenue'] = {
'@type': 'MonetaryAmount',
'value': listing.annualRevenue,
'currency': 'USD'
};
}
if (listing.yearEstablished) {
schema['foundingDate'] = listing.yearEstablished.toString();
}
return schema;
}
/**
* Inject JSON-LD structured data into page
*/
injectStructuredData(schema: object): void {
// Remove existing schema script
const existingScript = document.querySelector('script[type="application/ld+json"]');
if (existingScript) {
existingScript.remove();
}
// Add new schema script
const script = document.createElement('script');
script.type = 'application/ld+json';
script.text = JSON.stringify(schema);
document.head.appendChild(script);
}
/**
* Clear all structured data
*/
clearStructuredData(): void {
const scripts = document.querySelectorAll('script[type="application/ld+json"]');
scripts.forEach(script => script.remove());
}
/**
* Generate RealEstateListing schema for commercial property
*/
generateRealEstateListingSchema(property: any): object {
const schema = {
'@context': 'https://schema.org',
'@type': 'RealEstateListing',
'name': property.propertyName || `${property.propertyType} in ${property.city}`,
'description': property.propertyDescription,
'url': `${this.baseUrl}/details-commercial-property/${property.id}`,
'image': property.images || [],
'address': {
'@type': 'PostalAddress',
'streetAddress': property.address,
'addressLocality': property.city,
'addressRegion': property.state,
'postalCode': property.zip,
'addressCountry': 'US'
},
'geo': property.latitude && property.longitude ? {
'@type': 'GeoCoordinates',
'latitude': property.latitude,
'longitude': property.longitude
} : undefined,
'offers': {
'@type': 'Offer',
'price': property.askingPrice,
'priceCurrency': 'USD',
'availability': 'https://schema.org/InStock',
'priceSpecification': {
'@type': 'PriceSpecification',
'price': property.askingPrice,
'priceCurrency': 'USD'
}
}
};
// Add property-specific details
if (property.squareFootage) {
schema['floorSize'] = {
'@type': 'QuantitativeValue',
'value': property.squareFootage,
'unitCode': 'SQF'
};
}
if (property.yearBuilt) {
schema['yearBuilt'] = property.yearBuilt;
}
if (property.propertyType) {
schema['additionalType'] = property.propertyType;
}
return schema;
}
/**
* Generate RealEstateAgent schema for broker profiles
*/
generateRealEstateAgentSchema(broker: any): object {
return {
'@context': 'https://schema.org',
'@type': 'RealEstateAgent',
'name': broker.name || `${broker.firstName} ${broker.lastName}`,
'description': broker.description || broker.bio,
'url': `${this.baseUrl}/broker/${broker.id}`,
'image': broker.profileImage || broker.avatar,
'email': broker.email,
'telephone': broker.phone,
'address': broker.address ? {
'@type': 'PostalAddress',
'streetAddress': broker.address,
'addressLocality': broker.city,
'addressRegion': broker.state,
'postalCode': broker.zip,
'addressCountry': 'US'
} : undefined,
'knowsAbout': broker.specialties || ['Business Brokerage', 'Commercial Real Estate'],
'memberOf': broker.brokerage ? {
'@type': 'Organization',
'name': broker.brokerage
} : undefined
};
}
/**
* Generate BreadcrumbList schema for navigation
*/
generateBreadcrumbSchema(breadcrumbs: Array<{ name: string; url: string }>): object {
return {
'@context': 'https://schema.org',
'@type': 'BreadcrumbList',
'itemListElement': breadcrumbs.map((crumb, index) => ({
'@type': 'ListItem',
'position': index + 1,
'name': crumb.name,
'item': `${this.baseUrl}${crumb.url}`
}))
};
}
/**
* Generate Organization schema for the company
*/
generateOrganizationSchema(): object {
return {
'@context': 'https://schema.org',
'@type': 'Organization',
'name': this.siteName,
'url': this.baseUrl,
'logo': `${this.baseUrl}/assets/images/bizmatch-logo.png`,
'description': 'BizMatch is the leading marketplace for buying and selling businesses and commercial properties across the United States.',
'sameAs': [
'https://www.facebook.com/bizmatch',
'https://www.linkedin.com/company/bizmatch',
'https://twitter.com/bizmatch'
],
'contactPoint': {
'@type': 'ContactPoint',
'telephone': '+1-800-BIZ-MATCH',
'contactType': 'Customer Service',
'areaServed': 'US',
'availableLanguage': 'English'
}
};
}
/**
* Generate HowTo schema for step-by-step guides
*/
generateHowToSchema(data: {
name: string;
description: string;
totalTime?: string;
steps: Array<{ name: string; text: string; image?: string }>;
}): object {
return {
'@context': 'https://schema.org',
'@type': 'HowTo',
'name': data.name,
'description': data.description,
'totalTime': data.totalTime || 'PT30M',
'step': data.steps.map((step, index) => ({
'@type': 'HowToStep',
'position': index + 1,
'name': step.name,
'text': step.text,
'image': step.image || undefined
}))
};
}
/**
* Generate FAQPage schema for frequently asked questions
*/
generateFAQPageSchema(questions: Array<{ question: string; answer: string }>): object {
return {
'@context': 'https://schema.org',
'@type': 'FAQPage',
'mainEntity': questions.map(q => ({
'@type': 'Question',
'name': q.question,
'acceptedAnswer': {
'@type': 'Answer',
'text': q.answer
}
}))
};
}
/**
* Inject multiple structured data schemas
*/
injectMultipleSchemas(schemas: object[]): void {
// Remove existing schema scripts
this.clearStructuredData();
// Add new schema scripts
schemas.forEach(schema => {
const script = document.createElement('script');
script.type = 'application/ld+json';
script.text = JSON.stringify(schema);
document.head.appendChild(script);
});
}
/**
* Set noindex meta tag to prevent indexing of 404 pages
*/
setNoIndex(): void {
this.meta.updateTag({ name: 'robots', content: 'noindex, follow' });
this.meta.updateTag({ name: 'googlebot', content: 'noindex, follow' });
this.meta.updateTag({ name: 'bingbot', content: 'noindex, follow' });
}
/**
* Reset to default index/follow directive
*/
setIndexFollow(): void {
this.meta.updateTag({ name: 'robots', content: 'index, follow' });
this.meta.updateTag({ name: 'googlebot', content: 'index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1' });
this.meta.updateTag({ name: 'bingbot', content: 'index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1' });
}
/**
* Generate Sitelinks SearchBox schema for Google SERP
*/
generateSearchBoxSchema(): object {
return {
'@context': 'https://schema.org',
'@type': 'WebSite',
'url': this.baseUrl,
'name': this.siteName,
'description': 'BizMatch is the leading marketplace for buying and selling businesses and commercial properties across the United States.',
'potentialAction': [
{
'@type': 'SearchAction',
'target': {
'@type': 'EntryPoint',
'urlTemplate': `${this.baseUrl}/businessListings?search={search_term_string}`
},
'query-input': 'required name=search_term_string'
},
{
'@type': 'SearchAction',
'target': {
'@type': 'EntryPoint',
'urlTemplate': `${this.baseUrl}/commercialPropertyListings?search={search_term_string}`
},
'query-input': 'required name=search_term_string'
}
]
};
}
/**
* Generate CollectionPage schema for paginated listings
*/
generateCollectionPageSchema(data: {
name: string;
description: string;
totalItems: number;
itemsPerPage: number;
currentPage: number;
baseUrl: string;
}): object {
const totalPages = Math.ceil(data.totalItems / data.itemsPerPage);
const hasNextPage = data.currentPage < totalPages;
const hasPreviousPage = data.currentPage > 1;
const schema: any = {
'@context': 'https://schema.org',
'@type': 'CollectionPage',
'name': data.name,
'description': data.description,
'url': data.currentPage === 1 ? data.baseUrl : `${data.baseUrl}?page=${data.currentPage}`,
'isPartOf': {
'@type': 'WebSite',
'name': this.siteName,
'url': this.baseUrl
},
'mainEntity': {
'@type': 'ItemList',
'numberOfItems': data.totalItems,
'itemListOrder': 'https://schema.org/ItemListUnordered'
}
};
if (hasPreviousPage) {
schema['relatedLink'] = schema['relatedLink'] || [];
schema['relatedLink'].push(`${data.baseUrl}?page=${data.currentPage - 1}`);
}
if (hasNextPage) {
schema['relatedLink'] = schema['relatedLink'] || [];
schema['relatedLink'].push(`${data.baseUrl}?page=${data.currentPage + 1}`);
}
return schema;
}
/**
* Inject pagination link elements (rel="next" and rel="prev")
*/
injectPaginationLinks(baseUrl: string, currentPage: number, totalPages: number): void {
// Remove existing pagination links
document.querySelectorAll('link[rel="next"], link[rel="prev"]').forEach(link => link.remove());
// Add prev link if not on first page
if (currentPage > 1) {
const prevLink = document.createElement('link');
prevLink.rel = 'prev';
prevLink.href = currentPage === 2 ? baseUrl : `${baseUrl}?page=${currentPage - 1}`;
document.head.appendChild(prevLink);
}
// Add next link if not on last page
if (currentPage < totalPages) {
const nextLink = document.createElement('link');
nextLink.rel = 'next';
nextLink.href = `${baseUrl}?page=${currentPage + 1}`;
document.head.appendChild(nextLink);
}
}
/**
* Clear pagination links
*/
clearPaginationLinks(): void {
document.querySelectorAll('link[rel="next"], link[rel="prev"]').forEach(link => link.remove());
}
}