@@ -7,6 +7,7 @@ import {insertContent} from './content-render-utils/insertContent';
77import { readFileAndCheckPrePublishSlug } from './content-render-utils/readFileAndCheckPrePublishSlug' ;
88import { JSDOM } from 'jsdom' ;
99import { customMarkdownOptions } from './customMarkdownOptions' ;
10+ import { ssl } from '../utils' ;
1011
1112registerPlugin ( 'render' , 'contentFolder' , contentRenderPlugin ) ;
1213
@@ -18,18 +19,36 @@ export async function contentRenderPlugin(html: string, route: HandledRoute) {
1819 try {
1920 const extension = file . split ( '.' ) . pop ( ) ;
2021 const { fileContent} = await readFileAndCheckPrePublishSlug ( file ) ;
21- // TODO: create additional "routes" for every slug
22- const attr = getIdAttrName (
23- html
24- . split ( '<scully-content' ) [ 1 ]
25- . split ( '>' ) [ 0 ]
26- . trim ( )
27- ) ;
28- const additionalHTML = await customMarkdownOptions ( await handleFile ( extension , fileContent ) ) ;
22+ let attr = '' ;
23+ try {
24+ attr = getIdAttrName (
25+ html
26+ . split ( '<scully-content' ) [ 1 ]
27+ . split ( '>' ) [ 0 ]
28+ . trim ( )
29+ ) ;
30+ } catch ( e ) {
31+ logWarn ( `
32+ ----------------
33+ Error, missing "${ yellow ( '<scully-content>' ) } " in route "${ yellow ( route . route ) } "
34+ without <scully-content> we can not render this route.
35+ Make sure it is in there, and not inside any conditionals (*ngIf)
36+ You can check this by opening "${ yellow ( `http${ ssl ? 'S' : '' } ://localhost:4200/${ route . route } ` ) } "
37+ when you serve your app with ${ yellow ( 'ng serve' ) } and then in the browsers console run:
38+ ${ yellow ( `document.querySelector('scully-content')` ) }
39+ ----------------
40+ ` ) ;
41+ }
42+ let additionalHTML = '' ;
43+ try {
44+ additionalHTML = await customMarkdownOptions ( await handleFile ( extension , fileContent ) ) ;
45+ } catch ( e ) {
46+ logWarn ( `Error, while reading content for "${ yellow ( route . route ) } " from file: "${ yellow ( file ) } "` ) ;
47+ }
2948 const htmlWithNgAttr = addNgIdAttribute ( additionalHTML , attr ) ;
3049 return insertContent ( scullyBegin , scullyEnd , html , htmlWithNgAttr , getScript ( attr ) ) ;
3150 } catch ( e ) {
32- logWarn ( `Error, probably missing "${ yellow ( '<scully-content>' ) } " for ${ yellow ( file ) } ` ) ;
51+ logWarn ( `Error, while rendering content for "${ yellow ( route . route ) } " from file: " ${ yellow ( file ) } " ` ) ;
3352 console . error ( e ) ;
3453 }
3554}
0 commit comments