Skip to content

Instantly share code, notes, and snippets.

@manton
Created January 1, 2024 23:15
Show Gist options
  • Save manton/f4470f28ea50d649bbf08d9e43097f29 to your computer and use it in GitHub Desktop.
Save manton/f4470f28ea50d649bbf08d9e43097f29 to your computer and use it in GitHub Desktop.
require "json"
require "cgi"
# Micro.blog token
token = "..."
# mapping of local files to blog pages
markdown_folder = "/Users/manton/Dropbox/Documents/Indie Microblogging/Book Contents/"
markdown_files = {
"Introduction/Introduction.md": "/introduction/",
"Introduction/What is microblogging.md": "/what-is-microblogging/",
"Introduction/Uses for a microblog.md": "/uses-for-microblog/",
"Introduction/Mission to movement.md": "/mission-to-movement/",
"Introduction/The way forward.md": "/the-way-forward/",
"Part 1/Part 1- Rewind.md": "/rewind/",
"Part 1/Penn Station.md": "/penn-station/",
"Part 1/Pulled away from blogs.md": "/pulled-away-from/",
"Part 1/Leaving Twitter.md": "/leaving-twitter/",
"Part 1/App.net.md": "/appnet/",
"Part 1/WordPress and Tumblr.md": "/wordpress-and-tumblr/",
"Part 1/Interview with Leah Culver.md": "/interview-leah-culver/",
"Part 1/Toward decentralization.md": "/toward-decentralization/",
"Part 2/Part 2- Foundation.md": "/foundation/",
"Part 2/Domain names.md": "/domain-names/",
"Part 2/Syndication.md": "/syndication/",
"Part 2/RSS for microblogs.md": "/rss-for-microblogs/",
"Part 2/JSON Feed.md": "/json-feed/",
"Part 2/Introducing Micro.blog.md": "/introducing-microblog/",
"Part 2/External blogs with WordPress.md": "/external-blogs-wordpress/",
"Part 2/Alternative platforms.md": "/alternative-platforms/",
"Part 2/Micro.blog and feeds.md": "/microblog-and-feeds/",
"Part 2/Part of the web.md": "/part-of-web/",
"Part 2/Migration.md": "/migration/",
"Part 2/Blogging workflow.md": "/blogging-workflow/",
"Part 2/Why indie microblogging.md": "/why-indie-microblogging/",
"Part 2/Interview with Brent Simmons.md": "/interview-brent-simmons/",
"Part 3/Part 3- IndieWeb.md": "/indieweb/",
"Part 3/Permanence.md": "/permanence/",
"Part 3/Silos.md": "/silos/",
"Part 3/Cross-posting.md": "/cross-posting/",
"Part 3/Owning your content.md": "/owning-your-content/",
"Part 3/Microformats.md": "/microformats/",
"Part 3/Building blocks.md": "/building-blocks/",
"Part 3/IndieAuth.md": "/indieauth/",
"Part 3/Micropub.md": "/micropub/",
"Part 3/Webmention.md": "/webmention/",
"Part 3/Bridgy.md": "/bridgy/",
"Part 3/Blog archive format.md": "/blog-archive-format/",
"Part 3/Interview with Tantek Çelik and Aaron Parecki.md": "/interview-tantek-aaron/",
"Part 4/Part 4- Hypertext.md": "/hypertext/",
"Part 4/Photography.md": "/photography/",
"Part 4/Influence and reposts.md": "/influence-and-reposts/",
"Part 4/UI impacts behavior.md": "/ui-impacts-behavior/",
"Part 4/Using HTML.md": "/using-html/",
"Part 4/Starting a new photo blog.md": "/starting-photo-blog/",
"Part 4/Sunlit and photo feeds.md": "/sunlit-and-photo/",
"Part 4/Linkblogging.md": "/linkblogging/",
"Part 4/Interview with Om Malik": "/interview-om-malik/",
"Part 5/Part 5- Decentralization.md": "/decentralization/",
"Part 5/Notifications.md": "/notifications/",
"Part 5/Mastodon.md": "/mastodon/",
"Part 5/Pixelfed.md": "/pixelfed/",
"Part 5/ActivityPub.md": "/activitypub/",
"Part 5/Your blog.md": "/your-blog/",
"Part 5/WebSub.md": "/websub/",
"Part 5/Indie readers.md": "/indie-readers/",
"Part 6/Part 6- Community.md": "/community/",
"Part 6/Replies.md": "/replies/",
"Part 6/Harassment.md": "/harassment/",
"Part 6/Misinformation.md": "/misinformation/",
"Part 6/Section 230.md": "/section-230/",
"Part 6/Unattended algorithms.md": "/unattended-algorithms/",
"Part 6/Open gardens.md": "/open-gardens/",
"Part 6/Discovery.md": "/discovery/",
"Part 6/Popularity contests.md": "/popularity-contests/",
"Part 6/Banning users.md": "/banning-users/",
"Part 6/Interview with Jean MacDonald.md": "/interview-jean-macdonald/",
"Conclusion/Conclusion.md": "/conclusion/",
"Conclusion/The way out.md": "/the-way-out/",
"Conclusion/Sticking to the mission statement.md": "/sticking-to-mission/",
"Conclusion/Special thanks.md": "/special-thanks/"
}
for f in markdown_files.keys
# read Markdown text for the page
filename = markdown_files[f]
s = IO.read(File.join(markdown_folder, f.to_s))
url = "https://book.micro.blog" + filename
puts "Publishing page: #{filename}..."
# construct Micropub JSON to replace content
info = {
"mp-destination": "https://book.micro.blog/",
"mp-channel": "pages",
url: url,
action: "update",
replace: {
content: [ s ]
}
}
# write to temp file
IO.write("chapterfile.json", info.to_json)
# update the post
`curl https://micro.blog/micropub -d @chapterfile.json -H "Authorization: Bearer #{token}" -H "Content-Type: application/json"`
# always be nice to servers when looping
sleep 1
end
# cleanup the temp file we're using
if File.exists?("chapterfile.json")
File.delete("chapterfile.json")
end
puts "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment