Skip to content

Commit

Permalink
Update update-images.js
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroAntunesCosta committed Sep 24, 2024
1 parent 783a82d commit bea6dad
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions docs-utils/update-images.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const fs = require('fs')
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 baseURL = 'https://raw.githubusercontent.com/vtexdocs/help-center-content/refs/heads/main/'

const isValidExtension = (ext) => {
return /^[a-zA-Z0-9]*$/.test(ext)
Expand All @@ -28,19 +29,21 @@ const updateImages = async (filepath) => {
const isMarkdownBlock = match.startsWith('![')
if (url.startsWith(baseURL)) return match

if (url.startsWith('//')) {
url = `https:${url}`
}

let newURL = ''
if (url.startsWith('http://') || url.startsWith('https://')) {
const ext = getExtension(url)

const newfilepath = `${filepath.split('.')[0]}_${imageIndex}.${ext}`
images.push({
filepath: path.resolve(newfilepath),
url
})

newURL = `${baseURL}${filepath.split('.')[0]}_${imageIndex}.${ext}`
imageIndex++
}
const ext = getExtension(url)

const newfilepath = `${filepath.split('.')[0]}_${imageIndex}.${ext}`
images.push({
filepath: path.resolve(newfilepath),
url
})

newURL = `${baseURL}${filepath.split('.')[0]}_${imageIndex}.${ext}`
imageIndex++

return isMarkdownBlock ? `![${extra}](${newURL})` : `<img ${extra}src="${newURL}"`
}
Expand Down

0 comments on commit bea6dad

Please sign in to comment.