forked from neo4j-documentation/knowledge-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3-support-replace-image-target.js
30 lines (28 loc) · 1.09 KB
/
s3-support-replace-image-target.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
const path = require('path')
const fs = require('fs')
const pagesDir = path.join(__dirname, 'articles', 'modules', 'ROOT', 'pages')
const imgurImageReplaceMacroRx = /(image::?)(https:\/\/s3.amazonaws.com\/support.neotechnology.com\/KBs\/([^.]+\.(png|jpe?g)))\[([^\]]*)]/g
;(async () => {
try {
const asciidocFiles = fs.readdirSync(pagesDir)
for (const file of asciidocFiles) {
if (file.endsWith('.adoc')) {
const filePath = path.join(pagesDir, file);
const content = fs.readFileSync(filePath, 'utf8')
const lines = content.split(/\r?\n/)
const data = []
for (const line of lines) {
data.push(line.replace(imgurImageReplaceMacroRx, (replace, ...args) => {
const imageMacro = args[0]
let imageName = args[2]
const attributesList = args[4]
return `${imageMacro}https://s3.amazonaws.com/dev.assets.neo4j.com/kb-content/${imageName}[${attributesList}]`
}))
}
fs.writeFileSync(filePath, data.join('\n'), 'utf8')
}
}
} catch (err) {
console.error('Error', err)
}
})()