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

get-new-dotcom-path.js 1.3 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
35
36
37
38
39
40
41
42
43
44
45
46
  1. #!/usr/bin/env node
  2. const assert = require('assert')
  3. const { last } = require('lodash')
  4. const fs = require('fs')
  5. const { execSync } = require('child_process')
  6. const markdownExtension = '.md'
  7. const markdownRegex = new RegExp(`${markdownExtension}$`, 'm')
  8. const newDotcomDir = 'content/github'
  9. const oldPath = process.argv.slice(2)[0]
  10. assert(oldPath, 'must provide old dotcom path like "foo" or "articles/foo"')
  11. let filename = oldPath
  12. // [start-readme]
  13. //
  14. // Pass this script any old dotcom path (e.g., `articles/foo` or `foo.md`) and it
  15. // will output the new path in the content/github directory.
  16. //
  17. // [end-readme]
  18. // get last part of path
  19. if (filename.includes('/')) filename = last(filename.split('/'))
  20. // first check whether name is a category
  21. const categoryDir = `${newDotcomDir}/${filename.replace(markdownRegex, '')}`
  22. if (fs.existsSync(categoryDir)) {
  23. console.log(`New path:\n${categoryDir}/`)
  24. process.exit(0)
  25. }
  26. // otherwise add extension and check whether it's a file
  27. if (!filename.endsWith(markdownExtension)) filename = filename + markdownExtension
  28. // run find command
  29. const newPath = execSync(`find ${newDotcomDir} -name ${filename}`).toString()
  30. if (!newPath) {
  31. console.log(`Cannot find new path for "${oldPath}". Check the name and try again.\n`)
  32. process.exit(0)
  33. }
  34. console.log(`New path:\n${newPath}`)
Tip!

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

Comments

Loading...