Skip to content

Commit

Permalink
#25959 Fixing google validation
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelrojas committed Oct 17, 2023
1 parent c536c03 commit e3c9eb9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 10 deletions.
Expand Up @@ -35,6 +35,7 @@ export enum SEO_LIMITS {
MAX_IMAGE_BYTES = 8000000,
MAX_TWITTER_IMAGE_BYTES = 5000000,
MAX_TWITTER_DESCRIPTION_LENGTH = 200,
MIN_TWITTER_DESCRIPTION_LENGTH = 30,
MIN_TWITTER_TITLE_LENGTH = 30,
MAX_TWITTER_TITLE_LENGTH = 70
}
Expand Down
Expand Up @@ -72,7 +72,7 @@ export class DotSeoMetaTagsService {

metaTagsObject['faviconElements'] = favicon;
metaTagsObject['titleElements'] = title;
metaTagsObject['favicon'] = (favicon[0] as HTMLLinkElement)?.href;
metaTagsObject['favicon'] = (favicon[0] as HTMLLinkElement)?.href || null;
metaTagsObject['title'] = title[0]?.innerText;
metaTagsObject['titleOgElements'] = titleOgElements;
metaTagsObject['imageOgElements'] = imagesOgElements;
Expand Down Expand Up @@ -191,7 +191,10 @@ export class DotSeoMetaTagsService {
const favicon = metaTagsObject['favicon'];
const faviconElements = metaTagsObject['faviconElements'];

if (faviconElements.length === 0) {
if (
faviconElements.length <= SEO_LIMITS.MAX_FAVICONS &&
this.areAllFalsyOrEmpty([favicon])
) {
items.push(
this.getErrorItem(this.dotMessageService.get('seo.rules.favicon.not.found'))
);
Expand Down Expand Up @@ -459,7 +462,7 @@ export class DotSeoMetaTagsService {
}

if (
imageMetaData?.url === IMG_NOT_FOUND_KEY ||
imageMetaData?.url === IMG_NOT_FOUND_KEY &&
this.areAllFalsyOrEmpty([imageOgElements, imageOg])
) {
result.push(
Expand Down Expand Up @@ -530,15 +533,25 @@ export class DotSeoMetaTagsService {
const result: SeoRulesResult[] = [];
const titleCardElements = metaTagsObject['twitterTitleElements'];
const titleCard = metaTagsObject['twitter:title'];
const title = metaTagsObject['title'];
const titleElements = metaTagsObject['titleElements'];

if (this.areAllFalsyOrEmpty([titleCard, titleCardElements])) {
if (title && this.areAllFalsyOrEmpty([titleCard, titleCardElements])) {
result.push(
this.getErrorItem(
this.dotMessageService.get('seo.rules.twitter-card-title.not.found')
)
);
}

if (this.areAllFalsyOrEmpty([title, titleCard, titleElements, titleCardElements])) {
result.push(
this.getErrorItem(
this.dotMessageService.get('seo.rules.twitter-card-title.title.not.found')
)
);
}

if (titleCardElements?.length > 1) {
result.push(
this.getErrorItem(
Expand Down Expand Up @@ -629,7 +642,19 @@ export class DotSeoMetaTagsService {

if (
twitterDescription &&
twitterDescription.length < SEO_LIMITS.MAX_TWITTER_DESCRIPTION_LENGTH
twitterDescription.length < SEO_LIMITS.MIN_TWITTER_DESCRIPTION_LENGTH
) {
result.push(
this.getWarningItem(
this.dotMessageService.get('seo.rules.twitter-card-description.less')
)
);
}

if (
twitterDescription &&
twitterDescription.length < SEO_LIMITS.MAX_TWITTER_DESCRIPTION_LENGTH &&
twitterDescription.length > SEO_LIMITS.MAX_TWITTER_DESCRIPTION_LENGTH
) {
result.push(
this.getDoneItem(
Expand All @@ -646,25 +671,40 @@ export class DotSeoMetaTagsService {
const twitterImage = metaTagsObject['twitter:image'];

return this.getImageFileSize(twitterImage).pipe(
switchMap((imageMetaData) => {
switchMap((imageMetaData: ImageMetaData) => {
const result: SeoRulesResult[] = [];

if (twitterImage && imageMetaData.length <= SEO_LIMITS.MAX_IMAGE_BYTES) {
if (
imageMetaData?.url !== IMG_NOT_FOUND_KEY &&
imageMetaData.length <= SEO_LIMITS.MAX_IMAGE_BYTES
) {
result.push(
this.getDoneItem(
this.dotMessageService.get('seo.rules.twitter-image.found')
)
);
}

if (this.areAllFalsyOrEmpty([twitterImage, twitterImageElements])) {
if (
imageMetaData?.url === IMG_NOT_FOUND_KEY &&
this.areAllFalsyOrEmpty([twitterImage, twitterImageElements])
) {
result.push(
this.getErrorItem(
this.dotMessageService.get('seo.rules.twitter-image.not.found')
)
);
}

if (twitterImageElements?.length >= 1 && this.areAllFalsyOrEmpty([twitterImage])) {
result.push(
this.getErrorItem(
this.dotMessageService.get(
'seo.rules.twitter-image.more.one.found.empty'
)
)
);
}

if (twitterImageElements?.length > 1) {
result.push(
this.getErrorItem(
Expand Down
4 changes: 3 additions & 1 deletion dotCMS/src/main/webapp/WEB-INF/messages/Language.properties
Expand Up @@ -5433,7 +5433,7 @@ experiments.chart.xAxisLabel.bayesian=Conversion Rate (%)

seo.rules.read-more.title=Read More

seo.rules.favicon.not.found=Favicon not found!
seo.rules.favicon.not.found=Favicon not found, but Image Link is not valid!
seo.rules.favicon.more.one.found=More than 1 Favicon found!
seo.rules.favicon.found=Favicon found!

Expand Down Expand Up @@ -5484,6 +5484,7 @@ seo.rules.twitter-card.more.one.found.empty=twitter:card meta tag found, but is
seo.rules.twitter-card.found=twitter:card meta tag found!
seo.rules.twitter-card-title.not.found=twitter:title meta tag not found! Showing HTML Title instead.
seo.rules.twitter-card-title.title.not.found=twitter:title meta tag not found! Showing HTML Title instead.
seo.rules.twitter-card-title.more.one.found=more than 1 twitter:title meta tag found!
seo.rules.twitter-card-title.found.empty=twitter:title meta tag found, but is empty!
seo.rules.twitter-card.title.greater=twitter:title meta tag found, but has more than 70 characters.
Expand All @@ -5495,6 +5496,7 @@ seo.rules.twitter-card-description.more.one.found=more than 1 twitter:descriptio
seo.rules.twitter-card-description.more.one.found.empty=twitter:description meta tag found, but is empty!
seo.rules.twitter-card-description.found=twitter:description meta tag with valid content found!
seo.rules.twitter-card-description.greater=twitter:description meta tag found, but has more than 200 characters.
seo.rules.twitter-card-description.less=twitter:description meta tag found, but it has fewer than 30 characters of content.
seo.rules.twitter-image.not.found=twitter:image meta tag not found!
seo.rules.twitter-image.more.one.found=more than 1 twitter:image meta tag found!
Expand Down

0 comments on commit e3c9eb9

Please sign in to comment.