1
- import type { IWebSite } from '@sveltinio/seo/types' ;
2
- import type { Sveltin } from 'src/sveltin' ;
1
+ import type { Sveltin } from '$sveltin' ;
3
2
4
- export const ToTitle = ( text : string ) : string => {
5
- return CapitalizeAll ( text . replace ( / - / g, ' ' ) ) ;
3
+ export const toTitle = ( text : string ) : string => {
4
+ return capitalizeAll ( text . replace ( / - / g, ' ' ) ) ;
6
5
} ;
7
6
8
- export const CapitalizeAll = ( text : string ) : string => {
7
+ export const capitalizeAll = ( text : string ) : string => {
9
8
const splitted = text . toLowerCase ( ) . split ( ' ' ) ;
10
9
const capitalized : Array < string > = [ ] ;
11
10
12
11
splitted . forEach ( function ( item ) {
13
- capitalized . push ( CapitalizeFirstLetter ( item ) ) ;
12
+ capitalized . push ( capitalizeFirstLetter ( item ) ) ;
14
13
} ) ;
15
14
return capitalized . join ( ' ' ) ;
16
15
} ;
17
16
18
- export const CapitalizeFirstLetter = ( text : string ) : string => {
17
+ export const capitalizeFirstLetter = ( text : string ) : string => {
19
18
return text . charAt ( 0 ) . toUpperCase ( ) + text . substring ( 1 ) . toLowerCase ( ) ;
20
19
} ;
21
20
22
- export const ToSlug = ( text : string ) : string => {
21
+ export const toSlug = ( text : string ) : string => {
23
22
return text
24
23
. toLowerCase ( )
25
24
. replace ( / [ ^ \w ] + / g, '' )
@@ -34,19 +33,25 @@ export const removeTrailingSlash = (text: string): string => {
34
33
return text . replace ( / \/ + $ / , '' ) ;
35
34
} ;
36
35
37
- export const getPageUrl = ( name : string , websiteData : IWebSite ) : string => {
36
+ export const getPageUrl = ( name : string , websiteData : Sveltin . WebSite ) : string => {
38
37
return websiteData . baseURL . concat ( '/' , name ) ;
39
38
} ;
40
39
41
- export const getSlugPageUrl = ( item : Sveltin . ContentEntry , websiteData : IWebSite ) : string => {
40
+ export const getSlugPageUrl = (
41
+ item : Sveltin . ResourceContent ,
42
+ websiteData : Sveltin . WebSite
43
+ ) : string => {
42
44
return websiteData . baseURL . concat ( '/' , item . resource , '/' , item . metadata . slug ) ;
43
45
} ;
44
46
45
- export const getFavicon = ( websiteData : IWebSite ) : string => {
47
+ export const getFavicon = ( websiteData : Sveltin . WebSite ) : string => {
46
48
return websiteData . baseURL . concat ( '/' , websiteData . favicon ) ;
47
49
} ;
48
50
49
- export const getCoverImagePath = ( item : Sveltin . ContentEntry , websiteData : IWebSite ) : string => {
51
+ export const getCoverImagePath = (
52
+ item : Sveltin . ResourceContent ,
53
+ websiteData : Sveltin . WebSite
54
+ ) : string => {
50
55
if ( item . metadata . cover && isNotEmpty ( item . metadata . cover ) ) {
51
56
return websiteData . baseURL . concat (
52
57
'/' ,
@@ -55,3 +60,16 @@ export const getCoverImagePath = (item: Sveltin.ContentEntry, websiteData: IWebS
55
60
}
56
61
return getFavicon ( websiteData ) ;
57
62
} ;
63
+
64
+ export const canonicalPageUrl = ( name : string , baseURL : string ) : string => baseURL . concat ( name ) ;
65
+
66
+ export const definePageKeywords = ( keywords : Array < string > , others : string ) : string => {
67
+ let result = '' ;
68
+ if ( keywords && keywords . length != 0 ) {
69
+ result = keywords . join ( ', ' ) ;
70
+ } else if ( isNotEmpty ( others ) ) {
71
+ result = others ;
72
+ }
73
+
74
+ return result ;
75
+ } ;
0 commit comments