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

site-data-tag.js 822 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
  1. #!/usr/bin/env node
  2. const path = require('path')
  3. const walk = require('walk-sync')
  4. const replace = require('replace')
  5. const FINDER = /{{\s?site\.data\.([a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]+)+)\s*}}/g
  6. const REPLACER = '{% data $1 %}'
  7. async function rewriteFiles (dir) {
  8. const files = walk(dir, { includeBasePath: true })
  9. replace({
  10. regex: FINDER,
  11. replacement: REPLACER,
  12. paths: files,
  13. recursive: true
  14. })
  15. }
  16. async function main () {
  17. const dirs = [
  18. path.join(__dirname, '../../content'),
  19. path.join(__dirname, '../../data'),
  20. path.join(__dirname, '../../translations'),
  21. path.join(__dirname, '../../includes'),
  22. path.join(__dirname, '../../layouts')
  23. ]
  24. for (const dir of dirs) {
  25. await rewriteFiles(dir)
  26. }
  27. }
  28. main()
  29. .catch(console.error)
  30. .finally(() => console.log('Done!'))
Tip!

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

Comments

Loading...