Created
January 5, 2014 07:30
-
-
Save WardCunningham/8265495 to your computer and use it in GitHub Desktop.
Squeeze a federated wiki page by replacing a huge image with a smaller copy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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