forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
move-admin-dir.js
executable file
·64 lines (51 loc) · 2.18 KB
/
move-admin-dir.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const { execSync } = require('child_process')
const rimraf = require('rimraf').sync
const englishContentDir = 'content'
const walk = require('walk-sync')
const frontmatter = require('@github-docs/frontmatter')
const addRedirect = require('../../lib/redirects/add-redirect-to-frontmatter')
execSync(`mv ${englishContentDir}/enterprise/admin/ ${englishContentDir}/admin`)
rimraf(`${englishContentDir}/enterprise`)
fs.readdirSync('translations')
.filter(file => !file.endsWith('.md'))
.forEach(dir => {
const translatedContentDir = path.join('translations', dir, 'content')
execSync(`mv ${translatedContentDir}/enterprise/admin/ ${translatedContentDir}/admin`)
rimraf(`${translatedContentDir}/enterprise`)
})
const adminDir = path.join(process.cwd(), englishContentDir, 'admin')
// Add redirects to English
walk(adminDir, { includeBasePath: true, directories: false })
.filter(file => file.endsWith('.md'))
.forEach(file => {
const contents = fs.readFileSync(file, 'utf8')
const { data, content } = frontmatter(contents)
const oldPath = file
.replace(adminDir, '/enterprise/admin')
.replace('.md', '')
.replace('/index', '')
data.redirect_from = addRedirect(data.redirect_from, oldPath)
fs.writeFileSync(file, frontmatter.stringify(content, data, { lineWidth: 10000 }))
})
// Add redirects to translations
const translationDirs = fs.readdirSync('translations')
.filter(file => !file.endsWith('.md'))
.map(dir => path.join('translations', dir, 'content/admin'))
translationDirs
.forEach(translationDir => {
walk(translationDir, { includeBasePath: true, directories: false })
.filter(file => file.endsWith('.md'))
.forEach(file => {
const contents = fs.readFileSync(file, 'utf8')
const { data, content } = frontmatter(contents)
const oldPath = file
.replace(translationDir, '/enterprise/admin')
.replace('.md', '')
.replace('/index', '')
data.redirect_from = addRedirect(data.redirect_from, oldPath)
fs.writeFileSync(file, frontmatter.stringify(content, data, { lineWidth: 10000 }))
})
})