Skip to content

Instantly share code, notes, and snippets.

@czottmann
Created January 30, 2017 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save czottmann/e6179631b74727ff67084f13973ccd6a to your computer and use it in GitHub Desktop.
Save czottmann/e6179631b74727ff67084f13973ccd6a to your computer and use it in GitHub Desktop.
Ghost export (JSON) to Markdown files (while dropping a lot of metadata)
#!/Users/carlo/.rubies/ruby-2.3.3/bin/ruby
require 'json'
require 'ostruct'
json_content = File.open('ghost.2017-01-27.json', 'r').read
nodes = JSON.parse(json_content)
posts = nodes['db'][0]['data']['posts']
figures_pattern = /<figure>\s*\!\[(.+)\]\((.+)\)\s*<figcaption>.+<\/figcaption>\s*<\/figure>/
posts.each do |post|
p = OpenStruct.new(post)
title = JSON.generate(p.title)
src = p.markdown
if src.include?('<figure>')
figure_id = 0
src.gsub!(figures_pattern) do |match|
figure_id += 1
match.gsub(figures_pattern, "![#{ $1 }][fig_#{ figure_id }]
[fig_#{ figure_id }]: #{ $2 } \"#{ $1 }\"")
end
end
if p.page
filename = "site/pages/#{ p.slug }.html.md"
content = <<MD
---
title: #{ title }
---
#{ p.markdown }
MD
else
post_date = p.published_at[0, 10]
filename = "site/posts/#{ post_date }-#{ p.slug }.html.md"
content = <<MD
---
title: #{ title }
date: #{ post_date }
---
#{ src }
MD
end
File.open(filename, 'w') do |f|
f.puts content
end
puts title
end
# "id": 1376,
# "uuid": "b58fcc53-c403-4754-9a38-09293e073cff",
# "title": "Mandatory Improv Theatre 3000",
# "slug": "mandatory-improv-theatre-3000",
# "markdown": "<summary><strong>TL;DR: An afternoon suffering through the performance of an improv theatre troupe is likely not going to save the company after all.</strong></summary>\n\nThe whole staff had to participate in a mandatory \"workshop\" today. Until we've arrived at the location on afternoon we had no clue what would happen;\nbeing the sceptical bitches we are my co-workers and I declared that if this would turn out to be one of those \"get off your shoes and hold eachothers hands\" type of thing, we'd leave the scene immediately. Oh boy, we had _no_ idea.\n\nWhen we got there, it all started out with the more or less usual standing around, waiting for doom to hit us. While we were waiting, three totally unfamiliar faces showed up; one woman was dressed like a cleaning lady and bitching at several co-workers, one guy tried and failed miserably to make a\n\"austrian waiter\" impression, and the second woman was running around in a business dress telling people she had \"no clue what's going on here but someone mentioned hats\" (quote). At this point we all were highly suspicious and tried to get drunk quickly - which is somewhat hard when all you got is orange juice and lemonade.\n\nThen the fun began. We had to play games. No, not FPS or RTS, but the bad type. The \"look out, the bogeyman is trying to get you\" stuff. And counting games with numbers and noises. I'm serious. Silly shit. This crap went on for a while, then these fools came up with a play for the staff - the company history… or better said: the company history if the company would've existed 1000 years ago. Again, I'm serious. And they tried to do that using improvisation. Anyone seen improvisational stage play? No? It's like trying to make gold from poo. Never works out. They lost their dignity, and I was looking for co-workers willing to stab me, really. None were to be found, and sadly, noone had drugs at hand neither.\n\nAfter this motivational nightmare there was a rather lengthy break where almost everyone was trying to convince the others to knock him out or anything. The old \"please kill me\" routine -- because we all knew we were only halfway thru.\n\nAnyways, at one point the break was declared over, and we were dragged went back to our seats. They continued to do the improvisation stuff (look to the future yadda yadda yadda), then there was a couple of guys from the company --\nhigher levels -- which were showing some typical meeting situations etc.,\nwhich was fun because they were right, and since they were faces we could relate to, it was okay. Silly, but okay. After another 40 minutes or so the improv team took over again, made us pick colored cards from hats and told us that a) yellow cards represent the customer, the red cards represent the holding company and the green cards our own company, and b) we should try to write down what we as (customer|holding|company) expect from the whole merger\n/going-back-to-the-holding thing which is currently going on. People did that,\nfolded the cards, threw them back into the hat. Then these guys take all the cards, mix them and shower them over the stage floor -- and started a _totally_ improvised play by picking up and reading random cards. Basically the _idea_ behind the play was that everyone of them represented one of the aforementioned parties, and the overall scene we had to witness was about a customer asking for a job to be done, a concept to be written, blablabla.\n\nAt this point, the dignity was gone. At least theirs, in my eyes. A hundred years ago these folks would have been the property of a circus, leaving in cages. Nowadays they do \"improvisational stage play\" or whatever it is called,\nmaking money from it.\n\nWell, to finish up here -- none of these bastards wanted to knock me out, so I had to watch the whole thing. I never thought it was possible to put so much time (and thus money) to waste so easily. We could've done real work instead.\nI mean, really… At least the buffet was good.\n\nNext time I get a mail mentioning a workshop, I'll either call in sick or try to take the day off or anything.\n",
# "html": "<p><summary><strong>TL;DR: An afternoon suffering through the performance of an improv theatre troupe is likely not going to save the company after all.</strong></summary></p>\n\n<p>The whole staff had to participate in a mandatory \"workshop\" today. Until we've arrived at the location on afternoon we had no clue what would happen; <br />\nbeing the sceptical bitches we are my co-workers and I declared that if this would turn out to be one of those \"get off your shoes and hold eachothers hands\" type of thing, we'd leave the scene immediately. Oh boy, we had <em>no</em> idea.</p>\n\n<p>When we got there, it all started out with the more or less usual standing around, waiting for doom to hit us. While we were waiting, three totally unfamiliar faces showed up; one woman was dressed like a cleaning lady and bitching at several co-workers, one guy tried and failed miserably to make a <br />\n\"austrian waiter\" impression, and the second woman was running around in a business dress telling people she had \"no clue what's going on here but someone mentioned hats\" (quote). At this point we all were highly suspicious and tried to get drunk quickly - which is somewhat hard when all you got is orange juice and lemonade.</p>\n\n<p>Then the fun began. We had to play games. No, not FPS or RTS, but the bad type. The \"look out, the bogeyman is trying to get you\" stuff. And counting games with numbers and noises. I'm serious. Silly shit. This crap went on for a while, then these fools came up with a play for the staff - the company history… or better said: the company history if the company would've existed 1000 years ago. Again, I'm serious. And they tried to do that using improvisation. Anyone seen improvisational stage play? No? It's like trying to make gold from poo. Never works out. They lost their dignity, and I was looking for co-workers willing to stab me, really. None were to be found, and sadly, noone had drugs at hand neither.</p>\n\n<p>After this motivational nightmare there was a rather lengthy break where almost everyone was trying to convince the others to knock him out or anything. The old \"please kill me\" routine -- because we all knew we were only halfway thru.</p>\n\n<p>Anyways, at one point the break was declared over, and we were dragged went back to our seats. They continued to do the improvisation stuff (look to the future yadda yadda yadda), then there was a couple of guys from the company -- <br />\nhigher levels -- which were showing some typical meeting situations etc., <br />\nwhich was fun because they were right, and since they were faces we could relate to, it was okay. Silly, but okay. After another 40 minutes or so the improv team took over again, made us pick colored cards from hats and told us that a) yellow cards represent the customer, the red cards represent the holding company and the green cards our own company, and b) we should try to write down what we as (customer|holding|company) expect from the whole merger <br />\n/going-back-to-the-holding thing which is currently going on. People did that,\nfolded the cards, threw them back into the hat. Then these guys take all the cards, mix them and shower them over the stage floor -- and started a <em>totally</em> improvised play by picking up and reading random cards. Basically the <em>idea</em> behind the play was that everyone of them represented one of the aforementioned parties, and the overall scene we had to witness was about a customer asking for a job to be done, a concept to be written, blablabla.</p>\n\n<p>At this point, the dignity was gone. At least theirs, in my eyes. A hundred years ago these folks would have been the property of a circus, leaving in cages. Nowadays they do \"improvisational stage play\" or whatever it is called, <br />\nmaking money from it.</p>\n\n<p>Well, to finish up here -- none of these bastards wanted to knock me out, so I had to watch the whole thing. I never thought it was possible to put so much time (and thus money) to waste so easily. We could've done real work instead. <br />\nI mean, really… At least the buffet was good.</p>\n\n<p>Next time I get a mail mentioning a workshop, I'll either call in sick or try to take the day off or anything.</p>",
# "image": null,
# "featured": false,
# "page": false,
# "status": "published",
# "language": "en_US",
# "meta_title": null,
# "meta_description": null,
# "author_id": 1,
# "created_at": "2003-04-04T00:00:00.000Z",
# "created_by": 1,
# "updated_at": "2003-04-04T00:00:00.000Z",
# "updated_by": 1,
# "published_at": "2003-04-04T00:00:00.000Z",
# "published_by": 1,
# "visibility": "public",
# "mobiledoc": null,
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment