Compare commits

...

8 commits

Author SHA1 Message Date
abaac06cf4
chg: [test] default template updated 2024-09-03 06:21:17 +02:00
9808362509
Merge branch 'main' of https://git.garrido.io/gabriel/mastodon-markdown-archive 2024-09-03 06:20:05 +02:00
81673792b3
chg: [template] added the foo.be template 2024-09-03 06:17:21 +02:00
Gabriel Garrido
bfcafbeeeb Add changelog 2024-09-01 13:10:10 -06:00
Gabriel Garrido
d8bb031935 Update ToC 2024-09-01 13:05:39 -06:00
Gabriel Garrido
646dfde6aa Update ToC 2024-09-01 13:05:10 -06:00
Gabriel Garrido
f2b07a5516 Add a Dockerfile and update README 2024-09-01 13:02:44 -06:00
Gabriel Garrido
797ccfcb6d Replace alt text newlines in default post template 2024-09-01 12:09:03 -06:00
7 changed files with 108 additions and 5 deletions

1
.dockerignore Normal file
View file

@ -0,0 +1 @@
justfile

4
CHANGELOG.md Normal file
View file

@ -0,0 +1,4 @@
# Changelog
## Version 1.0.0 (September 1, 2024)
Initial release

25
Dockerfile Normal file
View file

@ -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"]

View file

@ -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)
@ -49,10 +51,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 +442,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.
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.

46
files/templates/foo.tmpl Normal file
View file

@ -0,0 +1,46 @@
---
date: {{ .Post.CreatedAt }}
{{- if .Post.InReplyToId }}
in_reply_to: {{ .Post.InReplyToId }}
{{- end }}
post_uri: {{ .Post.URI }}
post_id: {{ .Post.Id }}
{{- if len .Post.AllTags }}
tags:
{{- range .Post.AllTags }}
- {{ .Name }}
{{- end }}
{{- end }}
{{- if len .Post.Descendants }}
descendants:
{{- range .Post.Descendants }}
- {{ .Id }}
{{- end }}
{{- end }}
layout: page
title: paperbay.org Mastodon - {{ .Post.URI }}
---
{{ .Post.Content | toMarkdown }}
{{ range .Post.MediaAttachments }}
{{- if eq .Type "image" }}
{{- if .Path }}
![{{ .Description | replace "\n" "" }}]({{ osBase .Path }})
{{- else }}
![{{ .Description | replace "\n" "" }}]({{ .URL }})
{{- end }}
{{ end }}
{{- end -}}
{{ range .Post.Descendants }}
{{ .Content | toMarkdown }}
{{ range .MediaAttachments }}
{{- if eq .Type "image" }}
{{- if .Path }}
![{{ .Description | replace "\n" ""}}]({{ osBase .Path }})
{{- else }}
![{{ .Description | replace "\n" ""}}]({{ .URL }})
{{- end }}
{{- end }}
{{- end }}
{{- end }}

View file

@ -17,8 +17,6 @@ descendants:
- {{ .Id }}
{{- end }}
{{- end }}
layout: page
title: paperbay.org Mastodon - {{ .Post.URI }}
---
{{ .Post.Content | toMarkdown }}
@ -37,7 +35,7 @@ title: paperbay.org Mastodon - {{ .Post.URI }}
{{ range .MediaAttachments }}
{{- if eq .Type "image" }}
{{- if .Path }}
![{{ .Description | replace "\n" ""}}]({{ osBase .Path }})
![{{ .Description | replace "\n" "" }}]({{ osBase .Path }})
{{- else }}
![{{ .Description | replace "\n" ""}}]({{ .URL }})
{{- end }}

View file

@ -1,7 +1,7 @@
#!/bin/bash
while true; do
command="./mastodon-markdown-archive --template=../files/templates/post.tmpl --user=https://paperbay.org/@a --dist=./posts --persist-last=./last --max-id=$(test -f ./last && cat ./last || echo "") --download-media=./posts --porcelain=true --threaded=true"
command="./mastodon-markdown-archive --template=../files/templates/foo.tmpl --user=https://paperbay.org/@a --dist=./posts --persist-last=./last --max-id=$(test -f ./last && cat ./last || echo "") --download-media=./posts --porcelain=true --threaded=true"
output=$($command)
if [[ "$output" -eq 0 ]]; then
echo "No posts returned. Exiting"