fleet/website/api/controllers/articles/view-articles.js
Eric f713668390
Website: Add article landing and category pages (#5428)
* articles page

* update articles route to handle category urls

* update articles page

* add articleImageUrl meta tags to article pages

* basic empty state, add comments

* Update view-articles.js

* Update articles.less

* add articles, update styles and image url validation

* lint fix

* Update routes.js

* Update articles.ejs

* Update articles.page.js

Updated article category descriptions.

* migrated more articles

I migrated more articles so that all categories are populated.

* Added thumbnails to new posts

* Some style tweaks

- Tweaked a couple of styles
- Added cursor: pointer to filters
- Changed "Blog" to "Articles" in the navigation
- Changed /blog to /articles in the navigation

Co-authored-by: Mike Thomas <mthomas@fleetdm.com>
2022-04-28 15:16:07 +09:00

65 lines
1.6 KiB
JavaScript
Vendored

module.exports = {
friendlyName: 'View articles',
description: 'Display "Articles" page.',
inputs: {
category: {
type: 'string',
required: false,
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 ({category}) {
if (!_.isObject(sails.config.builtStaticContent) || !_.isArray(sails.config.builtStaticContent.markdownPages) || !sails.config.builtStaticContent.compiledPagePartialsAppPath) {
throw {badConfig: 'builtStaticContent.markdownPages'};
}
let articles = [];
if (category === 'articles') {
// If the category is `/articles` we'll show all articles
articles = sails.config.builtStaticContent.markdownPages.filter((page)=>{
if(_.startsWith(page.htmlId, 'articles')) {
return page;
}
});
// setting the category to all
category = 'all';
} 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;
}
});
}
return {
path: require('path'),
articles,
category,
markdownPages: sails.config.builtStaticContent.markdownPages,
compiledPagePartialsAppPath: sails.config.builtStaticContent.compiledPagePartialsAppPath,
};
}
};