Project

General

Profile

« Previous | Next » 

Revision 54748

[Library] update SEO service: rel canonical tag work also for server side| update method signature

View differences:

modules/uoa-services-library/trunk/ng-openaire-library/src/app/searchPages/find/search.component.ts
145 145
        this._meta.updateTag({content:description},"property='og:description'");
146 146
        this._meta.updateTag({content:title},"property='og:title'");
147 147
        this._meta.updateTag({content:url},"property='og:url'");
148
        this.seoService.createLinkForCanonicalURL(false);
148
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url,false);
149 149
        if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
150 150
          this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE |Search publications, research data, projects...", this.piwikSiteId).subscribe();
151 151

  
modules/uoa-services-library/trunk/ng-openaire-library/src/app/searchPages/searchUtils/searchPage.component.ts
105 105
        this.updateTitle(this.pageTitle);
106 106
        var description = "Openaire, search, repositories, open access, type, content provider, funder, project, " + this.type + "," +this.pageTitle;
107 107
        this.updateDescription(description);
108
        this.seoService.createLinkForCanonicalURL(false);
108
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this.router.url,false);
109 109
  }
110 110
  ngAfterViewChecked(){
111 111

  
modules/uoa-services-library/trunk/ng-openaire-library/src/app/searchPages/searchUtils/searchPageTableView.component.ts
3 3
import {EventEmitter, ViewEncapsulation}  from '@angular/core';
4 4
import {OnInit, AfterViewInit}            from '@angular/core';
5 5
import {Location}                         from '@angular/common';
6
import {ActivatedRoute}                   from '@angular/router';
6
import {ActivatedRoute, Router}                   from '@angular/router';
7 7
import {Title, Meta}                      from '@angular/platform-browser';
8 8

  
9 9
import {Observable}                       from 'rxjs/Observable';
......
79 79
  properties:EnvProperties;
80 80
  url = null;
81 81
  constructor (private route: ActivatedRoute,
82
               private router: Router,
82 83
               private location: Location,
83 84
               private _meta: Meta,
84 85
               private _title: Title,
......
108 109
        this.updateTitle(this.pageTitle);
109 110
        var description = "Openaire, search, repositories, open access, type, content provider, funder, project, " + this.type + "," +this.pageTitle;
110 111
        this.updateDescription(description);
111
        this.seoService.createLinkForCanonicalURL(false);
112
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this.router.url,false);
112 113

  
113 114

  
114 115
   }
modules/uoa-services-library/trunk/ng-openaire-library/src/app/searchPages/searchUtils/advancedSearchPage.component.ts
94 94
    this.searchUtils.baseUrl = "/" + this.searchUtils.baseUrl;
95 95

  
96 96
    this.updateBaseUrlWithParameters();
97
    this.seoService.createLinkForCanonicalURL(false);
97
    this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this.router.url,false);
98 98

  
99 99

  
100 100
  }
modules/uoa-services-library/trunk/ng-openaire-library/src/app/landingPages/orp/orp.component.ts
69 69
        .subscribe((data: { envSpecific: EnvProperties }) => {
70 70
           this.properties = data.envSpecific;
71 71
           this.updateUrl(data.envSpecific.baseLink+this._router.url);
72
           this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
72 73

  
73 74
        });
74 75
      this.sub =  this.route.queryParams.subscribe(params => {
75 76
          this.orpInfo = null;
76 77
          this.updateTitle("Other Research Product");
77 78
          this.updateDescription("");
78
          this.seoService.createLinkForCanonicalURL();
79 79
            this.orpId = params['orpId'];
80 80
             console.info("Id is :"+this.orpId);
81 81

  
modules/uoa-services-library/trunk/ng-openaire-library/src/app/landingPages/dataProvider/dataProvider.component.ts
131 131
     .subscribe((data: { envSpecific: EnvProperties }) => {
132 132
        this.properties = data.envSpecific;
133 133
        this.updateUrl(data.envSpecific.baseLink+this._router.url);
134
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
134 135

  
135 136
     });
136 137
   this.sub =  this.route.queryParams.subscribe(data => {
137 138
      this.updateTitle("Content provider");
138 139
      this.updateDescription("");
139
      this.seoService.createLinkForCanonicalURL();
140 140
      this.datasourceId = data['datasourceId'];
141 141
      if(this.datasourceId){
142 142
       this.getDataProviderInfo(this.datasourceId);
modules/uoa-services-library/trunk/ng-openaire-library/src/app/landingPages/organization/organization.component.ts
124 124
        .subscribe((data: { envSpecific: EnvProperties }) => {
125 125
           this.properties = data.envSpecific;
126 126
           this.updateUrl(data.envSpecific.baseLink+this._router.url);
127

  
127
           this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
128 128
        });
129 129
        console.info('organization init');
130 130
        this.sub =  this.route.queryParams.subscribe(params => {
131 131
            this.organizationInfo=null;
132 132
            this.updateTitle("Organization");
133 133
            this.updateDescription("");
134
            this.seoService.createLinkForCanonicalURL();
135 134
            this.projectsClicked = false;
136 135

  
137 136
            this.organizationId = params['organizationId'];
modules/uoa-services-library/trunk/ng-openaire-library/src/app/landingPages/dataset/dataset.component.ts
69 69
        .subscribe((data: { envSpecific: EnvProperties }) => {
70 70
           this.properties = data.envSpecific;
71 71
           this.updateUrl(data.envSpecific.baseLink+this._router.url);
72
           this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
72 73

  
73 74
        });
74 75
      this.sub =  this.route.queryParams.subscribe(params => {
75 76
          this.datasetInfo = null;
76 77
          this.updateTitle("Dataset");
77 78
          this.updateDescription("");
78
          this.seoService.createLinkForCanonicalURL();
79 79

  
80 80
            this.datasetId = params['datasetId'];
81 81
             console.info("Id is :"+this.datasetId);
......
133 133
                */
134 134
                if(this.datasetInfo.title){
135 135
                  this.updateTitle(this.datasetInfo.title);
136
                  this.updateDescription((this.datasetInfo.description?(this.datasetInfo.description):(","+this.datasetInfo.title)));                  
136
                  this.updateDescription((this.datasetInfo.description?(this.datasetInfo.description):(","+this.datasetInfo.title)));
137 137
                }
138 138
                if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
139 139
                  this.piwiksub = this._piwikService.trackView(this.properties, this.datasetInfo.title/*.name*/, this.piwikSiteId).subscribe();
modules/uoa-services-library/trunk/ng-openaire-library/src/app/landingPages/project/project.component.ts
135 135
        var description = "";
136 136

  
137 137
        this.updateTitle(title);
138
        this.updateDescription(description);
139
        this.seoService.createLinkForCanonicalURL();
140

  
138
        this.updateDescription(description);        
139
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
141 140
      this.projectId = params['projectId'];
142 141
      var grantId = params['grantId'];
143 142
      var funder = params['funder'];
modules/uoa-services-library/trunk/ng-openaire-library/src/app/landingPages/htmlProjectReport/htmlProjectReport.component.ts
79 79
        .subscribe((data: { envSpecific: EnvProperties }) => {
80 80
           this.properties = data.envSpecific;
81 81
           this.updateUrl(data.envSpecific.baseLink+this._router.url);
82
           this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
82 83

  
83 84
        });
84 85
        this.sub =  this.route.queryParams.subscribe(params => {
......
106 107
              var description = "project, project "+ this.resultsType +" report, funding, open access, publications, research data, software, other research products";
107 108
              this.updateTitle(title);
108 109
              this.updateDescription(description);
109
              this.seoService.createLinkForCanonicalURL();
110 110

  
111

  
111 112
            } else {
112 113
              this.showLoading = false;
113 114
    		      this.warningMessage="Requested type should be publication or research data or software or other research product";
modules/uoa-services-library/trunk/ng-openaire-library/src/app/landingPages/publication/publication.component.ts
91 91
           this.publicationInfo = null;
92 92
           this.updateTitle("Publication");
93 93
           this.updateDescription("");
94
           this.seoService.createLinkForCanonicalURL();
95

  
94
           this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
96 95
          this.articleId = data['articleId'];
97 96
          console.info("Article id is :"+this.articleId);
98 97

  
modules/uoa-services-library/trunk/ng-openaire-library/src/app/landingPages/software/software.component.ts
68 68
        .subscribe((data: { envSpecific: EnvProperties }) => {
69 69
           this.properties = data.envSpecific;
70 70
           this.updateUrl(data.envSpecific.baseLink+this._router.url);
71
           this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
71 72

  
72 73
        });
73 74
      this.sub =  this.route.queryParams.subscribe(params => {
74 75
          this.softwareInfo = null;
75 76
          this.updateTitle("Software");
76 77
          this.updateDescription("Software, search, open access");
77
          this.seoService.createLinkForCanonicalURL();
78

  
78
          
79 79
            this.softwareId = params['softwareId'];
80 80
             console.info("Id is :"+this.softwareId);
81 81

  
modules/uoa-services-library/trunk/ng-openaire-library/src/app/deposit/datasets/depositBySubjectResult.component.ts
70 70

  
71 71
          this.updateTitle(title);
72 72
          this.updateDescription(description);
73
          this.seoService.createLinkForCanonicalURL(false);
73
          this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url, false);
74 74

  
75 75
  }
76 76

  
modules/uoa-services-library/trunk/ng-openaire-library/src/app/deposit/depositResult.component.ts
189 189

  
190 190
      var description = "Deposit "+this.requestFor;
191 191
      var title = "Openaire, repositories, open access, content provider, compatibility, organization, deposit "+ this.requestFor;
192
      this.seoService.createLinkForCanonicalURL(false);
193 192

  
194 193
      this.updateTitle(title);
195 194
      this.updateDescription(description);
......
199 198
      this.route.data
200 199
        .subscribe((data: { envSpecific: EnvProperties }) => {
201 200
           this.properties = data.envSpecific;
201
           this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url, false);
202 202
           this.updateUrl(data.envSpecific.baseLink+this._router.url);
203 203
           this.url = data.envSpecific.baseLink+this._router.url;
204 204

  
modules/uoa-services-library/trunk/ng-openaire-library/src/app/deposit/deposit.component.ts
51 51

  
52 52
      var title = "Deposit "+this.requestFor;
53 53
      var description = "Openaire,  repositories, open access,  content provider, compatibility, organization, deposit "+ this.requestFor;
54
      this.seoService.createLinkForCanonicalURL(false);
54
      this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url, false);
55 55
      this.updateTitle(title);
56 56
      this.updateDescription(description);
57 57
  }
modules/uoa-services-library/trunk/ng-openaire-library/src/app/claims/claim-utils/displayClaims/displayClaims.component.ts
34 34

  
35 35
      });
36 36
     this.sub = this.route.queryParams.subscribe(params => {
37
       this.seoService.createLinkForCanonicalURL(false);
37
      this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url, false);
38 38

  
39 39
      if( this.myClaims){
40 40
          this.fetchBy = "User";
modules/uoa-services-library/trunk/ng-openaire-library/src/app/claims/directLinking/directLinking.component.ts
51 51

  
52 52
                  this._meta.updateTag({content:title},"property='og:title'");
53 53
                  this._title.setTitle(title);
54
                  this.seoService.createLinkForCanonicalURL(false);
55 54

  
56 55
  }
57 56
  ngOnInit() {
......
59 58
      .subscribe((data: { envSpecific: EnvProperties }) => {
60 59
         this.properties = data.envSpecific;
61 60
         this.url = data.envSpecific.baseLink+this._router.url;
61
         this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url, false);
62 62

  
63 63
      });
64 64

  
modules/uoa-services-library/trunk/ng-openaire-library/src/app/claims/linking/linkingGeneric.component.ts
53 53
                  var title = "OpenAIRE | Linking";
54 54
                  this._meta.updateTag({content:title},"property='og:title'");
55 55
                  this._title.setTitle(title);
56
                  this.seoService.createLinkForCanonicalURL(false);
57 56

  
58 57

  
59 58
  }
......
62 61
      .subscribe((data: { envSpecific: EnvProperties }) => {
63 62
         this.properties = data.envSpecific;
64 63
         this.url = data.envSpecific.baseLink+this._router.url;
64
         this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url, false);
65 65

  
66 66
      });
67 67
      if( typeof localStorage !== 'undefined') {
modules/uoa-services-library/trunk/ng-openaire-library/src/app/sharedComponents/SEO/SEO.service.ts
1 1
import { Injectable, Inject } from '@angular/core';
2 2
import { DOCUMENT } from '@angular/common';
3
import {  Optional, RendererFactory2, ViewEncapsulation } from '@angular/core';
3 4

  
4
// @Injectable({
5
//    providedIn: 'root'
6
// })
7 5
@Injectable()
8 6
export class SEOService {
9
   constructor( @Inject(DOCUMENT) private doc) {
7
   constructor( @Inject(DOCUMENT) private doc,
8
   private rendererFactory: RendererFactory2,
9
   @Inject(DOCUMENT) private document) {
10 10
   }
11 11

  
12
   createLinkForCanonicalURL(addParameters:boolean=true) {
13
       var url = "";
14
       if(this.doc  ){
12
   createLinkForCanonicalURL(url:string, addParameters:boolean=true) {
13
       if(this.doc && (typeof this.doc.getElementById === "function" || typeof this.doc.createElement === "function") ){
15 14
         if(addParameters ||  !this.doc.URL || this.doc.URL.indexOf("?") == -1){
16 15
           url = this.doc.URL;
17 16
         }else{
18 17
           url = this.doc.URL.substring(0,this.doc.URL.indexOf("?"));
19 18
         }
20
         console.log("createLinkForCanonicalURL");
21

  
22 19
        if (typeof this.doc.getElementById === "function") {
23 20
          let currentLink: HTMLLinkElement = this.doc.getElementById("relcan");
24 21
          if(currentLink ){
25 22
            currentLink.setAttribute('href', url);
26
            console.log("update canonical url:" + url);
27

  
28 23
            return ;
29 24
          }
30 25
        }
......
33 28
          link.setAttribute('id', 'relcan');
34 29
          link.setAttribute('rel', 'canonical');
35 30
          this.doc.head.appendChild(link);
36
          console.log("create new  canonical url:" + url);
37

  
38 31
         link.setAttribute('href', url);
39 32
        }
40 33

  
41
       }
34
      }else{
35
        try {
36
            const renderer = this.rendererFactory.createRenderer(this.document, {
37
                id: '-1',
38
                encapsulation: ViewEncapsulation.None,
39
                styles: [],
40
                data: {}
41
            });
42

  
43
            const link = renderer.createElement('link');
44
            const head = this.document.head;
45

  
46
            if (head === null) {
47
                throw new Error('<head> not found within DOCUMENT.');
48
            }
49
            renderer.setAttribute(link, "rel", "canonical");
50
            renderer.setAttribute(link, "href", (addParameters)?url:this.doc.URL.split("?")[0]);
51
            renderer.setAttribute(link, "id", "relcan");
52
            // [TODO]: get them to update the existing one (if it exists) ?
53
            renderer.appendChild(head, link);
54
        } catch (e) {
55
            console.error('Error within linkService : ', e);
56
        }
57
      }
58

  
42 59
   }
43 60

  
44 61
}
62

  
63
/*
64
 * -- LinkService --        [Temporary]
65
 * @MarkPieszak
66
 *
67
 * Similar to Meta service but made to handle <link> creation for SEO purposes
68
 * -- NOTE: Soon there will be an overall DocumentService within Angular that handles Meta/Link everything
69
 */
70
//
71
// import { Injectable, Optional, RendererFactory2, ViewEncapsulation, Inject } from '@angular/core';
72
// import { DOCUMENT } from '@angular/platform-browser';
73
//
74
// @Injectable()
75
// export class LinkService {
76
//
77
//     constructor(
78
//         private rendererFactory: RendererFactory2,
79
//         @Inject(DOCUMENT) private document
80
//     ) {
81
//     }
82

  
83
    /**
84
     * Inject the State into the bottom of the <head>
85
     */
86
//     addTag(tag: LinkDefinition, forceCreation?: boolean) {
87
//
88
//         try {
89
//             const renderer = this.rendererFactory.createRenderer(this.document, {
90
//                 id: '-1',
91
//                 encapsulation: ViewEncapsulation.None,
92
//                 styles: [],
93
//                 data: {}
94
//             });
95
//
96
//             const link = renderer.createElement('link');
97
//             const head = this.document.head;
98
//             const selector = this._parseSelector(tag);
99
//
100
//             if (head === null) {
101
//                 throw new Error('<head> not found within DOCUMENT.');
102
//             }
103
//
104
//             Object.keys(tag).forEach((prop: string) => {
105
//                 return renderer.setAttribute(link, prop, tag[prop]);
106
//             });
107
//
108
//             // [TODO]: get them to update the existing one (if it exists) ?
109
//             renderer.appendChild(head, link);
110
//
111
//         } catch (e) {
112
//             console.error('Error within linkService : ', e);
113
//         }
114
//     }
115
//
116
//     private _parseSelector(tag: LinkDefinition): string {
117
//         // Possibly re-work this
118
//         const attr: string = tag.rel ? 'rel' : 'hreflang';
119
//         return `${attr}="${tag[attr]}"`;
120
//     }
121
// }
122

  
123
export declare type LinkDefinition = {
124
    charset?: string;
125
    crossorigin?: string;
126
    href?: string;
127
    hreflang?: string;
128
    media?: string;
129
    rel?: string;
130
    rev?: string;
131
    sizes?: string;
132
    target?: string;
133
    type?: string;
134
} & {
135
        [prop: string]: string;
136
    };

Also available in: Unified diff