@ngx-meta/core
Version:
Dynamic page title & meta tags utility for Angular (w/server-side rendering)
2 lines • 6.48 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/platform-browser"),require("rxjs")):"function"==typeof define&&define.amd?define("@ngx-meta/core",["exports","@angular/core","@angular/platform-browser","rxjs"],e):e(((t=t||self)["ngx-meta"]=t["ngx-meta"]||{},t["ngx-meta"].core={}),t.ng.core,t.ng.platformBrowser,t.rxjs)}(this,(function(t,e,i,a){"use strict";var n;(n=t.PageTitlePositioning||(t.PageTitlePositioning={}))[n.AppendPageTitle=0]="AppendPageTitle",n[n.PrependPageTitle=10]="PrependPageTitle";var o=function(){},s=function(){function e(e){void 0===e&&(e={pageTitlePositioning:t.PageTitlePositioning.PrependPageTitle,defaults:{}}),this.providedSettings=e}return Object.defineProperty(e.prototype,"settings",{get:function(){return this.providedSettings},enumerable:!0,configurable:!0}),e}(),r=function(){function n(t,e,i){this.loader=t,this.title=e,this.meta=i,this.settings=t.settings,this.isMetaTagSet={}}return n.prototype.setTitle=function(t,e){var i=this;void 0===e&&(e=!1),(t?this.callback(t):a.of("")).subscribe((function(t){var n="";t?!e&&i.settings.pageTitleSeparator&&i.settings.applicationName?i.callback(i.settings.applicationName).subscribe((function(e){n=e?i.getTitleWithPositioning(t,e):t,i.updateTitle(n)})):i.updateTitle(t):(i.settings.defaults&&i.settings.defaults.title?i.callback(i.settings.defaults.title):a.of("")).subscribe((function(t){!e&&i.settings.pageTitleSeparator&&i.settings.applicationName?i.callback(i.settings.applicationName).subscribe((function(e){n=e?i.getTitleWithPositioning(t,e):t,i.updateTitle(n)})):i.updateTitle(t)}))}))},n.prototype.setTag=function(t,e){var i=this;if("title"===t)throw new Error("Attempt to set "+t+' through "setTag": "title" is a reserved tag name. Please use `MetaService.setTitle` instead.');var n=e||(this.settings.defaults&&this.settings.defaults[t]?this.settings.defaults[t]:"");("og:locale"!==t&&"og:locale:alternate"!==t?this.callback(n):a.of(n)).subscribe((function(e){i.updateTag(t,e)}))},n.prototype.update=function(t,e){var i=this;if(e){if(e.disabled)return void this.update(t);this.setTitle(e.title,e.override),Object.keys(e).forEach((function(t){var a=e[t];if("title"!==t&&"override"!==t){if("og:locale"===t)a=a.replace(/-/g,"_");else if("og:locale:alternate"===t){var n=e["og:locale"];return void i.updateLocales(n,e[t])}i.setTag(t,a)}}))}else{var a=this.settings.defaults&&this.settings.defaults.title||this.settings.applicationName;this.setTitle(a,!0)}this.settings.defaults&&Object.keys(this.settings.defaults).forEach((function(t){var a=i.settings.defaults[t];if(!(e&&(t in i.isMetaTagSet||t in e)||"title"===t||"override"===t)){if("og:locale"===t)a=a.replace(/-/g,"_");else if("og:locale:alternate"===t){var n=e?e["og:locale"]:void 0;return void i.updateLocales(n,a)}i.setTag(t,a)}}));var n=(""+(this.settings.applicationUrl?this.settings.applicationUrl:"/")+t).replace(/(https?:\/\/)|(\/)+/g,"$1$2").replace(/\/$/g,"");this.setTag("og:url",n||"/")},n.prototype.removeTag=function(t){this.meta.removeTag(t)},n.prototype.callback=function(t){if(this.settings.callback){var e=this.settings.callback(t);return(i=e)&&"function"==typeof i.subscribe?e:function(t){return!!t&&"function"==typeof t.then}(e)?a.from(e):a.of(e)}var i;return a.of(t)},n.prototype.getTitleWithPositioning=function(e,i){switch(this.settings.pageTitlePositioning){case t.PageTitlePositioning.AppendPageTitle:return i+String(this.settings.pageTitleSeparator)+e;case t.PageTitlePositioning.PrependPageTitle:return e+String(this.settings.pageTitleSeparator)+i;default:throw new Error("Invalid pageTitlePositioning specified ["+this.settings.pageTitlePositioning+"]!")}},n.prototype.updateTitle=function(t){this.title.setTitle(t),this.meta.updateTag({property:"og:title",content:t})},n.prototype.updateLocales=function(t,e){var i=this,a=t||(this.settings.defaults?this.settings.defaults["og:locale"]:"");a&&this.settings.defaults&&(this.settings.defaults["og:locale"]=a.replace(/_/g,"-")),this.meta.getTags('property="og:locale:alternate"').forEach((function(t){i.meta.removeTagElement(t)})),a&&e&&e.split(",").forEach((function(t){a.replace(/-/g,"_")!==t.replace(/-/g,"_")&&i.meta.addTag({property:"og:locale:alternate",content:t.replace(/-/g,"_")})}))},n.prototype.updateTag=function(t,e){if(0===t.lastIndexOf("og:",0)?this.meta.updateTag({property:t,content:"og:locale"===t?e.replace(/-/g,"_"):e}):this.meta.updateTag({name:t,content:e}),this.isMetaTagSet[t]=!0,"description"===t)this.meta.updateTag({property:"og:description",content:e});else if("author"===t)this.meta.updateTag({property:"og:author",content:e});else if("publisher"===t)this.meta.updateTag({property:"og:publisher",content:e});else if("og:locale"===t){var i=this.settings.defaults?this.settings.defaults["og:locale:alternate"]:"";this.updateLocales(e,i),this.isMetaTagSet["og:locale:alternate"]=!0}else if("og:locale:alternate"===t){var a=this.meta.getTag('property="og:locale"').content;this.updateLocales(a,e),this.isMetaTagSet["og:locale"]=!0}},n.ɵfac=function(t){return new(t||n)(e.ɵɵinject(o),e.ɵɵinject(i.Title),e.ɵɵinject(i.Meta))},n.ɵprov=e.ɵɵdefineInjectable({token:n,factory:n.ɵfac}),n}();e.ɵsetClassMetadata(r,[{type:e.Injectable}],(function(){return[{type:o},{type:i.Title},{type:i.Meta}]}),null);var l=function(){function t(t){this.meta=t}return t.prototype.canActivate=function(t,e){var i=e.url,a=t.hasOwnProperty("data")?t.data.meta:void 0;return this.meta.update(i,a),!0},t.prototype.canActivateChild=function(t,e){return this.canActivate(t,e)},t.ɵfac=function(i){return new(i||t)(e.ɵɵinject(r))},t.ɵprov=e.ɵɵdefineInjectable({token:t,factory:t.ɵfac}),t}();e.ɵsetClassMetadata(l,[{type:e.Injectable}],(function(){return[{type:r}]}),null);var c=function(){return new s},g=function(){function t(t){if(t)throw new Error("MetaModule already loaded; import in root module only.")}return t.forRoot=function(e){return void 0===e&&(e={provide:o,useFactory:c}),{ngModule:t,providers:[e,l,r]}},t.ɵmod=e.ɵɵdefineNgModule({type:t}),t.ɵinj=e.ɵɵdefineInjector({factory:function(i){return new(i||t)(e.ɵɵinject(t,12))}}),t}();e.ɵsetClassMetadata(g,[{type:e.NgModule}],(function(){return[{type:g,decorators:[{type:e.Optional},{type:e.SkipSelf}]}]}),null),t.MetaGuard=l,t.MetaLoader=o,t.MetaModule=g,t.MetaService=r,t.MetaStaticLoader=s,t.metaFactory=c,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=ngx-meta-core.umd.min.js.map