mastodon-markdown-archive/README.md

50 lines
2 KiB
Markdown
Raw Normal View History

2024-05-09 08:36:28 +00:00
# Mastodon markdown archive
2024-04-21 13:16:46 +00:00
2024-05-09 08:36:28 +00:00
Fetch a Mastodon account's posts and save them as markdown files. Post content is converted to markdown, images are downloaded and inlined, and replies are threaded. Implements most of the parameters in Mastodon's public [API to get an account's statuses](https://docs.joinmastodon.org/methods/accounts/#statuses).
2024-04-21 13:16:46 +00:00
2024-05-09 08:36:28 +00:00
For the time being this formats the files in accordance to [Hugo's](https://gohugo.io) front-matter.
2024-04-21 11:21:55 +00:00
2024-05-09 08:36:28 +00:00
If a post has images, the post is created as a Hugo [page bundle](https://gohugo.io/content-management/page-bundles/) and images are downloaded in the corresponding post directory.
I use this tool to create an [archive of my Mastodon posts](https://garrido.io/microblog/), which I then syndicate to my own site following [PESOS](https://indieweb.org/PESOS).
2024-04-21 17:52:01 +00:00
## Flags
```
Usage of ./mastodon-pesos:
-dist string
2024-04-21 18:10:25 +00:00
Path to directory where files will be written (default "./posts")
2024-04-21 17:52:01 +00:00
-exclude-reblogs
Whether or not to exclude reblogs
-exclude-replies
Whether or not exclude replies to other users
-limit int
Maximum number of posts to fetch (default 40)
2024-04-21 18:10:25 +00:00
-max-id string
Fetch posts lesser than this id
-min-id string
Fetch posts immediately newer than this id
2024-04-21 17:52:01 +00:00
-persist
Persist most recent post id to /tmp/mastodon-pesos-fid
-since-id string
2024-04-21 18:10:25 +00:00
Fetch posts greater than this id
2024-04-21 17:52:01 +00:00
-user string
URL of User's Mastodon account whose toots will be fetched
```
2024-04-21 18:11:14 +00:00
## Example
2024-04-21 17:52:01 +00:00
Here is how I use this to fetch the 15 most recent posts in my Mastodon account. It excludes replies to others, and reblogs.
Lastly, I use `--persist` to save the most recent id to a file and use `--since-id` so that subsequent runs fetch posts only after the most recently fetched post.
```sh
./mastodon-pesos \
--user https://social.coop/@ggpsv \
--dist ./posts \
--exclude-replies \
--exclude-reblogs \
--limit=15 \
--persist \
--since-id=$(test -f /tmp/mastodon-pesos-fid && cat /tmp/mastodon-pesos-fid || echo "")
```