Created
December 4, 2024 09:09
-
-
Save zzpzaf/8e65b754f4d33f86eea1e9e700806f7c to your computer and use it in GitHub Desktop.
ang18-SSR-SEO-SupportBlog2-seoObjects1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Constants | |
const META_VALUES = { | |
BLOG_SITE_NAME: 'A simple Multi-Container Blog Site Project', | |
FAVICON_URL: '/assets/images/favicon.ico', | |
ROBOTS_VALUE: 'index, follow', | |
TWITTER_CARD_VALUE: 'summary_large_image', | |
} as const; | |
const SCHEMA_TYPES = { | |
POST: 'BlogPosting', | |
ORGANIZATION: 'Organization', | |
ORG_NAME: 'The Big Byte Solutions', | |
AUTHOR: 'Person', | |
LOGO: 'ImageObject' | |
} as const; | |
export class PostTags { | |
// Default values | |
readonly postPgNr: number = 0; | |
readonly blogsitename: string = META_VALUES.BLOG_SITE_NAME; | |
readonly postfaviconUrl: string = META_VALUES.FAVICON_URL; | |
readonly postrobotsValue: string = META_VALUES.ROBOTS_VALUE; | |
readonly posttwiitercardValue: string = META_VALUES.TWITTER_CARD_VALUE; | |
// Post metadata | |
postTitle: string = ''; | |
postDescription: string = ''; | |
postFaviconUrl: string = ''; | |
postCanonicalUrl: string = ''; | |
postRobotsValue: string = ''; | |
postUser: string = ''; | |
postCreationTimestamp!: Date; | |
// Open Graph metadata | |
ogTitle: string = ''; | |
ogDescription: string = ''; | |
postTwiiterCardValue: string = ''; | |
constructor(init?: Partial<PostTags>) { | |
Object.assign(this, init); | |
} | |
} | |
// Interface for structured data | |
interface IStructuredDataConfig { | |
headline: string; | |
description: string; | |
imageUrl: string; | |
authorName: string; | |
datePublished: string; | |
orgLogoUrl: string; | |
} | |
export class PostStructuredData { | |
private readonly orgName: string = SCHEMA_TYPES.ORG_NAME; | |
constructor(private config?: Partial<IStructuredDataConfig>) {} | |
public getStructuredDataWithDefaults(config: IStructuredDataConfig): Record<string, any> { | |
return { | |
'@context': 'https://schema.org', | |
'@type': SCHEMA_TYPES.POST, | |
headline: config.headline, | |
description: config.description, | |
image: config.imageUrl, | |
author: { | |
'@type': SCHEMA_TYPES.AUTHOR, | |
name: config.authorName, | |
}, | |
datePublished: config.datePublished, | |
publisher: { | |
'@type': SCHEMA_TYPES.ORGANIZATION, | |
name: this.orgName, | |
logo: { | |
'@type': SCHEMA_TYPES.LOGO, | |
url: config.orgLogoUrl, | |
}, | |
}, | |
}; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment