Skip to content

Commit

Permalink
rewrite locale image urls in readmes
Browse files Browse the repository at this point in the history
  • Loading branch information
zeke committed Sep 14, 2017
1 parent e5d4cc8 commit c3a6f98
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"devDependencies": {
"chai": "^3.5.0",
"check-for-leaks": "^1.0.2",
"cheerio": "^1.0.0-rc.2",
"clean-deep": "^2.0.1",
"count-array-values": "^1.2.1",
"dotenv-safe": "^4.0.4",
Expand Down
22 changes: 20 additions & 2 deletions script/releases.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs')
const path = require('path')
const github = require('../lib/github')
const cheerio = require('cheerio')
const parseGitUrl = require('github-url-to-object')
const Duration = require('duration')
const downloadExtensions = [
Expand Down Expand Up @@ -87,8 +88,25 @@ function go () {
latestRelease: false
}
return github.repos.getReadme(gitHubOptions)
}).then((readme) => {
output[app.slug].readme = readme.data
}).then((response) => {
let readme = response.data
let $ = cheerio.load(readme)
let imagesChanged = false

$('img').each(function (i, img) {
let currentImg = $(img)
let imageSrc = currentImg.attr('src')
if (imageSrc && imageSrc.indexOf('http') === -1) {
currentImg.attr('src', `${app.repository}/raw/master/${imageSrc}`)
imagesChanged = true
}
})
if (imagesChanged) {
console.log(`Updating relative image URLs in readme for ${app.name}`)
readme = $('body').html()
}

output[app.slug].readme = readme
go()
})
}

0 comments on commit c3a6f98

Please sign in to comment.