public int renderTags ( String tagPath ) throws Exception { int renderedCount = 0 ; final List < Throwable > errors = new LinkedList <> ( ) ; for ( String tag : db . getAllTags ( ) ) { try { Map < String , Object > model = new HashMap <> ( ) ; model . put ( "renderer" , renderingEngine ) ; model . put ( Attributes . TAG , tag ) ; Map < String , Object > map = buildSimpleModel ( Attributes . TAG ) ; model . put ( "content" , map ) ; File path = new File ( config . getDestinationFolder ( ) + File . separator + tagPath + File . separator + tag + config . getOutputExtension ( ) ) ; map . put ( Attributes . ROOTPATH , FileUtil . getUriPathToDestinationRoot ( config , path ) ) ; render ( new ModelRenderingConfig ( path , Attributes . TAG , model , findTemplateName ( Attributes . TAG ) ) ) ; renderedCount ++ ; } catch ( Exception e ) { errors . add ( e ) ; } } if ( config . getRenderTagsIndex ( ) ) { try { // Add an index file at root folder of tags. // This will prevent directory listing and also provide an option to // display all tags page. Map < String , Object > model = new HashMap < String , Object > ( ) ; model . put ( "renderer" , renderingEngine ) ; Map < String , Object > map = buildSimpleModel ( Attributes . TAGS ) ; model . put ( "content" , map ) ; File path = new File ( config . getDestinationFolder ( ) + File . separator + tagPath + File . separator + "index" + config . getOutputExtension ( ) ) ; map . put ( Attributes . ROOTPATH , FileUtil . getUriPathToDestinationRoot ( config , path ) ) ; render ( new ModelRenderingConfig ( path , "tagindex" , model , findTemplateName ( "tagsindex" ) ) ) ; renderedCount ++ ; } catch ( Exception e ) { errors . add ( e ) ; } } if ( ! errors . isEmpty ( ) ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "Failed to render tags. Cause(s):" ) ; for ( Throwable error : errors ) { sb . append ( "\n" ) . append ( error . getMessage ( ) ) ; } throw new Exception ( sb . toString ( ) , errors . get ( 0 ) ) ; } else { return renderedCount ; } }
Render tag files using the supplied content .