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.
2025-01-07 17:43:36 +00:00
let thisPage = _ . find ( sails . config . builtStaticContent . markdownPages , { url : this . req . path } ) ;
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 ( /\/+$/ , '' ) ;
2026-03-02 22:31:33 +00:00
thisPage = _ . find ( sails . config . builtStaticContent . markdownPages , ( page ) => { return _ . endsWith ( page . url , revisedPageUrlSuffix ) ; } ) ;
2022-07-21 22:02:32 +00:00
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
// 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 ) {
2024-07-31 19:50:42 +00:00
pageTitleForMeta = thisPage . meta . articleTitle ;
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
2025-01-07 17:43:36 +00:00
let articleCategorySlug = this . req . path . split ( '/' ) [ 1 ] ;
// console.log(articleCategorySlug);
let categoryFriendlyNamesByCategorySlug = {
'success-stories' : 'Success stories' ,
'releases' : 'Releases' ,
'guides' : 'Guides' ,
'securing' : 'Security articles' ,
'engineering' : 'Engineering articles' ,
'announcements' : 'Announcements' ,
'podcasts' : 'Podcasts' ,
'report' : 'Reports' ,
2026-01-28 16:01:57 +00:00
'articles' : 'Blog' ,
2025-01-07 17:43:36 +00:00
} ;
let categoryFriendlyName = categoryFriendlyNamesByCategorySlug [ articleCategorySlug ] ;
2023-02-11 00:33:12 +00:00
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 ,
2025-01-07 17:43:36 +00:00
categoryFriendlyName ,
2026-02-27 20:33:42 +00:00
currentSection : 'more' ,
2024-09-18 22:37:22 +00:00
algoliaPublicKey : sails . config . custom . algoliaPublicKey ,
2022-04-22 17:27:03 +00:00
} ;
}
2025-01-07 17:43:36 +00:00
2022-04-22 17:27:03 +00:00
} ;