1
1
'use strict' ;
2
2
3
3
const moment = require ( 'moment' ) ;
4
+ const cheerio = require ( 'cheerio' ) ;
4
5
5
6
describe ( 'open_graph' , ( ) => {
6
7
const Hexo = require ( '../../../lib/hexo' ) ;
@@ -112,6 +113,22 @@ describe('open_graph', () => {
112
113
result . should . contain ( meta ( { property : 'og:url' , content : 'https://hexo.io/bar' } ) ) ;
113
114
} ) ;
114
115
116
+ it ( 'url - should not ends with index.html' , ( ) => {
117
+ hexo . config . pretty_urls . trailing_index = false ;
118
+ const result = openGraph . call ( {
119
+ page : { } ,
120
+ config : hexo . config ,
121
+ is_post : isPost ,
122
+ url : 'http://yoursite.com/page/index.html'
123
+ } ) ;
124
+
125
+ const $ = cheerio . load ( result ) ;
126
+
127
+ $ ( 'meta[property="og:url"]' ) . attr ( 'content' ) . endsWith ( 'index.html' ) . should . be . false ;
128
+
129
+ hexo . config . pretty_urls . trailing_index = true ;
130
+ } ) ;
131
+
115
132
it ( 'images - content' , ( ) => {
116
133
const result = openGraph . call ( {
117
134
page : {
@@ -401,7 +418,7 @@ describe('open_graph', () => {
401
418
it ( 'updated - options' , ( ) => {
402
419
const result = openGraph . call ( {
403
420
page : { updated : moment ( '2016-05-23T21:20:21.372Z' ) } ,
404
- config : { } ,
421
+ config : hexo . config ,
405
422
is_post : isPost
406
423
} , { } ) ;
407
424
@@ -411,7 +428,7 @@ describe('open_graph', () => {
411
428
it ( 'updated - options - allow overriding og:updated_time' , ( ) => {
412
429
const result = openGraph . call ( {
413
430
page : { updated : moment ( '2016-05-23T21:20:21.372Z' ) } ,
414
- config : { } ,
431
+ config : hexo . config ,
415
432
is_post : isPost
416
433
} , { updated : moment ( '2015-04-22T20:19:20.371Z' ) } ) ;
417
434
@@ -421,7 +438,7 @@ describe('open_graph', () => {
421
438
it ( 'updated - options - allow disabling og:updated_time' , ( ) => {
422
439
const result = openGraph . call ( {
423
440
page : { updated : moment ( '2016-05-23T21:20:21.372Z' ) } ,
424
- config : { } ,
441
+ config : hexo . config ,
425
442
is_post : isPost
426
443
} , { updated : false } ) ;
427
444
@@ -431,7 +448,7 @@ describe('open_graph', () => {
431
448
it ( 'description - do not add /(?:og:)?description/ meta tags if there is no description' , ( ) => {
432
449
const result = openGraph . call ( {
433
450
page : { } ,
434
- config : { } ,
451
+ config : hexo . config ,
435
452
is_post : isPost
436
453
} , { } ) ;
437
454
@@ -442,7 +459,7 @@ describe('open_graph', () => {
442
459
it ( 'keywords - page keywords string' , ( ) => {
443
460
const ctx = {
444
461
page : { keywords : 'optimize,web' } ,
445
- config : { } ,
462
+ config : hexo . config ,
446
463
is_post : isPost
447
464
} ;
448
465
@@ -455,7 +472,7 @@ describe('open_graph', () => {
455
472
it ( 'keywords - page keywords array' , ( ) => {
456
473
const ctx = {
457
474
page : { keywords : [ 'optimize' , 'web' ] } ,
458
- config : { } ,
475
+ config : hexo . config ,
459
476
is_post : isPost
460
477
} ;
461
478
@@ -468,7 +485,7 @@ describe('open_graph', () => {
468
485
it ( 'keywords - page tags' , ( ) => {
469
486
const ctx = {
470
487
page : { tags : [ 'optimize' , 'web' ] } ,
471
- config : { } ,
488
+ config : hexo . config ,
472
489
is_post : isPost
473
490
} ;
474
491
@@ -479,9 +496,10 @@ describe('open_graph', () => {
479
496
} ) ;
480
497
481
498
it ( 'keywords - config keywords string' , ( ) => {
499
+ hexo . config . keywords = 'optimize,web' ;
482
500
const ctx = {
483
501
page : { } ,
484
- config : { keywords : 'optimize,web' } ,
502
+ config : hexo . config ,
485
503
is_post : isPost
486
504
} ;
487
505
@@ -492,9 +510,10 @@ describe('open_graph', () => {
492
510
} ) ;
493
511
494
512
it ( 'keywords - config keywords array' , ( ) => {
513
+ hexo . config . keywords = [ 'optimize' , 'web' ] ;
495
514
const ctx = {
496
515
page : { } ,
497
- config : { keywords : [ 'optimize' , 'web' ] } ,
516
+ config : hexo . config ,
498
517
is_post : isPost
499
518
} ;
500
519
@@ -505,12 +524,13 @@ describe('open_graph', () => {
505
524
} ) ;
506
525
507
526
it ( 'keywords - page keywords first' , ( ) => {
527
+ hexo . config . keywords = 'web5,web6' ;
508
528
const ctx = {
509
529
page : {
510
530
keywords : [ 'web1' , 'web2' ] ,
511
531
tags : [ 'web3' , 'web4' ]
512
532
} ,
513
- config : { keywords : 'web5,web6' } ,
533
+ config : hexo . config ,
514
534
is_post : isPost
515
535
} ;
516
536
@@ -521,9 +541,10 @@ describe('open_graph', () => {
521
541
} ) ;
522
542
523
543
it ( 'keywords - page tags second' , ( ) => {
544
+ hexo . config . keywords = 'web5,web6' ;
524
545
const ctx = {
525
546
page : { tags : [ 'optimize' , 'web' ] } ,
526
- config : { keywords : 'web5,web6' } ,
547
+ config : hexo . config ,
527
548
is_post : isPost
528
549
} ;
529
550
@@ -534,9 +555,10 @@ describe('open_graph', () => {
534
555
} ) ;
535
556
536
557
it ( 'keywords - page tags empty' , ( ) => {
558
+ hexo . config . keywords = 'web5,web6' ;
537
559
const ctx = {
538
560
page : { tags : [ ] } ,
539
- config : { keywords : 'web5,web6' } ,
561
+ config : hexo . config ,
540
562
is_post : isPost
541
563
} ;
542
564
@@ -549,7 +571,7 @@ describe('open_graph', () => {
549
571
it ( 'keywords - escape' , ( ) => {
550
572
const ctx = {
551
573
page : { keywords : 'optimize,web&<>"\'/,site' } ,
552
- config : { } ,
574
+ config : hexo . config ,
553
575
is_post : isPost
554
576
} ;
555
577
0 commit comments