From 54d21b2b32faad23a7bfb6401c583ad6708fd3fd Mon Sep 17 00:00:00 2001 From: John Bowdre Date: Sat, 13 Apr 2024 15:11:41 -0500 Subject: [PATCH] add action to convert markdown posts to gempost --- .github/actions/markdown2gempost/Dockerfile | 23 +++++++++++++ .github/actions/markdown2gempost/action.yml | 15 +++++++++ .../actions/markdown2gempost/convert-dir.sh | 24 ++++++++++++++ .github/workflows/markdown2gempost.yml | 32 +++++++++++++++++++ markdown/.gitkeep | 0 5 files changed, 94 insertions(+) create mode 100644 .github/actions/markdown2gempost/Dockerfile create mode 100644 .github/actions/markdown2gempost/action.yml create mode 100644 .github/actions/markdown2gempost/convert-dir.sh create mode 100644 .github/workflows/markdown2gempost.yml create mode 100644 markdown/.gitkeep diff --git a/.github/actions/markdown2gempost/Dockerfile b/.github/actions/markdown2gempost/Dockerfile new file mode 100644 index 0000000..0af5cc8 --- /dev/null +++ b/.github/actions/markdown2gempost/Dockerfile @@ -0,0 +1,23 @@ +FROM golang:1.22 AS go-builder + +WORKDIR /app + +RUN git clone https://github.com/jbowdre/md2gmi.git + +WORKDIR /app/md2gmi + +RUN go mod download && CGO_ENABLED=0 GOOS=linux go build -o /md2gmi + +FROM ubuntu:22.04 AS release + +RUN DEBIAN_FRONTEND=noninteractive apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y uuid-runtime=2.37.2-4ubuntu3.4 \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=go-builder /md2gmi /usr/local/bin/md2gmi +COPY convert-dir.sh /usr/local/bin/convert-dir.sh +RUN chmod +x /usr/local/bin/convert-dir.sh + +WORKDIR /github/workspace + +ENTRYPOINT ["/usr/local/bin/convert-dir.sh"] \ No newline at end of file diff --git a/.github/actions/markdown2gempost/action.yml b/.github/actions/markdown2gempost/action.yml new file mode 100644 index 0000000..cca1129 --- /dev/null +++ b/.github/actions/markdown2gempost/action.yml @@ -0,0 +1,15 @@ +name: 'Markdown to Gempost' +description: 'Convert Markdown posts to Gemini posts with YAML sidecars for use with Gempost' +inputs: + input-dir: + description: 'The directory containing markdown files' + required: true + output-dir: + description: 'The directory to write gemini files to' + required: true +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.input-dir }} + - ${{ inputs.output-dir }} \ No newline at end of file diff --git a/.github/actions/markdown2gempost/convert-dir.sh b/.github/actions/markdown2gempost/convert-dir.sh new file mode 100644 index 0000000..6bc384b --- /dev/null +++ b/.github/actions/markdown2gempost/convert-dir.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +input_dir="$1" +output_dir="$2" + +# Iterate over .md files in input directory +for file in "$input_dir"/*.md; do + file=$(basename "$file") + echo "Processing file: $file" + + # Extract frontmatter and dump it to YAML file + echo "id: \"urn:uuid:$(uuidgen)\"" > "$output_dir/${file%.md}.yaml" + awk '/^---$/{if(seen){exit}else{seen=1;next}} seen' "$input_dir/$file" >> "$output_dir/${file%.md}.yaml" + echo "Wrote frontmatter to file: $output_dir/${file%.md}.yaml" + + # Remove HTML tags, including those which may span multiple lines + if awk -v RS='^$' -v ORS='' '{gsub(/<[^>]*>/, ""); print}' "$input_dir/$file" > "$input_dir/tmp.md"; then + mv "$input_dir/tmp.md" "$input_dir/$file" + fi + + # Convert Markdown to GMI + /usr/local/bin/md2gmi -i "$input_dir/$file" -o "$output_dir/${file%.md}.gmi" + echo "Wrote file: $output_dir/${file%.md}.gmi" +done diff --git a/.github/workflows/markdown2gempost.yml b/.github/workflows/markdown2gempost.yml new file mode 100644 index 0000000..a7d6a5f --- /dev/null +++ b/.github/workflows/markdown2gempost.yml @@ -0,0 +1,32 @@ +on: + workflow_dispatch: + push: + branches: + - main + paths: + - 'markdown/**' + +concurrency: + group: md2gmi + cancel-in-progress: true + +defaults: + run: + shell: bash + +jobs: + md2gmi: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/markdown2gempost + with: + input-dir: 'markdown' + output-dir: 'gemlog' + - uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: 'convert Markdown post to Gempost' + file_pattern: 'gemlog/*.gmi gemlog/*.yaml' + diff --git a/markdown/.gitkeep b/markdown/.gitkeep new file mode 100644 index 0000000..e69de29