@osovitny/anatoly 3.19.47 → 3.19.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3597,11 +3597,11 @@ class BrowserService {
3597
3597
  @osovitny/anatoly
3598
3598
 
3599
3599
  Authors:
3600
- Vadim Osovitny vadim.osovitny@osovitny.com
3601
- Anatoly Osovitny anatoly.osovitny@osovitny.com
3600
+ Vadim Osovitny vadim.osovitny@osovitny.com
3601
+ Anatoly Osovitny anatoly.osovitny@osovitny.com
3602
3602
 
3603
3603
  Created:
3604
- 29 Nov 2020
3604
+ 29 Nov 2020
3605
3605
 
3606
3606
  Copyright (c) 2016-2025 Osovitny Inc. All rights reserved.
3607
3607
  </file>
@@ -3612,25 +3612,72 @@ class DigitalMarketingService {
3612
3612
  this.title = title;
3613
3613
  this.meta = meta;
3614
3614
  this.dom = dom;
3615
+ this.existingMetaTags = new Map();
3615
3616
  }
3616
3617
  updateTitle(title) {
3617
3618
  this.title.setTitle(title);
3618
3619
  }
3619
3620
  updateDescription(desc) {
3620
- this.meta.updateTag({ name: 'description', content: desc });
3621
+ if (desc) {
3622
+ this.meta.updateTag({ name: 'description', content: desc });
3623
+ }
3624
+ else {
3625
+ this.meta.removeTag('name="description"');
3626
+ }
3621
3627
  }
3622
3628
  updateKeywords(keywords) {
3623
- this.meta.updateTag({ name: 'keywords', content: keywords });
3629
+ if (keywords) {
3630
+ this.meta.updateTag({ name: 'keywords', content: keywords });
3631
+ }
3632
+ else {
3633
+ this.meta.removeTag('name="keywords"');
3634
+ }
3624
3635
  }
3625
- updateMetaTags(meta) {
3626
- meta.forEach(m => this.meta.updateTag(m));
3636
+ updateMetaTags(metaDefinitions) {
3637
+ this.removePreviousMetaTags();
3638
+ if (metaDefinitions && metaDefinitions.length > 0) {
3639
+ metaDefinitions.forEach(metaDef => {
3640
+ const tag = this.meta.updateTag(metaDef);
3641
+ if (tag) {
3642
+ const key = this.getMetaTagKey(metaDef);
3643
+ this.existingMetaTags.set(key, tag);
3644
+ }
3645
+ });
3646
+ }
3647
+ }
3648
+ removePreviousMetaTags() {
3649
+ this.existingMetaTags.forEach((tag, key) => {
3650
+ if (tag && tag.parentNode) {
3651
+ tag.parentNode.removeChild(tag);
3652
+ }
3653
+ });
3654
+ this.existingMetaTags.clear();
3655
+ }
3656
+ getMetaTagKey(metaDef) {
3657
+ if (metaDef.name) {
3658
+ return `name:${metaDef.name}`;
3659
+ }
3660
+ else if (metaDef.property) {
3661
+ return `property:${metaDef.property}`;
3662
+ }
3663
+ else if (metaDef.httpEquiv) {
3664
+ return `httpEquiv:${metaDef.httpEquiv}`;
3665
+ }
3666
+ return Math.random().toString(); // fallback
3627
3667
  }
3628
3668
  setCanonicalUrl(url) {
3629
3669
  const canUrl = url === undefined ? this.dom.URL : url;
3670
+ const head = this.dom.getElementsByTagName('head')[0];
3671
+ const existingLinks = this.dom.querySelectorAll('link[rel="canonical"]');
3672
+ existingLinks.forEach((link) => {
3673
+ if (link.parentNode) {
3674
+ link.parentNode.removeChild(link);
3675
+ }
3676
+ });
3630
3677
  const link = this.dom.createElement('link');
3631
3678
  link.setAttribute('rel', 'canonical');
3632
- this.dom.head.appendChild(link);
3633
3679
  link.setAttribute('href', canUrl);
3680
+ head.appendChild(link);
3634
3681
  }
3635
3682
  updateCanonicalUrl(url) {
3636
3683
  const canUrl = url === undefined ? this.dom.URL : url;
@@ -3643,6 +3690,38 @@ class DigitalMarketingService {
3643
3690
  link.setAttribute('rel', 'canonical');
3644
3691
  link.setAttribute('href', canUrl);
3645
3692
  }
3693
+ updateOpenGraphTags(ogTags) {
3694
+ const metaTags = [];
3695
+ if (ogTags.title) {
3696
+ metaTags.push({ property: 'og:title', content: ogTags.title });
3697
+ metaTags.push({ name: 'twitter:title', content: ogTags.title });
3698
+ }
3699
+ if (ogTags.description) {
3700
+ metaTags.push({ property: 'og:description', content: ogTags.description });
3701
+ metaTags.push({ name: 'twitter:description', content: ogTags.description });
3702
+ }
3703
+ if (ogTags.image) {
3704
+ metaTags.push({ property: 'og:image', content: ogTags.image });
3705
+ metaTags.push({ name: 'twitter:image', content: ogTags.image });
3706
+ }
3707
+ if (ogTags.url) {
3708
+ metaTags.push({ property: 'og:url', content: ogTags.url });
3709
+ }
3710
+ metaTags.push({ name: 'twitter:card', content: 'summary_large_image' });
3711
+ this.updateMetaTags(metaTags);
3712
+ }
3713
+ clearAllMetaTags() {
3714
+ this.removePreviousMetaTags();
3715
+ this.meta.removeTag('name="description"');
3716
+ this.meta.removeTag('name="keywords"');
3717
+ const metaTagsToRemove = [
3718
+ 'property="og:title"', 'property="og:description"', 'property="og:image"', 'property="og:url"',
3719
+ 'name="twitter:title"', 'name="twitter:description"', 'name="twitter:image"', 'name="twitter:card"'
3720
+ ];
3721
+ metaTagsToRemove.forEach(selector => {
3722
+ this.meta.removeTag(selector);
3723
+ });
3724
+ }
3646
3725
  static { this.ɵfac = function DigitalMarketingService_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || DigitalMarketingService)(i0.ɵɵinject(i1$7.Title), i0.ɵɵinject(i1$7.Meta), i0.ɵɵinject(DOCUMENT)); }; }
3647
3726
  static { this.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: DigitalMarketingService, factory: DigitalMarketingService.ɵfac, providedIn: 'root' }); }
3648
3727
  }