@@ -5,19 +5,18 @@ describe('parser', () => {
55 beforeEach ( jest . clearAllMocks ) ;
66
77 it ( 'should error when article does not contain metadata' , ( ) => {
8- expect ( parseArticle . bind ( null , '' ) ) . toThrowError ( 'Incorrect metadata' ) ;
8+ expect ( parseArticle . bind ( null , '' , '' ) ) . toThrowError ( 'Incorrect metadata' ) ;
99 } ) ;
1010
1111 it ( 'should error when article does not contain a title' , ( ) => {
1212 const article = `
1313---
14- tags:
15- - tagOne
14+ tags: tagOne
1615---
1716## some sub title
1817some content
1918` ;
20- expect ( parseArticle . bind ( null , article ) ) . toThrowError ( 'Article does not have a title' ) ;
19+ expect ( parseArticle . bind ( null , article , '' ) ) . toThrowError ( 'Article does not have a title' ) ;
2120 } ) ;
2221
2322 it ( 'should get title from article content' , ( ) => {
2928# Main Title
3029some content
3130` ;
32- const parsed = parseArticle ( article ) ;
31+ const parsed = parseArticle ( article , '' ) ;
3332 expect ( parsed . config . title ) . toEqual ( 'Main Title' ) ;
3433 } ) ;
3534
@@ -40,7 +39,7 @@ title: Metadata Title
4039---
4140# Main Title
4241some content` ;
43- const parsed = parseArticle ( article ) ;
42+ const parsed = parseArticle ( article , '' ) ;
4443 expect ( parsed . config . title ) . toEqual ( 'Metadata Title' ) ;
4544 expect ( parsed . config . description ) . toEqual ( '' ) ;
4645 expect ( parsed . config . license ) . toEqual ( MediumLicense . PublicDomain ) ;
@@ -54,20 +53,50 @@ some content`);
5453---
5554title: Metadata Title
5655description: New Article
57- tags:
58- - one
56+ tags: one, two
5957license: ${ MediumLicense . CC40Zero }
6058published: false
6159---
6260# Main Title
6361some content` ;
64- const parsed = parseArticle ( article ) ;
62+ const parsed = parseArticle ( article , '' ) ;
6563 expect ( parsed . config . title ) . toEqual ( 'Metadata Title' ) ;
6664 expect ( parsed . config . description ) . toEqual ( 'New Article' ) ;
67- expect ( parsed . config . tags ) . toEqual ( [ 'one' ] ) ;
65+ expect ( parsed . config . tags ) . toEqual ( 'one, two' ) ;
6866 expect ( parsed . config . license ) . toEqual ( MediumLicense . CC40Zero ) ;
6967 expect ( parsed . config . published ) . toEqual ( false ) ;
7068 expect ( parsed . content ) . toEqual ( `# Main Title
7169some content` ) ;
7270 } ) ;
71+
72+
73+ it ( 'should parse all images with relative path' , ( ) => {
74+ const article = `
75+ ---
76+ title: Some Title
77+ description: New Article
78+ tags: one, images
79+ published: false
80+ ---
81+
82+ # Main Title
83+ some content
84+
85+ 
86+
87+ <img alt="image" src="@/assets/img.jpg" />
88+
89+ ## Description
90+ ` ;
91+ const parsed = parseArticle ( article , 'https://raw.github.com/protiumx/blogpub/main/articles' ) ;
92+ console . info ( parsed . content ) ;
93+ expect (
94+ parsed . content . includes (
95+ '' ,
96+ ) ) . toBeTruthy ( ) ;
97+ expect (
98+ parsed . content . includes (
99+ '<img alt="image" src="https://raw.github.com/protiumx/blogpub/main/articles/assets/img.jpg"' ,
100+ ) ) . toBeTruthy ( ) ;
101+ } ) ;
73102} ) ;
0 commit comments