Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Squeeze a federated wiki page by replacing a huge image with a smaller copy
# replace an image with a much smaller one
# work in localhost, then post with scp
# scp pages/degrees-of-publicness fed.wiki.org:wiki/farm-8080/data/farm/mehaffy.fed.wiki.org/pages/
fs = require 'fs'
destFileName = '../pages/degrees-of-publicness'
# find source image
source = JSON.parse fs.readFileSync '../pages/scratch', 'utf-8'
images = (item for item in source.story when item.type is 'image')
throw "trouble: expect one source image" unless images.length is 1
image = images[0]
# find dest image
dest = JSON.parse fs.readFileSync destFileName, 'utf-8'
destImages = (item for item in dest.story when item.type is 'image')
throw "trouble: expect one dest image" unless images.length is 1
destImage = destImages[0]
# revise the story
destImage.url = image.url
# revise the journal
for action in dest.journal
continue unless action.id is destImage.id and action.type in ['add', 'edit']
console.log action.type
action.item.url = image.url
# write revised dest
data = JSON.stringify dest, null, 2
fs.writeFileSync destFileName, data, 'utf-8'
console.log 'done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment