Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

topics-upcase.js 1.1 KB

You have to be logged in to leave a comment. Sign In
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
  1. #!/usr/bin/env node
  2. const fs = require('fs')
  3. const path = require('path')
  4. const walk = require('walk-sync')
  5. const readFrontmatter = require('../../lib/read-frontmatter')
  6. const allowTopics = require('../../data/allowed-topics')
  7. // key is the downcased valued for comparison
  8. // value is the display value with correct casing
  9. const topicLookupObject = {}
  10. allowTopics.forEach(topic => {
  11. const lowerCaseTopic = topic.toLowerCase()
  12. topicLookupObject[lowerCaseTopic] = topic
  13. })
  14. const files = walk(path.join(process.cwd(), 'content'), { includeBasePath: true, directories: false })
  15. files.forEach(file => {
  16. const fileContent = fs.readFileSync(file, 'utf8')
  17. const { content, data } = readFrontmatter(fileContent)
  18. if (data.topics === undefined) return
  19. const topics = data.topics.map(elem => elem.toLowerCase())
  20. const newTopics = []
  21. topics.forEach(topic => {
  22. // for each topic in the markdown file, lookup the display value
  23. // and add it to a new array
  24. newTopics.push(topicLookupObject[topic])
  25. })
  26. data.topics = newTopics
  27. const newContents = readFrontmatter.stringify(content, data, { lineWidth: 10000 })
  28. fs.writeFileSync(file, newContents)
  29. })
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...