[Library] update SEO service: rel canonical tag work also for server side| update method signature
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@54748 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
21d8198774
commit
dfdc601812
|
@ -34,7 +34,7 @@ private seoService: SEOService) {
|
||||||
|
|
||||||
});
|
});
|
||||||
this.sub = this.route.queryParams.subscribe(params => {
|
this.sub = this.route.queryParams.subscribe(params => {
|
||||||
this.seoService.createLinkForCanonicalURL(false);
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url, false);
|
||||||
|
|
||||||
if( this.myClaims){
|
if( this.myClaims){
|
||||||
this.fetchBy = "User";
|
this.fetchBy = "User";
|
||||||
|
|
|
@ -51,7 +51,6 @@ export class DirectLinkingComponent {
|
||||||
|
|
||||||
this._meta.updateTag({content:title},"property='og:title'");
|
this._meta.updateTag({content:title},"property='og:title'");
|
||||||
this._title.setTitle(title);
|
this._title.setTitle(title);
|
||||||
this.seoService.createLinkForCanonicalURL(false);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
@ -59,6 +58,7 @@ export class DirectLinkingComponent {
|
||||||
.subscribe((data: { envSpecific: EnvProperties }) => {
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
||||||
this.properties = data.envSpecific;
|
this.properties = data.envSpecific;
|
||||||
this.url = data.envSpecific.baseLink+this._router.url;
|
this.url = data.envSpecific.baseLink+this._router.url;
|
||||||
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url, false);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,6 @@ export class LinkingGenericComponent {
|
||||||
var title = "OpenAIRE | Linking";
|
var title = "OpenAIRE | Linking";
|
||||||
this._meta.updateTag({content:title},"property='og:title'");
|
this._meta.updateTag({content:title},"property='og:title'");
|
||||||
this._title.setTitle(title);
|
this._title.setTitle(title);
|
||||||
this.seoService.createLinkForCanonicalURL(false);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -62,6 +61,7 @@ export class LinkingGenericComponent {
|
||||||
.subscribe((data: { envSpecific: EnvProperties }) => {
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
||||||
this.properties = data.envSpecific;
|
this.properties = data.envSpecific;
|
||||||
this.url = data.envSpecific.baseLink+this._router.url;
|
this.url = data.envSpecific.baseLink+this._router.url;
|
||||||
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url, false);
|
||||||
|
|
||||||
});
|
});
|
||||||
if( typeof localStorage !== 'undefined') {
|
if( typeof localStorage !== 'undefined') {
|
||||||
|
|
|
@ -70,7 +70,7 @@ export class DepositBySubjectResultComponent {
|
||||||
|
|
||||||
this.updateTitle(title);
|
this.updateTitle(title);
|
||||||
this.updateDescription(description);
|
this.updateDescription(description);
|
||||||
this.seoService.createLinkForCanonicalURL(false);
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ export class DepositComponent {
|
||||||
|
|
||||||
var title = "Deposit "+this.requestFor;
|
var title = "Deposit "+this.requestFor;
|
||||||
var description = "Openaire, repositories, open access, content provider, compatibility, organization, deposit "+ this.requestFor;
|
var description = "Openaire, repositories, open access, content provider, compatibility, organization, deposit "+ this.requestFor;
|
||||||
this.seoService.createLinkForCanonicalURL(false);
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url, false);
|
||||||
this.updateTitle(title);
|
this.updateTitle(title);
|
||||||
this.updateDescription(description);
|
this.updateDescription(description);
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,7 +189,6 @@ export class DepositResultComponent {
|
||||||
|
|
||||||
var description = "Deposit "+this.requestFor;
|
var description = "Deposit "+this.requestFor;
|
||||||
var title = "Openaire, repositories, open access, content provider, compatibility, organization, deposit "+ this.requestFor;
|
var title = "Openaire, repositories, open access, content provider, compatibility, organization, deposit "+ this.requestFor;
|
||||||
this.seoService.createLinkForCanonicalURL(false);
|
|
||||||
|
|
||||||
this.updateTitle(title);
|
this.updateTitle(title);
|
||||||
this.updateDescription(description);
|
this.updateDescription(description);
|
||||||
|
@ -199,6 +198,7 @@ export class DepositResultComponent {
|
||||||
this.route.data
|
this.route.data
|
||||||
.subscribe((data: { envSpecific: EnvProperties }) => {
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
||||||
this.properties = data.envSpecific;
|
this.properties = data.envSpecific;
|
||||||
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url, false);
|
||||||
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
||||||
this.url = data.envSpecific.baseLink+this._router.url;
|
this.url = data.envSpecific.baseLink+this._router.url;
|
||||||
|
|
||||||
|
|
|
@ -131,12 +131,12 @@ export class DataProviderComponent {
|
||||||
.subscribe((data: { envSpecific: EnvProperties }) => {
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
||||||
this.properties = data.envSpecific;
|
this.properties = data.envSpecific;
|
||||||
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
||||||
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
|
||||||
|
|
||||||
});
|
});
|
||||||
this.sub = this.route.queryParams.subscribe(data => {
|
this.sub = this.route.queryParams.subscribe(data => {
|
||||||
this.updateTitle("Content provider");
|
this.updateTitle("Content provider");
|
||||||
this.updateDescription("");
|
this.updateDescription("");
|
||||||
this.seoService.createLinkForCanonicalURL();
|
|
||||||
this.datasourceId = data['datasourceId'];
|
this.datasourceId = data['datasourceId'];
|
||||||
if(this.datasourceId){
|
if(this.datasourceId){
|
||||||
this.getDataProviderInfo(this.datasourceId);
|
this.getDataProviderInfo(this.datasourceId);
|
||||||
|
|
|
@ -69,13 +69,13 @@ export class DatasetComponent {
|
||||||
.subscribe((data: { envSpecific: EnvProperties }) => {
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
||||||
this.properties = data.envSpecific;
|
this.properties = data.envSpecific;
|
||||||
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
||||||
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
|
||||||
|
|
||||||
});
|
});
|
||||||
this.sub = this.route.queryParams.subscribe(params => {
|
this.sub = this.route.queryParams.subscribe(params => {
|
||||||
this.datasetInfo = null;
|
this.datasetInfo = null;
|
||||||
this.updateTitle("Dataset");
|
this.updateTitle("Dataset");
|
||||||
this.updateDescription("");
|
this.updateDescription("");
|
||||||
this.seoService.createLinkForCanonicalURL();
|
|
||||||
|
|
||||||
this.datasetId = params['datasetId'];
|
this.datasetId = params['datasetId'];
|
||||||
console.info("Id is :"+this.datasetId);
|
console.info("Id is :"+this.datasetId);
|
||||||
|
@ -133,7 +133,7 @@ export class DatasetComponent {
|
||||||
*/
|
*/
|
||||||
if(this.datasetInfo.title){
|
if(this.datasetInfo.title){
|
||||||
this.updateTitle(this.datasetInfo.title);
|
this.updateTitle(this.datasetInfo.title);
|
||||||
this.updateDescription((this.datasetInfo.description?(this.datasetInfo.description):(","+this.datasetInfo.title)));
|
this.updateDescription((this.datasetInfo.description?(this.datasetInfo.description):(","+this.datasetInfo.title)));
|
||||||
}
|
}
|
||||||
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
|
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
|
||||||
this.piwiksub = this._piwikService.trackView(this.properties, this.datasetInfo.title/*.name*/, this.piwikSiteId).subscribe();
|
this.piwiksub = this._piwikService.trackView(this.properties, this.datasetInfo.title/*.name*/, this.piwikSiteId).subscribe();
|
||||||
|
|
|
@ -79,6 +79,7 @@ export class HtmlProjectReportComponent{
|
||||||
.subscribe((data: { envSpecific: EnvProperties }) => {
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
||||||
this.properties = data.envSpecific;
|
this.properties = data.envSpecific;
|
||||||
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
||||||
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
|
||||||
|
|
||||||
});
|
});
|
||||||
this.sub = this.route.queryParams.subscribe(params => {
|
this.sub = this.route.queryParams.subscribe(params => {
|
||||||
|
@ -106,7 +107,7 @@ export class HtmlProjectReportComponent{
|
||||||
var description = "project, project "+ this.resultsType +" report, funding, open access, publications, research data, software, other research products";
|
var description = "project, project "+ this.resultsType +" report, funding, open access, publications, research data, software, other research products";
|
||||||
this.updateTitle(title);
|
this.updateTitle(title);
|
||||||
this.updateDescription(description);
|
this.updateDescription(description);
|
||||||
this.seoService.createLinkForCanonicalURL();
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.showLoading = false;
|
this.showLoading = false;
|
||||||
|
|
|
@ -124,14 +124,13 @@ export class OrganizationComponent {
|
||||||
.subscribe((data: { envSpecific: EnvProperties }) => {
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
||||||
this.properties = data.envSpecific;
|
this.properties = data.envSpecific;
|
||||||
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
||||||
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
|
||||||
});
|
});
|
||||||
console.info('organization init');
|
console.info('organization init');
|
||||||
this.sub = this.route.queryParams.subscribe(params => {
|
this.sub = this.route.queryParams.subscribe(params => {
|
||||||
this.organizationInfo=null;
|
this.organizationInfo=null;
|
||||||
this.updateTitle("Organization");
|
this.updateTitle("Organization");
|
||||||
this.updateDescription("");
|
this.updateDescription("");
|
||||||
this.seoService.createLinkForCanonicalURL();
|
|
||||||
this.projectsClicked = false;
|
this.projectsClicked = false;
|
||||||
|
|
||||||
this.organizationId = params['organizationId'];
|
this.organizationId = params['organizationId'];
|
||||||
|
|
|
@ -69,13 +69,13 @@ export class OrpComponent {
|
||||||
.subscribe((data: { envSpecific: EnvProperties }) => {
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
||||||
this.properties = data.envSpecific;
|
this.properties = data.envSpecific;
|
||||||
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
||||||
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
|
||||||
|
|
||||||
});
|
});
|
||||||
this.sub = this.route.queryParams.subscribe(params => {
|
this.sub = this.route.queryParams.subscribe(params => {
|
||||||
this.orpInfo = null;
|
this.orpInfo = null;
|
||||||
this.updateTitle("Other Research Product");
|
this.updateTitle("Other Research Product");
|
||||||
this.updateDescription("");
|
this.updateDescription("");
|
||||||
this.seoService.createLinkForCanonicalURL();
|
|
||||||
this.orpId = params['orpId'];
|
this.orpId = params['orpId'];
|
||||||
console.info("Id is :"+this.orpId);
|
console.info("Id is :"+this.orpId);
|
||||||
|
|
||||||
|
|
|
@ -135,9 +135,8 @@ properties:EnvProperties;
|
||||||
var description = "";
|
var description = "";
|
||||||
|
|
||||||
this.updateTitle(title);
|
this.updateTitle(title);
|
||||||
this.updateDescription(description);
|
this.updateDescription(description);
|
||||||
this.seoService.createLinkForCanonicalURL();
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
|
||||||
|
|
||||||
this.projectId = params['projectId'];
|
this.projectId = params['projectId'];
|
||||||
var grantId = params['grantId'];
|
var grantId = params['grantId'];
|
||||||
var funder = params['funder'];
|
var funder = params['funder'];
|
||||||
|
|
|
@ -91,8 +91,7 @@ export class PublicationComponent {
|
||||||
this.publicationInfo = null;
|
this.publicationInfo = null;
|
||||||
this.updateTitle("Publication");
|
this.updateTitle("Publication");
|
||||||
this.updateDescription("");
|
this.updateDescription("");
|
||||||
this.seoService.createLinkForCanonicalURL();
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
|
||||||
|
|
||||||
this.articleId = data['articleId'];
|
this.articleId = data['articleId'];
|
||||||
console.info("Article id is :"+this.articleId);
|
console.info("Article id is :"+this.articleId);
|
||||||
|
|
||||||
|
|
|
@ -68,14 +68,14 @@ export class SoftwareComponent {
|
||||||
.subscribe((data: { envSpecific: EnvProperties }) => {
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
||||||
this.properties = data.envSpecific;
|
this.properties = data.envSpecific;
|
||||||
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
||||||
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
|
||||||
|
|
||||||
});
|
});
|
||||||
this.sub = this.route.queryParams.subscribe(params => {
|
this.sub = this.route.queryParams.subscribe(params => {
|
||||||
this.softwareInfo = null;
|
this.softwareInfo = null;
|
||||||
this.updateTitle("Software");
|
this.updateTitle("Software");
|
||||||
this.updateDescription("Software, search, open access");
|
this.updateDescription("Software, search, open access");
|
||||||
this.seoService.createLinkForCanonicalURL();
|
|
||||||
|
|
||||||
this.softwareId = params['softwareId'];
|
this.softwareId = params['softwareId'];
|
||||||
console.info("Id is :"+this.softwareId);
|
console.info("Id is :"+this.softwareId);
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ public subPub;public subData; public subSoftware; public subOrps; public subProj
|
||||||
this._meta.updateTag({content:description},"property='og:description'");
|
this._meta.updateTag({content:description},"property='og:description'");
|
||||||
this._meta.updateTag({content:title},"property='og:title'");
|
this._meta.updateTag({content:title},"property='og:title'");
|
||||||
this._meta.updateTag({content:url},"property='og:url'");
|
this._meta.updateTag({content:url},"property='og:url'");
|
||||||
this.seoService.createLinkForCanonicalURL(false);
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url,false);
|
||||||
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
|
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
|
||||||
this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE |Search publications, research data, projects...", this.piwikSiteId).subscribe();
|
this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE |Search publications, research data, projects...", this.piwikSiteId).subscribe();
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ export class AdvancedSearchPageComponent {
|
||||||
this.searchUtils.baseUrl = "/" + this.searchUtils.baseUrl;
|
this.searchUtils.baseUrl = "/" + this.searchUtils.baseUrl;
|
||||||
|
|
||||||
this.updateBaseUrlWithParameters();
|
this.updateBaseUrlWithParameters();
|
||||||
this.seoService.createLinkForCanonicalURL(false);
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this.router.url,false);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ export class SearchPageComponent {
|
||||||
this.updateTitle(this.pageTitle);
|
this.updateTitle(this.pageTitle);
|
||||||
var description = "Openaire, search, repositories, open access, type, content provider, funder, project, " + this.type + "," +this.pageTitle;
|
var description = "Openaire, search, repositories, open access, type, content provider, funder, project, " + this.type + "," +this.pageTitle;
|
||||||
this.updateDescription(description);
|
this.updateDescription(description);
|
||||||
this.seoService.createLinkForCanonicalURL(false);
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this.router.url,false);
|
||||||
}
|
}
|
||||||
ngAfterViewChecked(){
|
ngAfterViewChecked(){
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import {ViewChild, Output} from '@angular/core';
|
||||||
import {EventEmitter, ViewEncapsulation} from '@angular/core';
|
import {EventEmitter, ViewEncapsulation} from '@angular/core';
|
||||||
import {OnInit, AfterViewInit} from '@angular/core';
|
import {OnInit, AfterViewInit} from '@angular/core';
|
||||||
import {Location} from '@angular/common';
|
import {Location} from '@angular/common';
|
||||||
import {ActivatedRoute} from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
import {Title, Meta} from '@angular/platform-browser';
|
import {Title, Meta} from '@angular/platform-browser';
|
||||||
|
|
||||||
import {Observable} from 'rxjs/Observable';
|
import {Observable} from 'rxjs/Observable';
|
||||||
|
@ -79,6 +79,7 @@ export class SearchPageTableViewComponent implements OnInit, AfterViewInit {
|
||||||
properties:EnvProperties;
|
properties:EnvProperties;
|
||||||
url = null;
|
url = null;
|
||||||
constructor (private route: ActivatedRoute,
|
constructor (private route: ActivatedRoute,
|
||||||
|
private router: Router,
|
||||||
private location: Location,
|
private location: Location,
|
||||||
private _meta: Meta,
|
private _meta: Meta,
|
||||||
private _title: Title,
|
private _title: Title,
|
||||||
|
@ -108,7 +109,7 @@ export class SearchPageTableViewComponent implements OnInit, AfterViewInit {
|
||||||
this.updateTitle(this.pageTitle);
|
this.updateTitle(this.pageTitle);
|
||||||
var description = "Openaire, search, repositories, open access, type, content provider, funder, project, " + this.type + "," +this.pageTitle;
|
var description = "Openaire, search, repositories, open access, type, content provider, funder, project, " + this.type + "," +this.pageTitle;
|
||||||
this.updateDescription(description);
|
this.updateDescription(description);
|
||||||
this.seoService.createLinkForCanonicalURL(false);
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this.router.url,false);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,25 @@
|
||||||
import { Injectable, Inject } from '@angular/core';
|
import { Injectable, Inject } from '@angular/core';
|
||||||
import { DOCUMENT } from '@angular/common';
|
import { DOCUMENT } from '@angular/common';
|
||||||
|
import { Optional, RendererFactory2, ViewEncapsulation } from '@angular/core';
|
||||||
|
|
||||||
// @Injectable({
|
|
||||||
// providedIn: 'root'
|
|
||||||
// })
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SEOService {
|
export class SEOService {
|
||||||
constructor( @Inject(DOCUMENT) private doc) {
|
constructor( @Inject(DOCUMENT) private doc,
|
||||||
|
private rendererFactory: RendererFactory2,
|
||||||
|
@Inject(DOCUMENT) private document) {
|
||||||
}
|
}
|
||||||
|
|
||||||
createLinkForCanonicalURL(addParameters:boolean=true) {
|
createLinkForCanonicalURL(url:string, addParameters:boolean=true) {
|
||||||
var url = "";
|
if(this.doc && (typeof this.doc.getElementById === "function" || typeof this.doc.createElement === "function") ){
|
||||||
if(this.doc ){
|
|
||||||
if(addParameters || !this.doc.URL || this.doc.URL.indexOf("?") == -1){
|
if(addParameters || !this.doc.URL || this.doc.URL.indexOf("?") == -1){
|
||||||
url = this.doc.URL;
|
url = this.doc.URL;
|
||||||
}else{
|
}else{
|
||||||
url = this.doc.URL.substring(0,this.doc.URL.indexOf("?"));
|
url = this.doc.URL.substring(0,this.doc.URL.indexOf("?"));
|
||||||
}
|
}
|
||||||
console.log("createLinkForCanonicalURL");
|
|
||||||
|
|
||||||
if (typeof this.doc.getElementById === "function") {
|
if (typeof this.doc.getElementById === "function") {
|
||||||
let currentLink: HTMLLinkElement = this.doc.getElementById("relcan");
|
let currentLink: HTMLLinkElement = this.doc.getElementById("relcan");
|
||||||
if(currentLink ){
|
if(currentLink ){
|
||||||
currentLink.setAttribute('href', url);
|
currentLink.setAttribute('href', url);
|
||||||
console.log("update canonical url:" + url);
|
|
||||||
|
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,12 +28,109 @@ export class SEOService {
|
||||||
link.setAttribute('id', 'relcan');
|
link.setAttribute('id', 'relcan');
|
||||||
link.setAttribute('rel', 'canonical');
|
link.setAttribute('rel', 'canonical');
|
||||||
this.doc.head.appendChild(link);
|
this.doc.head.appendChild(link);
|
||||||
console.log("create new canonical url:" + url);
|
|
||||||
|
|
||||||
link.setAttribute('href', url);
|
link.setAttribute('href', url);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}else{
|
||||||
|
try {
|
||||||
|
const renderer = this.rendererFactory.createRenderer(this.document, {
|
||||||
|
id: '-1',
|
||||||
|
encapsulation: ViewEncapsulation.None,
|
||||||
|
styles: [],
|
||||||
|
data: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
const link = renderer.createElement('link');
|
||||||
|
const head = this.document.head;
|
||||||
|
|
||||||
|
if (head === null) {
|
||||||
|
throw new Error('<head> not found within DOCUMENT.');
|
||||||
|
}
|
||||||
|
renderer.setAttribute(link, "rel", "canonical");
|
||||||
|
renderer.setAttribute(link, "href", (addParameters)?url:this.doc.URL.split("?")[0]);
|
||||||
|
renderer.setAttribute(link, "id", "relcan");
|
||||||
|
// [TODO]: get them to update the existing one (if it exists) ?
|
||||||
|
renderer.appendChild(head, link);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error within linkService : ', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* -- LinkService -- [Temporary]
|
||||||
|
* @MarkPieszak
|
||||||
|
*
|
||||||
|
* Similar to Meta service but made to handle <link> creation for SEO purposes
|
||||||
|
* -- NOTE: Soon there will be an overall DocumentService within Angular that handles Meta/Link everything
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
// import { Injectable, Optional, RendererFactory2, ViewEncapsulation, Inject } from '@angular/core';
|
||||||
|
// import { DOCUMENT } from '@angular/platform-browser';
|
||||||
|
//
|
||||||
|
// @Injectable()
|
||||||
|
// export class LinkService {
|
||||||
|
//
|
||||||
|
// constructor(
|
||||||
|
// private rendererFactory: RendererFactory2,
|
||||||
|
// @Inject(DOCUMENT) private document
|
||||||
|
// ) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inject the State into the bottom of the <head>
|
||||||
|
*/
|
||||||
|
// addTag(tag: LinkDefinition, forceCreation?: boolean) {
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// const renderer = this.rendererFactory.createRenderer(this.document, {
|
||||||
|
// id: '-1',
|
||||||
|
// encapsulation: ViewEncapsulation.None,
|
||||||
|
// styles: [],
|
||||||
|
// data: {}
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// const link = renderer.createElement('link');
|
||||||
|
// const head = this.document.head;
|
||||||
|
// const selector = this._parseSelector(tag);
|
||||||
|
//
|
||||||
|
// if (head === null) {
|
||||||
|
// throw new Error('<head> not found within DOCUMENT.');
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Object.keys(tag).forEach((prop: string) => {
|
||||||
|
// return renderer.setAttribute(link, prop, tag[prop]);
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// // [TODO]: get them to update the existing one (if it exists) ?
|
||||||
|
// renderer.appendChild(head, link);
|
||||||
|
//
|
||||||
|
// } catch (e) {
|
||||||
|
// console.error('Error within linkService : ', e);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private _parseSelector(tag: LinkDefinition): string {
|
||||||
|
// // Possibly re-work this
|
||||||
|
// const attr: string = tag.rel ? 'rel' : 'hreflang';
|
||||||
|
// return `${attr}="${tag[attr]}"`;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
export declare type LinkDefinition = {
|
||||||
|
charset?: string;
|
||||||
|
crossorigin?: string;
|
||||||
|
href?: string;
|
||||||
|
hreflang?: string;
|
||||||
|
media?: string;
|
||||||
|
rel?: string;
|
||||||
|
rev?: string;
|
||||||
|
sizes?: string;
|
||||||
|
target?: string;
|
||||||
|
type?: string;
|
||||||
|
} & {
|
||||||
|
[prop: string]: string;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue