1
|
import {Component, Input} from '@angular/core';
|
2
|
import {ActivatedRoute, Router} from '@angular/router';
|
3
|
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
4
|
import {Meta, Title} from "@angular/platform-browser";
|
5
|
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
|
6
|
import {PiwikService} from "../openaireLibrary/utils/piwik/piwik.service";
|
7
|
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
|
8
|
import {ConnectHelper} from "../openaireLibrary/connect/connectHelper";
|
9
|
import {Subscriber} from "rxjs";
|
10
|
import {properties} from "../../environments/environment";
|
11
|
|
12
|
@Component({
|
13
|
selector: 'html-page',
|
14
|
template: `
|
15
|
<schema2jsonld *ngIf="url" [URL]="url" [name]="pageTitle" type="other" [description]="description"></schema2jsonld>
|
16
|
<helper *ngIf="pageContents && pageContents['top'] && pageContents['top'].length > 0"
|
17
|
[texts]="pageContents['top']"></helper>
|
18
|
`
|
19
|
})
|
20
|
export class HtmlPageComponent {
|
21
|
properties: EnvProperties = properties;
|
22
|
public pageContents = null;
|
23
|
public divContents = null;
|
24
|
|
25
|
@Input() url: string = null;
|
26
|
@Input() pageTitle: string;
|
27
|
@Input() description: string;
|
28
|
private subscriptions = [];
|
29
|
communityId;
|
30
|
|
31
|
constructor(private route: ActivatedRoute, private _router: Router,
|
32
|
private _meta: Meta,
|
33
|
private _title: Title,
|
34
|
private seoService: SEOService,
|
35
|
private _piwikService: PiwikService,
|
36
|
private helper: HelperService) {
|
37
|
}
|
38
|
|
39
|
public ngOnInit() {
|
40
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
41
|
this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle, this.properties.piwikSiteId).subscribe());
|
42
|
}
|
43
|
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
|
44
|
//TODO set the proper URL
|
45
|
this.url = this.properties.domain + this._router.url;
|
46
|
this.seoService.createLinkForCanonicalURL(this.url);
|
47
|
this.updateUrl(this.url);
|
48
|
this.updateTitle(this.pageTitle);
|
49
|
this.updateDescription(this.description);
|
50
|
this.getPageContents();
|
51
|
|
52
|
}
|
53
|
|
54
|
ngOnDestroy() {
|
55
|
this.subscriptions.forEach(subscription => {
|
56
|
if (subscription instanceof Subscriber) {
|
57
|
subscription.unsubscribe();
|
58
|
}
|
59
|
});
|
60
|
}
|
61
|
|
62
|
|
63
|
private updateDescription(description: string) {
|
64
|
this._meta.updateTag({content: description}, "name='description'");
|
65
|
this._meta.updateTag({content: description}, "property='og:description'");
|
66
|
}
|
67
|
|
68
|
private updateTitle(title: string) {
|
69
|
var _title = ((title.length > 50) ? title.substring(0, 50) : title);
|
70
|
this._title.setTitle(_title);
|
71
|
this._meta.updateTag({content: _title}, "property='og:title'");
|
72
|
}
|
73
|
|
74
|
private updateUrl(url: string) {
|
75
|
this._meta.updateTag({content: url}, "property='og:url'");
|
76
|
}
|
77
|
|
78
|
private getPageContents() {
|
79
|
this.subscriptions.push(this.helper.getPageHelpContents(this.properties, this.communityId ? this.communityId : "connect", this._router.url).subscribe(contents => {
|
80
|
this.pageContents = contents;
|
81
|
}));
|
82
|
}
|
83
|
}
|