Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a926f3789 | ||
|
|
db6c0f6cc2 | ||
|
|
25adc4410d | ||
|
|
b77a69e634 | ||
|
|
1e448c3f31 | ||
|
|
99899bd49e | ||
|
|
f90cc7d2a0 | ||
|
|
1341dd2833 | ||
|
|
260b946f25 |
@@ -5,43 +5,50 @@ _A small Janet script to archive all your Mastodon bookmarks in Markdown files._
|
|||||||
Because Mastodon posts can disappear for a variety of reasons (deletion, defederation, server instance shutdown, ...), it is safer to archive your bookmarks.
|
Because Mastodon posts can disappear for a variety of reasons (deletion, defederation, server instance shutdown, ...), it is safer to archive your bookmarks.
|
||||||
|
|
||||||
Each Markdown file will contain:
|
Each Markdown file will contain:
|
||||||
- A link to the original post
|
- [x] A link to the original post
|
||||||
- The author's handle
|
- [x] The author's handle
|
||||||
- The post's content in HTML
|
- [x] The post's content in HTML
|
||||||
- The media attachments locally downloaded
|
- [x] The media attachments locally downloaded
|
||||||
- If available, the alt text for each media
|
- [x] If available, the alt text for each media
|
||||||
|
- [ ] The full thread, if applicable
|
||||||
|
- [ ] The link card, if any
|
||||||
|
|
||||||
Most of these values will be in the form of `key:: value` for easy integration with Obsidian's plugin Dataview. A sample script is available [here](./dataview-query.js)
|
Most of these values will be in the form of `key:: value` for easy integration with Obsidian's plugin Dataview.
|
||||||
|
|
||||||
## Setup & Run
|
A sample script to render all your bookmarks is available [here](./dataview-query.js)
|
||||||
|
|
||||||
|
## Build & Run
|
||||||
|
|
||||||
|
### Pre-requirements
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Required by the httprequest dependency
|
||||||
|
$ sudo apt install libcurl4-openssl-dev
|
||||||
|
```
|
||||||
|
|
||||||
|
- Clone this repository
|
||||||
|
- Install Janet and jpm https://janet-lang.org/
|
||||||
- Get an access token for your Mastodon account
|
- Get an access token for your Mastodon account
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
- Run the program
|
|
||||||
|
### Run
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ ./mastodon-bookmarks YOUR_INSTANCE YOUR_APP_TOKEN
|
# Install dependencies locally with -l (--local)
|
||||||
|
$ jpm deps -l
|
||||||
|
# Tell jpm that our dependencies are local, before starting the script
|
||||||
|
$ jpm -l janet main.janet YOUR_INSTANCE YOUR_APP_TOKEN
|
||||||
```
|
```
|
||||||
|
|
||||||
The `YOUR_INSTANCE` value must not have trailing slash (e.g: `https://hachyderm.io`)
|
The `YOUR_INSTANCE` value **must not** have the trailing slash (e.g: `https://hachyderm.io`)
|
||||||
|
|
||||||
## Development
|
### Build for release
|
||||||
|
|
||||||
- Clone this repository
|
|
||||||
- Install Janet and jpm https://janet-lang.org/
|
|
||||||
- `jpm deps --local`
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ janet main.janet YOUR_INSTANCE YOUR_APP_TOKEN
|
$ jpm build -l
|
||||||
```
|
|
||||||
|
|
||||||
## Build binary
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ jpm build
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## LICENSE
|
## LICENSE
|
||||||
|
|||||||
+11
-4
@@ -15,20 +15,27 @@
|
|||||||
"Downloads the media from the item."
|
"Downloads the media from the item."
|
||||||
(def files @[])
|
(def files @[])
|
||||||
(def media (item "media_attachments"))
|
(def media (item "media_attachments"))
|
||||||
(pp (item "media_attachments"))
|
(if dbg
|
||||||
|
(pp (item "media_attachments")))
|
||||||
(each m media
|
(each m media
|
||||||
(def url (m "url"))
|
(def url (m "url"))
|
||||||
(def folder (string save-path "attachments/"))
|
(def folder (string save-path "attachments/"))
|
||||||
(array/push files {:path (string "./attachments/" (utils/get-image url folder))
|
(array/push files {:path (string "./attachments/" (utils/get-image url folder))
|
||||||
:description (m "description")}))
|
:description (m "description")}))
|
||||||
(pp files)
|
(if dbg (pp files))
|
||||||
files)
|
files)
|
||||||
|
|
||||||
|
|
||||||
(defn write-markdown [item]
|
(defn write-markdown [item]
|
||||||
(def files (download-media item))
|
(def files (download-media item))
|
||||||
(def id (item "id"))
|
(def id (item "id"))
|
||||||
(def fout (file/open (string save-path id ".md") :w))
|
(def path (string save-path id ".md"))
|
||||||
|
|
||||||
|
(if (utils/exists? path)
|
||||||
|
(do
|
||||||
|
(print (string "Skipping " id))
|
||||||
|
(break)))
|
||||||
|
(def fout (file/open path :w))
|
||||||
|
|
||||||
(def inline (string
|
(def inline (string
|
||||||
"mastodon-url:: " (item "url") " \n"
|
"mastodon-url:: " (item "url") " \n"
|
||||||
@@ -103,7 +110,7 @@
|
|||||||
(set dbg (get args 3))
|
(set dbg (get args 3))
|
||||||
|
|
||||||
(array/push urls (string server "/api/v1/bookmarks"))
|
(array/push urls (string server "/api/v1/bookmarks"))
|
||||||
|
|
||||||
(os/mkdir "./bookmarks")
|
(os/mkdir "./bookmarks")
|
||||||
(os/mkdir "./bookmarks/attachments")
|
(os/mkdir "./bookmarks/attachments")
|
||||||
(download-bookmarks))
|
(download-bookmarks))
|
||||||
|
|||||||
+6
-1
@@ -1,5 +1,10 @@
|
|||||||
(import httprequest :as r)
|
(import httprequest :as r)
|
||||||
|
|
||||||
|
(def exists? (fn [path]
|
||||||
|
"Returns whether a file exists at the specified path."
|
||||||
|
(def f (file/open path :r))
|
||||||
|
(if f (do (file/close f) true) false)))
|
||||||
|
|
||||||
(defn get-image [url folder &named headers opts]
|
(defn get-image [url folder &named headers opts]
|
||||||
"Download an image from a URL and save it to a file. Returns the path to the saved file."
|
"Download an image from a URL and save it to a file. Returns the path to the saved file."
|
||||||
(default headers {})
|
(default headers {})
|
||||||
@@ -42,4 +47,4 @@
|
|||||||
(if (empty? arr) (break nil))
|
(if (empty? arr) (break nil))
|
||||||
(def head (in arr 0))
|
(def head (in arr 0))
|
||||||
(array/remove arr 0)
|
(array/remove arr 0)
|
||||||
head)
|
head)
|
||||||
|
|||||||
Reference in New Issue
Block a user