From 797ccfcb6d75fe6175e2af895be937af28d9f814 Mon Sep 17 00:00:00 2001 From: Gabriel Garrido Date: Sun, 1 Sep 2024 12:09:03 -0600 Subject: [PATCH 1/5] Replace alt text newlines in default post template --- files/templates/post.tmpl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/files/templates/post.tmpl b/files/templates/post.tmpl index 93f2592..f64736e 100644 --- a/files/templates/post.tmpl +++ b/files/templates/post.tmpl @@ -23,9 +23,9 @@ descendants: {{ range .Post.MediaAttachments }} {{- if eq .Type "image" }} {{- if .Path }} -![{{ .Description }}]({{ osBase .Path }}) +![{{ .Description | replace "\n" "" }}]({{ osBase .Path }}) {{- else }} -![{{ .Description }}]({{ .URL }}) +![{{ .Description | replace "\n" "" }}]({{ .URL }}) {{- end }} {{ end }} {{- end -}} @@ -35,9 +35,9 @@ descendants: {{ range .MediaAttachments }} {{- if eq .Type "image" }} {{- if .Path }} -![{{ .Description }}]({{ osBase .Path }}) +![{{ .Description | replace "\n" "" }}]({{ osBase .Path }}) {{- else }} -![{{ .Description }}]({{ .URL }}) +![{{ .Description | replace "\n" ""}}]({{ .URL }}) {{- end }} {{- end }} {{- end }} From f2b07a5516c272251b89e5d9013202679ece9d37 Mon Sep 17 00:00:00 2001 From: Gabriel Garrido Date: Sun, 1 Sep 2024 13:02:44 -0600 Subject: [PATCH 2/5] Add a Dockerfile and update README --- .dockerignore | 1 + Dockerfile | 25 +++++++++++++++++++++++++ README.md | 29 ++++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..08e1001 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +justfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1da9514 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM golang:1.23.0-alpine3.20 AS build + +WORKDIR /app +COPY go.mod go.sum . +RUN go mod download + +COPY . . +ENV CGO_ENABLED=0 +ENV GOOS=linux + +RUN go build -o mastodon-markdown-archive + +FROM alpine:3.20 +RUN apk add --no-cache ca-certificates + +LABEL org.opencontainers.image.title="Mastodon Markdown Archive" +LABEL org.opencontainers.image.description="Archive Mastodon posts as markdown files" +LABEL org.opencontainers.image.vendor="Gabriel Garrido" +LABEL org.opencontainers.image.licenses=MIT +LABEL org.opencontainers.image.url=https://git.garrido.io/gabriel/mastodon-markdown-archive +LABEL org.opencontainers.image.source=https://git.garrido.io/gabriel/mastodon-markdown-archive +LABEL org.opencontainers.image.documentation=https://git.garrido.io/gabriel/mastodon-markdown-archive + +COPY --from=build /app/mastodon-markdown-archive /usr/bin/mastodon-markdown-archive +ENTRYPOINT ["/usr/bin/mastodon-markdown-archive"] diff --git a/README.md b/README.md index 92ae7bc..10c91d7 100644 --- a/README.md +++ b/README.md @@ -49,10 +49,37 @@ It is likely that I have not considered all possible use cases, or that I've bee ## Installation +### From source + [Go](https://go.dev/doc/install) is required for installation. You can clone this repo and run `go build main.go` in the repository's directory, or you can run `go install git.garrido.io/gabriel/mastodon-markdown-archive@latest` to install a binary of the latest version. +### Container + +A [Dockerfile](./Dockerfile) is included in this repository. + +An image can be built as follows: + +`docker build -t mastodon-markdown-archive .` + +A host folder should be mounted into the container so that the files generated by the container are persisted to the host's file system. You can run the tool as follows: + +```sh +docker run --rm -v ~/posts:/posts mastodon-markdown-archive \ +--user=https://social.coop/@ggpsv \ +--dist=/posts \ +--exclude-replies \ +--exclude-reblogs \ +--persist-last=./last \ +--visibility=public \ +--download-media=bundle \ +--threaded=true \ +--max-id=$(test -f ./last && cat ./last || echo "") +``` + +The container's volume target (e.g `:/posts`) should match the directory passed to the `--dist` argument. + ## Dependencies This tool has only two direct dependencies, which are included to provide useful, though largely optional, functionality in templates: @@ -413,4 +440,4 @@ This is done specifically to support Hugo [page bundles](https://gohugo.io/conte ## Known issues -1. A reply post may still appear in the list of posts despite using `--exclude-replies`. This happens when the post in question is a reply to a post that has since been deleted. It looks like Mastodon's API stops treating the reply as a reply. It no longer points to another post, and thus is not affected by the `exclude_replies` parameter. \ No newline at end of file +1. A reply post may still appear in the list of posts despite using `--exclude-replies`. This happens when the post in question is a reply to a post that has since been deleted. It looks like Mastodon's API stops treating the reply as a reply. It no longer points to another post, and thus is not affected by the `exclude_replies` parameter. From 646dfde6aa20ac6ccf63a0d3c0a00e2104e7983f Mon Sep 17 00:00:00 2001 From: Gabriel Garrido Date: Sun, 1 Sep 2024 13:05:10 -0600 Subject: [PATCH 3/5] Update ToC --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 10c91d7..ed60f13 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ It is likely that I have not considered all possible use cases, or that I've bee ## Table of contents * [Installation](#installation) + * [From Source](#from-source) + * [Container](#container) * [Dependencies](#dependencies) * [Usage](#usage) * [Environment variables](#environment-variables) From d8bb031935229abec1ce2eb69494dfe698135d24 Mon Sep 17 00:00:00 2001 From: Gabriel Garrido Date: Sun, 1 Sep 2024 13:05:39 -0600 Subject: [PATCH 4/5] Update ToC --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ed60f13..16902e0 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ It is likely that I have not considered all possible use cases, or that I've bee ## Table of contents * [Installation](#installation) - * [From Source](#from-source) + * [From source](#from-source) * [Container](#container) * [Dependencies](#dependencies) * [Usage](#usage) From bfcafbeeeb0440d76ade405816c07854028ff036 Mon Sep 17 00:00:00 2001 From: Gabriel Garrido Date: Sun, 1 Sep 2024 13:10:10 -0600 Subject: [PATCH 5/5] Add changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..166382b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +# Changelog + +## Version 1.0.0 (September 1, 2024) +Initial release