11import { Component , Input , OnInit } from '@angular/core' ;
2+ import { SettingsService } from '../services/settings.service' ;
3+
4+ import { join } from '../shared/utils' ;
25
36@Component ( {
4- selector : 'made-with-docspa' , // tslint:disable-line
5- template : `
7+ selector : 'made-with-docspa' , // tslint:disable-line
8+ template : `
69 <ng-template #noUrl>
7- by
10+ by
811 <ng-content></ng-content>
912 <slot></slot>
1013 {{name}}
1114 </ng-template>
1215 <span [style.font-size.em]="size">
1316 <ng-container *ngIf="url && url.length > 0; else noUrl">
14- By <a [attr.href]="url" target="_blank" [style.color]="color" rel="noopener">
17+ 作者: <a [attr.href]="url" target="_blank" [style.color]="color" rel="noopener">
1518 <ng-content></ng-content>
1619 <slot></slot>
1720 {{name}}
18- </a>
21+ </a>({{url}})
1922 </ng-container>
2023 </span>
2124 ` ,
22- styles : [ `
25+ styles : [ `
2326 :host {
2427 span {
2528 a {
@@ -31,23 +34,33 @@ import { Component, Input, OnInit } from '@angular/core';
3134 ` ]
3235} )
3336export class MadeWithDocSPAComponent implements OnInit {
34- static readonly is = 'made-with-docspa' ;
37+ static readonly is = 'made-with-docspa' ;
3538
36- @Input ( )
37- public name : string ;
39+ @Input ( )
40+ public color = 'red' ;
3841
39- @Input ( )
40- public url : string ;
42+ @Input ( )
43+ public size = 0.5 ;
4144
42- @Input ( )
43- public color = 'red' ;
45+ constructor (
46+ private settings : SettingsService
47+ ) { }
4448
45- @Input ( )
46- public size = 0.5 ;
49+ get bookPath ( ) {
50+ return this . settings . bookPath ;
51+ }
4752
48- ngOnInit ( ) {
49- if ( ! this . name || this . name . length === 0 ) {
50- console . error ( `Name attribute must be provided!` ) ;
53+ get name ( ) {
54+ return this . bookPath . replace ( / ^ \/ / , '' ) . replace ( / \/ $ / , '' ) . split ( '/' ) [ 1 ] ;
55+ }
56+
57+ get url ( ) {
58+ return join ( 'https://' , this . bookPath . replace ( / \/ $ / , '' ) . replace ( / \/ [ ^ \/ ] { 1 , 254 } $ / , '' ) ) ;
59+ }
60+
61+ ngOnInit ( ) {
62+ if ( ! this . name || this . name . length === 0 ) {
63+ console . error ( `Name attribute must be provided!` ) ;
64+ }
5165 }
52- }
5366}
0 commit comments