mirror of
https://github.com/jbowdre/capsule.git
synced 2024-11-09 16:32:18 +00:00
add action to convert markdown posts to gempost
This commit is contained in:
parent
bb60e90662
commit
54d21b2b32
5 changed files with 94 additions and 0 deletions
23
.github/actions/markdown2gempost/Dockerfile
vendored
Normal file
23
.github/actions/markdown2gempost/Dockerfile
vendored
Normal file
|
@ -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"]
|
15
.github/actions/markdown2gempost/action.yml
vendored
Normal file
15
.github/actions/markdown2gempost/action.yml
vendored
Normal file
|
@ -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 }}
|
24
.github/actions/markdown2gempost/convert-dir.sh
vendored
Normal file
24
.github/actions/markdown2gempost/convert-dir.sh
vendored
Normal file
|
@ -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
|
32
.github/workflows/markdown2gempost.yml
vendored
Normal file
32
.github/workflows/markdown2gempost.yml
vendored
Normal file
|
@ -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'
|
||||||
|
|
0
markdown/.gitkeep
Normal file
0
markdown/.gitkeep
Normal file
Loading…
Reference in a new issue