fleet/website/api/controllers/articles/view-case-study.js
Eric 84b9027148
Website: update case study articles (#40567)
Closes: https://github.com/fleetdm/fleet/issues/40161
Closes: https://github.com/fleetdm/confidential/issues/14508

Changes:
- Added support for a new meta tag (`<meta
name="useBasicArticleTemplate" value="true">`) that will be used to
determine which template case study articles use.
- Updated the build-static-content script to not require
`summaryChallenge`, `summarySolution`, `summaryKeyResults`, and
`companyLogoFilename` meta tags for case study articles with a
`useBasicArticleTemplate` meta tag.
- Updated the view-case-study action to display case study articles with
a `useBasicArticleTemplate` meta tag on the basic-article template page

---------

Co-authored-by: Mike Thomas <[email protected]>
2026-02-27 14:33:42 -06:00

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