From 493f8d9d2812ef763aa2e30e816b067aaf8f99bd Mon Sep 17 00:00:00 2001 From: Dominic Watson Date: Sun, 26 Apr 2015 09:56:57 +0100 Subject: [PATCH] #7 Outputting links to a page's tagged categories in the 'see also' section of the page layout --- api/data/DocTree.cfc | 4 ++++ builders/html/Builder.cfc | 25 ++++++++++++++++++++----- builders/html/layouts/main.cfm | 10 +++++----- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/api/data/DocTree.cfc b/api/data/DocTree.cfc index a5c8b31d5..df343e834 100644 --- a/api/data/DocTree.cfc +++ b/api/data/DocTree.cfc @@ -18,6 +18,10 @@ component accessors=true { return pathMap[ arguments.path ] ?: NullValue(); } + public boolean function pageExists( required string id ) { + return idMap.keyExists( arguments.id ); + } + public array function getPagesByCategory( required string category ) { var matchedPages = []; diff --git a/builders/html/Builder.cfc b/builders/html/Builder.cfc index bca3b7336..9b7ecb6ca 100644 --- a/builders/html/Builder.cfc +++ b/builders/html/Builder.cfc @@ -27,20 +27,35 @@ component { ); var crumbs = []; var parent = arguments.page.getParent(); + var links = []; + while( !IsNull( parent ) ) { crumbs.prepend( parent.getId() ); parent = parent.getParent(); } + if ( !IsNull( arguments.page.getCategories() ) ) { + for( var category in arguments.page.getCategories() ) { + if ( arguments.docTree.pageExists( "category-" & category ) ) { + links.append( "[[category-" & category & "]]" ); + } + } + } + if ( !IsNull( arguments.page.getRelated() ) ) { + for( var link in arguments.page.getRelated() ) { + links.append( link ); + } + } + return renderTemplate( template = "layouts/main.cfm" , args = { - body = Trim( renderedPage ) - , page = arguments.page - , crumbs = renderTemplate( template="layouts/breadcrumbs.cfm", args={ crumbs=crumbs, page=arguments.page } ) - , navTree = renderTemplate( template="layouts/sideNavTree.cfm", args={ crumbs=crumbs, docTree=arguments.docTree, pageLineage=arguments.page.getLineage() } ) - , seeAlso = renderTemplate( template="layouts/seeAlso.cfm", args={ links=arguments.page.getRelated() } ) + body = Trim( renderedPage ) + , page = arguments.page + , crumbs = renderTemplate( template="layouts/breadcrumbs.cfm", args={ crumbs=crumbs, page=arguments.page } ) + , navTree = renderTemplate( template="layouts/sideNavTree.cfm", args={ crumbs=crumbs, docTree=arguments.docTree, pageLineage=arguments.page.getLineage() } ) + , seeAlso = renderTemplate( template="layouts/seeAlso.cfm" , args={ links=links } ) } ); } diff --git a/builders/html/layouts/main.cfm b/builders/html/layouts/main.cfm index a01c9a544..b1ddfec2a 100644 --- a/builders/html/layouts/main.cfm +++ b/builders/html/layouts/main.cfm @@ -1,8 +1,8 @@ - - - - - + + + + +