Files
Eric 5cefa9d5bb Website: use git to get lastModifiedAt timestamps for markdown and yaml files, show last updated date on article pages (#48918)
Changes:
- Updated the "Test Fleet website" and "Deploy Fleet website" workflows
to include the full git history when checking out the repo.
- Updated the website's build-static-content script to use git to build
lastModifiedAt timestamps for Markdown and YAML files on the website.
- Updated the article template page and article category pages to show a
timestamp of when an article's Markdown file was last changed, if it was
updated >3 days after it was published.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Articles now conditionally display an **Updated** timestamp when they
were substantially modified after publication.
* The **Updated** indicator is shown on both article listing pages and
individual article pages (including mobile/desktop headers).

* **Bug Fixes**
* Timestamp rendering is now more consistent, helping readers
distinguish original publish dates from later edits.

* **Styling**
* Added styling to support the new “updated timestamp” label and
timestamp formatting within article cards.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-07-09 13:18:56 -05:00

133 lines
5.1 KiB
JavaScript
Vendored

module.exports = {
friendlyName: 'View articles',
description: 'Display "Articles" page.',
inputs: {
category: {
type: 'string',
description: 'The category of article to display.',
defaultsTo: '',
}
},
exits: {
success: { viewTemplatePath: 'pages/articles/articles' },
badConfig: { responseType: 'badConfig' },
notFound: { responseType: 'notFound' },
redirect: { responseType: 'redirect' },
},
fn: async function () {
if (!_.isObject(sails.config.builtStaticContent) || !_.isArray(sails.config.builtStaticContent.markdownPages) || !sails.config.builtStaticContent.compiledPagePartialsAppPath) {
throw {badConfig: 'builtStaticContent.markdownPages'};
}
let articles = [];
let category = this.req.path.split('/')[1];
if (category === 'articles') {
// If the category is `/articles` we'll show everything but guides, webinars and whitepaper articles.
articles = sails.config.builtStaticContent.markdownPages.filter((page)=>{
if(_.startsWith(page.htmlId, 'articles') && !_.startsWith(page.url, '/guides') && !_.startsWith(page.url, '/whitepapers') && !_.startsWith(page.url, '/webinars')) {
return page;
}
});
} else {
// if the user navigates to a URL for a specific category, we'll only display articles in that category
articles = sails.config.builtStaticContent.markdownPages.filter((page)=>{
if(_.startsWith(page.url, '/'+category)) {
return page;
}
});
}
// Sort articles in descending order by publish date.
articles = _.sortByOrder(articles, 'meta.publishedOn', 'DESC');
// If an article was updated three days after it's publishedOn timestamp, we'll show a timestamp of when the markdown file was last changed.
for(let article of articles) {
article.showUpdatedTimestamp = false;
let publishedAt = new Date(article.meta.publishedOn).getTime();
if(publishedAt + (1000 * 60 * 60 * 24 * 3) <= article.lastModifiedAt) {
article.showUpdatedTimestamp = true;
}
}
let pageTitleForMeta = 'Fleet blog';
let pageDescriptionForMeta = 'Read the latest articles written by Fleet.';
// Create a currentSection variable, this will be used to highlight the header dropdown that this article category lives under.
// There are three possible values for this (documentation, community, and platform), so we'll default to the one with the most article categories (community) and set the value to another section if needed.
// If the category is deploy, guides, or releases, currentSection will be set to 'documentation', and if the category is 'success-stories', currentSection will be set to 'platform'.
let currentSection = 'community';
// Set a pageTitleForMeta, pageDescriptionForMeta, and currentSection variable based on the article category.
switch(category) {
case 'deploy':
pageTitleForMeta = 'Deployment guides';
pageDescriptionForMeta = 'Learn how to deploy Fleet on a variety of production environments.';
currentSection = 'documentation';
break;
case 'releases':
pageTitleForMeta = 'Releases';
pageDescriptionForMeta = 'Fleet releases new and updated features every three weeks. Read about the latest product improvements here.';
currentSection = 'documentation';
break;
case 'guides':
pageTitleForMeta = 'Guides';
pageDescriptionForMeta = 'A collection of how-to guides for Fleet and osquery.';
currentSection = 'documentation';
break;
case 'securing':
pageTitleForMeta = 'Security articles';
pageDescriptionForMeta = 'Learn more about how we secure Fleet.';
break;
case 'engineering':
pageTitleForMeta = 'Engineering articles';
pageDescriptionForMeta = 'Read about engineering at Fleet and beyond.';
break;
case 'announcements':
pageTitleForMeta = 'Announcements';
pageDescriptionForMeta = 'Read the latest news from Fleet.';
break;
case 'podcasts':
pageTitleForMeta = 'Podcasts';
pageDescriptionForMeta = 'Listen to the Future of Device Management podcast.';
break;
case 'articles':
pageTitleForMeta = 'Blog';
pageDescriptionForMeta = 'Read the latest articles from the Fleet team and community.';
break;
case 'whitepapers':
pageTitleForMeta = 'Whitepapers';
pageDescriptionForMeta = 'Browse our whitepapers to learn how modern teams manage and secure their devices.';
break;
case 'webinars':
pageTitleForMeta = 'Webinars';
pageDescriptionForMeta = 'Watch Fleet and industry practitioners discuss real-world device management and IT operations.';
break;
}
return {
path: require('path'),
articles,
category,
markdownPages: sails.config.builtStaticContent.markdownPages,
compiledPagePartialsAppPath: sails.config.builtStaticContent.compiledPagePartialsAppPath,
currentSection,
pageTitleForMeta,
pageDescriptionForMeta,
algoliaPublicKey: sails.config.custom.algoliaPublicKey,
};
}
};