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

standardize-frontmatter-order.js 1023 B

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
35
36
37
  1. #!/usr/bin/env node
  2. const fs = require('fs')
  3. const path = require('path')
  4. const walk = require('walk-sync')
  5. const matter = require('gray-matter')
  6. const { schema } = require('../lib/frontmatter')
  7. const properties = Object.keys(schema.properties)
  8. const contentDir = path.join(__dirname, '../content')
  9. const contentFiles = walk(contentDir, { includeBasePath: true })
  10. .filter(relativePath => relativePath.endsWith('.md') && !relativePath.includes('README'))
  11. // [start-readme]
  12. //
  13. // Run this script to standardize frontmatter fields in all content files,
  14. // per the order:
  15. // - title
  16. // - intro
  17. // - product callout
  18. // - productVersion
  19. // - map topic status
  20. // - hidden status
  21. // - layout
  22. // - redirect
  23. //
  24. // [end-readme]
  25. contentFiles.forEach(fullPath => {
  26. const { content, data } = matter(fs.readFileSync(fullPath, 'utf8'))
  27. const newData = {}
  28. properties.forEach(prop => {
  29. if (data[prop]) newData[prop] = data[prop]
  30. })
  31. fs.writeFileSync(fullPath, matter.stringify(content, newData, { lineWidth: 10000 }))
  32. })
Tip!

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

Comments

Loading...