11const _ = require ( 'lodash' )
22const frontMatter = require ( 'front-matter' )
33const slug = require ( 'slug' )
4- const { templateExtensions, removeExtension } = require ( '../helpers' )
4+ const { templateExtensions, removeExtension, Markdown } = require ( '../helpers' )
55
66const models = {
77 attachment : require ( './attachment' )
88}
99
1010const isIndexFile = ( node , nameOptions ) => {
11+ if ( node . children ) {
12+ return false
13+ }
1114 const names = nameOptions . join ( '|' )
1215 const extensions = templateExtensions . join ( '|' )
1316 const namePattern = new RegExp ( `^(${ names } )(${ extensions } )$` , 'i' )
14- return ! node . children && node . name . match ( namePattern )
17+ return node . name . match ( namePattern )
1518}
1619
1720function parseFolderedEntry ( node , indexFileNameOptions ) {
@@ -33,6 +36,13 @@ function parseFolderedEntry(node, indexFileNameOptions) {
3336 }
3437}
3538
39+ function parseContent ( node , content ) {
40+ if ( node . extension . match ( / ( h t m l | h t m | h b s | h a n d l e b a r s ) / i) ) {
41+ return content
42+ }
43+ return Markdown . parse ( content )
44+ }
45+
3646function _baseEntry ( node , indexFileNameOptions ) {
3747 const folderedEntry = node . children ?
3848 parseFolderedEntry ( node , indexFileNameOptions ) :
@@ -43,13 +53,16 @@ function _baseEntry(node, indexFileNameOptions) {
4353 folderedEntry ?. name || entryFile . name
4454 )
4555 const attachments = folderedEntry ?. attachments || [ ]
56+ const contentRaw = body || ''
57+ const content = parseContent ( entryFile , contentRaw )
4658
4759 return {
4860 ..._ . omit ( node , 'children' ) ,
4961 ...attributes ,
5062 title : attributes . title || entryName ,
5163 slug : attributes . slug || slug ( entryName ) ,
52- content : body || '' ,
64+ contentRaw,
65+ content,
5366 attachments
5467 }
5568}
0 commit comments