Skip to content

Commit f80c985

Browse files
authored
Merge pull request #11 from 10gen/DOCSP-700
DOCSP-700: Ensure consistent tag ordering
2 parents 93e630d + aa5e2ec commit f80c985

File tree

2 files changed

+68
-45
lines changed

2 files changed

+68
-45
lines changed

config.toml

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,76 +12,93 @@ contentDir = "content-html"
1212
category = ""
1313
tags = ""
1414

15-
[tags]
15+
# Tags
1616

17-
# Language Options
18-
[tags.shell]
17+
# Language Options
18+
[[tags]]
19+
id = "shell"
1920
name = "Mongo Shell"
2021
facet = "language"
21-
22-
[tags.python]
22+
23+
[[tags]]
24+
id = "python"
2325
name = "Python"
2426
facet = "language"
25-
26-
[tags.ruby]
27+
28+
[[tags]]
29+
id = "ruby"
2730
name = "Ruby"
2831
facet = "language"
29-
30-
# Product Options
31-
[tags.mongodb]
32+
33+
# Product Options
34+
[[tags]]
35+
id = "mongodb"
3236
name = "MongoDB"
3337
facet = "product"
34-
35-
[tags.mongodb-enterprise]
38+
39+
[[tags]]
40+
id = "mongodb-enterprise"
3641
name = "MongoDB Enterprise"
3742
facet = "product"
38-
39-
[tags.bi]
43+
44+
[[tags]]
45+
id = "bi"
4046
name = "BI Connector"
4147
facet = "product"
42-
43-
[tags.compass]
48+
49+
[[tags]]
50+
id = "compass"
4451
name = "Compass"
4552
facet = "product"
46-
47-
[tags.driver]
53+
54+
[[tags]]
55+
id = "driver"
4856
name = "Driver"
4957
facet = "product"
50-
51-
# Topic Options
52-
[tags.administration]
58+
59+
# Topic Options
60+
[[tags]]
61+
id = "administration"
5362
name = "Administration"
5463
facet = "topic"
55-
56-
[tags.crud]
64+
65+
[[tags]]
66+
id = "crud"
5767
name = "CRUD"
5868
facet = "topic"
59-
60-
[tags.performance]
69+
70+
[[tags]]
71+
id = "performance"
6172
name = "Performance"
6273
facet = "topic"
63-
64-
[tags.replication]
74+
75+
[[tags]]
76+
id = "replication"
6577
name = "Replication"
6678
facet = "topic"
67-
68-
[tags.security]
79+
80+
[[tags]]
81+
id = "security"
6982
name = "Security"
7083
facet = "topic"
71-
72-
[tags.sharding]
84+
85+
[[tags]]
86+
id = "sharding"
7387
name = "Sharding"
7488
facet = "topic"
75-
76-
# Level Options
77-
[tags.beginner]
89+
90+
# Level Options
91+
[[tags]]
92+
id = "beginner"
7893
name = "Beginner"
7994
facet = "level"
80-
81-
[tags.intermediate]
95+
96+
[[tags]]
97+
id = "intermediate"
8298
name = "Intermediate"
8399
facet = "level"
84-
85-
[tags.advanced]
100+
101+
[[tags]]
102+
id = "advanced"
86103
name = "Advanced"
87104
facet = "level"

tools/genindex.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,12 @@ function main() {
187187
const args = docopt.docopt(__doc__)
188188
const tutorials = []
189189
const config = toml.parse(fs.readFileSync(args['--config']))
190-
const tagManifest = config.tags || {}
190+
const tagManifest = config.tags || []
191+
const tagIndexes = new Map()
192+
const tagMap = new Map(tagManifest.map((tag, index) => {
193+
tagIndexes.set(tag.id, index)
194+
return [tag.id, tag]
195+
}))
191196
let error = false
192197

193198
const sourceContentDir = config.sourceContentDir.replace(/\/$/, '')
@@ -212,17 +217,18 @@ function main() {
212217
}
213218

214219
doc.headmatter.options.forEach(function(option) {
215-
if (tagManifest[option] === undefined) {
220+
if (!tagMap.has(option)) {
216221
console.error(`Unknown tag "${option}" in ${path}`)
217222
error = true
218223
}
219224
})
220225

221-
doc.headmatter.options = doc.headmatter.options.map(option => {
222-
// Add the ID from the TOML to the object
223-
let tagWithId = tagManifest[option]
224-
tagWithId.id = option
225-
return tagWithId
226+
// Add facet and title information
227+
doc.headmatter.options = doc.headmatter.options.map(option => tagMap.get(option))
228+
229+
// Ensure that tags have a consistent order defined by the config file
230+
doc.headmatter.options.sort((a, b) => {
231+
return tagIndexes.get(a.id) - tagIndexes.get(b.id)
226232
})
227233

228234
tutorials.push(doc.headmatter)

0 commit comments

Comments
 (0)