fleet/website/api/controllers/articles/view-case-study.js
Eric fa27fda724
Website: Add case study article template page and three articles (#37153)
Changes:
- Updated the website's build-static-content script to add support for a
new article category: `case study`.
- Added a new article template page for case study articles
- Added case study articles from Stripe, Faire, and Foursquare.

---------

Co-authored-by: Mike Thomas <[email protected]>
2025-12-12 13:37:16 +09:00

72 lines
2.5 KiB
JavaScript
Vendored

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' },
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';
// Respond with view.
return {
path: require('path'),
thisPage: thisPage,
markdownPages: sails.config.builtStaticContent.markdownPages,
compiledPagePartialsAppPath: sails.config.builtStaticContent.compiledPagePartialsAppPath,
pageTitleForMeta,
pageDescriptionForMeta,
currentSection,
};
}
};