2022-04-22 17:27:03 +00:00
module . exports = {
friendlyName : 'View blog article' ,
description : 'Display "Blog article" page.' ,
2022-07-21 22:02:32 +00:00
urlWildcardSuffix : 'pageUrlSuffix' ,
2022-04-22 17:27:03 +00:00
inputs : {
2022-07-21 22:02:32 +00:00
pageUrlSuffix : {
description : 'The relative path to the blog article page from within this route.' ,
2022-04-22 17:27:03 +00:00
example : 'guides/deploying-fleet-on-render' ,
type : 'string' ,
defaultsTo : ''
}
} ,
exits : {
success : { viewTemplatePath : 'pages/articles/basic-article' } ,
badConfig : { responseType : 'badConfig' } ,
notFound : { responseType : 'notFound' } ,
redirect : { responseType : 'redirect' } ,
} ,
2022-07-21 22:02:32 +00:00
fn : async function ( { pageUrlSuffix } ) {
2022-04-22 17:27:03 +00:00
if ( ! _ . isObject ( sails . config . builtStaticContent ) || ! _ . isArray ( sails . config . builtStaticContent . markdownPages ) || ! sails . config . builtStaticContent . compiledPagePartialsAppPath ) {
throw { badConfig : 'builtStaticContent.markdownPages' } ;
}
2022-07-21 22:02:32 +00:00
// Serve appropriate page content.
let thisPage = _ . find ( sails . config . builtStaticContent . markdownPages , { url : '/' + pageUrlSuffix } ) ;
2022-07-25 16:16:40 +00:00
if ( ! thisPage ) { // If there's no EXACTLY matching content page, try a revised version of the URL suffix that's lowercase, with all slashes deduped, and any leading or trailing slash removed (leading slashes are only possible if this is a regex, rather than "/*" route)
let revisedPageUrlSuffix = pageUrlSuffix . toLowerCase ( ) . replace ( /\/+/g , '/' ) . replace ( /^\/+/ , '' ) . replace ( /\/+$/ , '' ) ;
2022-07-21 22:02:32 +00:00
thisPage = _ . find ( sails . config . builtStaticContent . markdownPages , { url : '/' + revisedPageUrlSuffix } ) ;
if ( thisPage ) { // If we matched a page with the revised suffix, then redirect to that rather than rendering it, so the URL gets cleaned up.
throw { redirect : thisPage . url } ;
} else { // If no page could be found even with the revised suffix, then throw a 404 error.
2022-04-22 17:27:03 +00:00
throw 'notFound' ;
}
}
2022-07-21 22:02:32 +00:00
2023-01-27 22:58:53 +00:00
let articleCategorySlug = pageUrlSuffix . split ( '/' ) [ 0 ] ;
2022-07-21 22:02:32 +00:00
// Setting the pages meta title and description from the articles meta tags, as well as an article image, if provided.
// Note: Every article page should have a 'articleTitle' and a 'authorFullName' meta tag.
// Note: Leaving title and description as `undefined` in our view means we'll default to the generic title and description set in layout.ejs.
2022-04-22 17:27:03 +00:00
let pageTitleForMeta ;
if ( thisPage . meta . articleTitle ) {
pageTitleForMeta = thisPage . meta . articleTitle + ' | Fleet for osquery' ;
2022-07-21 22:02:32 +00:00
} //fi
2022-04-22 17:27:03 +00:00
let pageDescriptionForMeta ;
2022-09-21 22:14:58 +00:00
if ( thisPage . meta . description ) {
pageDescriptionForMeta = thisPage . meta . description ;
} else if ( thisPage . meta . articleTitle && thisPage . meta . authorFullName ) {
2022-07-21 22:02:32 +00:00
pageDescriptionForMeta = _ . trimRight ( thisPage . meta . articleTitle , '.' ) + ' by ' + thisPage . meta . authorFullName ;
} //fi
2022-04-22 17:27:03 +00:00
2023-02-11 00:33:12 +00:00
// Set a currentSection variable for the website header based on how the articles category page is linked to in the header navigation dropdown menus.
let currentSection ;
if ( articleCategorySlug === 'success-stories' ) {
// If the article is in the 'device-management' category, highlight the "Platform" dropdown.
currentSection = 'platform' ;
} else if ( _ . contains ( [ 'deploy' , 'guides' , 'releases' ] , articleCategorySlug ) ) {
// If the articleCategorySlug is deploy, guides, or release, highlight the "Documentation" dropdown.
currentSection = 'documentation' ;
} else {
// If the article is in any other category, highlight the "Community" dropdown.
currentSection = 'community' ;
}
2022-04-22 17:27:03 +00:00
// Respond with view.
return {
path : require ( 'path' ) ,
thisPage : thisPage ,
markdownPages : sails . config . builtStaticContent . markdownPages ,
compiledPagePartialsAppPath : sails . config . builtStaticContent . compiledPagePartialsAppPath ,
pageTitleForMeta ,
pageDescriptionForMeta ,
2022-07-21 22:02:32 +00:00
pageImageForMeta : thisPage . meta . articleImageUrl || undefined ,
2023-02-11 00:33:12 +00:00
articleCategorySlug ,
currentSection ,
2022-04-22 17:27:03 +00:00
} ;
}
} ;