-
Notifications
You must be signed in to change notification settings - Fork 550
/
Copy pathview-articles.js
120 lines (100 loc) · 4.3 KB
/
view-articles.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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 all articles
articles = sails.config.builtStaticContent.markdownPages.filter((page)=>{
if(_.startsWith(page.htmlId, 'articles')) {
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;
}
});
articles = _.sortBy(articles, 'meta.publishedOn');
}
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 'success-stories':
pageTitleForMeta = 'Success stories';
pageDescriptionForMeta = 'Read about how others are using Fleet and osquery.';
currentSection = 'platform';
break;
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 = 'Articles';
pageDescriptionForMeta = 'Read the latest articles from the Fleet team and community.';
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,
};
}
};