forked from InnerSourceCommons/InnerSourceLearningPath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubstitute_article_urls.js
More file actions
48 lines (40 loc) · 1.47 KB
/
substitute_article_urls.js
File metadata and controls
48 lines (40 loc) · 1.47 KB
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
47
48
// TODO: Update to work with translations; may require changing the urls.yaml
const fs = require('fs')
const YAML = require('yaml')
const { join } = require('path')
const target = process.argv[2]
const urlsFile = fs.readFileSync(join('..', 'config', 'urls.yaml'), 'utf8')
const urls = YAML.parse(urlsFile).map(({ video, article }) => [video, article]).flat()
const getArticleFiles = (path) => {
return fs.readdirSync(path).map((filename) => {
const filePath = join(path, filename)
if (fs.lstatSync(filePath).isDirectory()) {
return getArticleFiles(filePath)
} else {
return {
filePath,
asciiDoc: fs.readFileSync(filePath, 'utf-8')
}
}
}).flat()
}
const articleFiles = [getArticleFiles(join('..', 'introduction')), getArticleFiles(join('..', 'product-owner')), getArticleFiles(join('..', 'trusted-committer')), getArticleFiles(join('..', 'contributor'))].flat()
const substituted = articleFiles.map((articleFile) => {
let asciiDoc = articleFile.asciiDoc
urls.forEach((urlObj) => {
const targetUrl = urlObj[target]
if (targetUrl) {
Object.keys(urlObj).forEach((platform) => {
const url = urlObj[platform]
if (url && platform !== target) {
asciiDoc = asciiDoc.split(url).join(targetUrl)
}
})
}
})
return {
filePath: articleFile.filePath,
asciiDoc
}
})
substituted.forEach(substitutedArticle => fs.writeFileSync(substitutedArticle.filePath, substitutedArticle.asciiDoc))