2025-12-12 04:37:16 +00:00
module . exports = {
friendlyName : 'View case study' ,
description : 'Display "Case study" page.' ,
inputs : {
pageUrlSuffix : {
description : 'The relative path to the case study article page from within this route.' ,
example : 'case-study/foo' ,
type : 'string' ,
defaultsTo : ''
}
} ,
exits : {
success : { viewTemplatePath : 'pages/articles/case-study' } ,
2026-02-27 20:33:42 +00:00
useBasicArticleTemplate : { viewTemplatePath : 'pages/articles/basic-article' } , // Note: Normally we use one view action per EJS template, we're doing this here to display case studies using the articles/basic-article EJS template.
2025-12-12 04:37:16 +00:00
badConfig : { responseType : 'badConfig' } ,
notFound : { responseType : 'notFound' } ,
redirect : { responseType : 'redirect' } ,
} ,
fn : async function ( { pageUrlSuffix } ) {
if ( ! _ . isObject ( sails . config . builtStaticContent ) || ! _ . isArray ( sails . config . builtStaticContent . markdownPages ) || ! sails . config . builtStaticContent . compiledPagePartialsAppPath ) {
throw { badConfig : 'builtStaticContent.markdownPages' } ;
}
// Serve appropriate page content.
let thisPage = _ . find ( sails . config . builtStaticContent . markdownPages , { url : this . req . path } ) ;
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 ( /\/+$/ , '' ) ;
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.
throw 'notFound' ;
}
}
// Setting the pages meta title and description from the articles meta tags.
let pageTitleForMeta ;
if ( thisPage . meta . articleTitle ) {
pageTitleForMeta = thisPage . meta . articleTitle ;
} //fi
let pageDescriptionForMeta ;
if ( thisPage . meta . description ) {
pageDescriptionForMeta = thisPage . meta . description ;
}
// Set the currentSection variable for the website header to "customers"
let currentSection = 'customers' ;
2026-02-27 20:33:42 +00:00
// If this case study has a useBasicArticleTemplate meta tag, well return a `useBasicArticleTemplate response to display this article with the basic-article EJS template.
if ( thisPage . meta . useBasicArticleTemplate ) {
throw { 'useBasicArticleTemplate' : {
path : require ( 'path' ) ,
thisPage : thisPage ,
markdownPages : sails . config . builtStaticContent . markdownPages ,
compiledPagePartialsAppPath : sails . config . builtStaticContent . compiledPagePartialsAppPath ,
pageTitleForMeta ,
pageDescriptionForMeta ,
currentSection ,
articleCategorySlug : 'customers' , // Note: This value is required in the basic-article template
categoryFriendlyName : 'Case studies' , // Note: This value is required in the basic-article template
} } ;
}
2025-12-12 04:37:16 +00:00
// Respond with view.
return {
path : require ( 'path' ) ,
thisPage : thisPage ,
markdownPages : sails . config . builtStaticContent . markdownPages ,
compiledPagePartialsAppPath : sails . config . builtStaticContent . compiledPagePartialsAppPath ,
pageTitleForMeta ,
pageDescriptionForMeta ,
currentSection ,
} ;
}
} ;