forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcategories-for-support-team.js
More file actions
54 lines (44 loc) · 1.51 KB
/
categories-for-support-team.js
File metadata and controls
54 lines (44 loc) · 1.51 KB
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
const path = require('path')
module.exports = async function categoriesForSupportTeam (req, res, next) {
const englishSiteTree = req.context.siteTree.en
const allCategories = []
Object.keys(englishSiteTree).forEach(version => {
const versionedProductsTree = englishSiteTree[version].products
Object.values(versionedProductsTree).forEach(productObj => {
if (productObj.id === 'early-access') return
if (productObj.external) return
Object.values(productObj.categories).forEach(categoryObj => {
const articlesArry = []
if (categoryObj.maptopics) {
Object.values(categoryObj.maptopics).forEach(maptopicObj => {
Object.values(maptopicObj.articles).forEach(articleObj => {
articlesArry.push({
title: articleObj.title,
slug: path.basename(articleObj.href)
})
})
})
}
if (categoryObj.standalone) {
articlesArry.push({
title: categoryObj.title,
slug: path.basename(categoryObj.href)
})
}
if (categoryObj.articles) {
Object.values(categoryObj.articles).forEach(articleObj => {
articlesArry.push({
title: articleObj.title,
slug: path.basename(articleObj.href)
})
})
}
allCategories.push({
name: categoryObj.title,
published_articles: articlesArry
})
})
})
})
return res.json(allCategories)
}