diff --git a/docs-utils/update-images.js b/docs-utils/update-images.js index 83335188d..bc736cca7 100644 --- a/docs-utils/update-images.js +++ b/docs-utils/update-images.js @@ -3,8 +3,7 @@ const path = require('path') const frontmatter = require('front-matter') const imageDownloader = require('image-downloader') -const baseURL = 'https://raw.githubusercontent.com/vtexdocs/help-center-content/main' -const rootDir = path.resolve(__dirname, '..') +const baseURL = 'https://raw.githubusercontent.com/vtexdocs/help-center-content/main/' const isValidExtension = (ext) => { return /^[a-zA-Z0-9]*$/.test(ext) @@ -23,10 +22,9 @@ const getExtension = (url) => { const updateImages = async (filepath) => { const content = fs.readFileSync(filepath, 'utf-8') - const slug = frontmatter(content).attributes.slug - const locale = frontmatter(content).attributes.locale const images = [] + let imageIndex = 1 const replaceURL = (match, extra, url) => { const isMarkdownBlock = match.startsWith('![') if (url.startsWith(baseURL)) return match @@ -34,20 +32,17 @@ const updateImages = async (filepath) => { let newURL = '' if (url.startsWith('http://') || url.startsWith('https://')) { const ext = getExtension(url) - const filename = `${slug}-${images.length}.${ext}` - + + const newfilepath = `${filepath.split('.')[0]}_${imageIndex}.${ext}` images.push({ - filepath: path.resolve('images', locale, filename), + filepath: path.resolve(newfilepath), url }) - - newURL = `${baseURL}/images/${locale}/${filename}` - } else if (path.isAbsolute(url)) { - newURL = `${baseURL}${url}` - } else { - newURL = `${baseURL}${path.resolve(path.dirname(filepath), url).replace(rootDir, '')}` - } - + + newURL = `${baseURL}${filepath.split('.')[0]}_${imageIndex}.${ext}` + imageIndex++ + } + return isMarkdownBlock ? `![${extra}](${newURL})` : `