Compare commits

...

27 commits

Author SHA1 Message Date
fa7f0b3157 New entry via EchoFeed 2024-04-13 18:03:33 -05:00
jbowdre
12169e24e9 convert Markdown post to Gempost 2024-04-13 22:12:01 +00:00
6651185bc6 New entry via EchoFeed 2024-04-13 17:11:29 -05:00
f4abf7d7b8 cleanup 2024-04-13 17:07:02 -05:00
c68026a748 remove empty/trailing spaces 2024-04-13 17:06:19 -05:00
jbowdre
0521ce3e3a convert Markdown post to Gempost 2024-04-13 21:47:46 +00:00
7a68658e8e New entry via EchoFeed 2024-04-13 16:47:13 -05:00
46c5d8c961 cleanup 2024-04-13 16:45:07 -05:00
559dca65fc assign PAT to checkout action 2024-04-13 16:45:03 -05:00
jbowdre
10e8fdce8e convert Markdown post to Gempost 2024-04-13 21:37:51 +00:00
60838bfaa9 New entry via EchoFeed 2024-04-13 16:37:17 -05:00
cf7ab8f039 use PAT for auto-commit 2024-04-13 16:28:38 -05:00
b708e77b74 cleanup 2024-04-13 16:15:56 -05:00
18888dbb6a Merge branch 'main' of github.com:jbowdre/capsule 2024-04-13 16:15:24 -05:00
d42c7bc12a fix missing input on action 2024-04-13 16:15:15 -05:00
jbowdre
3bfd21ab79 convert Markdown post to Gempost 2024-04-13 21:11:39 +00:00
da8f044d60 add processed-dir arg to action 2024-04-13 16:10:47 -05:00
0e33a32350 new test post 2024-04-13 16:08:37 -05:00
eaf0295091 new folder for incoming markdown 2024-04-13 16:08:03 -05:00
f971202e1a fix action 2024-04-13 16:07:22 -05:00
35edc698f7 cleanup 2024-04-13 15:40:14 -05:00
af61f3a539 testing cleanup 2024-04-13 15:27:51 -05:00
jbowdre
6fd22acf34 convert Markdown post to Gempost 2024-04-13 20:20:58 +00:00
0edff6a784 New entry via EchoFeed 2024-04-13 15:20:24 -05:00
jbowdre
0b508628ac convert Markdown post to Gempost 2024-04-13 20:15:55 +00:00
John Bowdre
4af396753e
Merge pull request #1 from jbowdre/echofeed
add action to convert markdown posts to gempost
2024-04-13 15:15:19 -05:00
54d21b2b32 add action to convert markdown posts to gempost 2024-04-13 15:11:41 -05:00
10 changed files with 177 additions and 0 deletions

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

View file

@ -0,0 +1,19 @@
name: 'Convert Markdown to Gempost'
description: 'Convert Markdown posts to Gemtext 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
processed-dir:
description: 'The directory to move processed markdown files to'
required: true
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.input-dir }}
- ${{ inputs.output-dir }}
- ${{ inputs.processed-dir }}

View file

@ -0,0 +1,52 @@
#!/usr/bin/env bash
# Throw error if required paths are not provided
if [ $# -ne 3 ]; then
echo "Usage: $0 <input_dir> <output_dir> <processed_dir>"
exit 1
fi
# strip trailing slashes from input and output directories
input_dir="${1%/}"
output_dir="${2%/}"
processed_dir="${3%/}"
# Find all .md files and check if the array is empty
mapfile -t md_files < <(find "$input_dir" -type f -name "*.md")
if [ ${#md_files[@]} -eq 0 ]; then
echo "No Markdown files to process."
exit 0
fi
# Iterate over .md files in input directory
for file in "$input_dir"/*.md; do
file=$(basename "$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 file: $output_dir/${file%.md}.yaml"
# Check for HTML tags
if grep -q '<[^>]*>' "$input_dir/$file"; then
# 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
fi
# Remove empty/trailing spaces
sed -i 's/[ \t]*$//' "$input_dir/$file"
# Convert Markdown to GMI
/usr/local/bin/md2gmi -i "$input_dir/$file" -o "$output_dir/${file%.md}.gmi"
# Remove first line (and blank lines which follow) from output file (gempost will render the title)
if awk 'NR == 1 {next} NF == 0 && !p {next} {p=1; print}' "$output_dir/${file%.md}.gmi" > "$output_dir/tmp.gmi"; then
mv "$output_dir/tmp.gmi" "$output_dir/${file%.md}.gmi"
fi
echo "Wrote gemtext file: $output_dir/${file%.md}.gmi"
# Move original Markdown file to processed directory
mv "$input_dir/$file" "$processed_dir/$file"
done

35
.github/workflows/markdown2gempost.yml vendored Normal file
View file

@ -0,0 +1,35 @@
name: "Markdown to Gempost"
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
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.MY_GH_TOKEN }}
- uses: ./.github/actions/markdown2gempost
with:
input-dir: 'markdown/incoming'
output-dir: 'gemlog'
processed-dir: 'markdown'
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: 'convert Markdown post to Gempost'

View file

@ -0,0 +1,17 @@
This is a quick post to see if this absolute nonsense[1] I have cobbled together actually works.
=> https://github.com/jbowdre/capsule/blob/main/.github/workflows/markdown2gempost.yml 1: absolute nonsense
If it works:
- EchoFeed[1] will see this post in my Scribbles RSS feed, and relay it to my GitHub repo as a Markdown file.
=> https://echofeed.app/ 1: EchoFeed
- My new GitHub Actions workflow will see the new Markdown file, use a script and md2gmi[1] in a Docker container to convert the Markdown to Gemtext along with a YAML metadata sidecar for gempost, and store the results in the repo.
- The existing workflow will see the new gemtext post and use gempost[2] to (re)build the site, and then deploy it to my virtual server where it will be made available within Geminispace.
=> https://github.com/n0x1m/md2gmi 1: md2gmi
=> https://github.com/justlark/gempost 2: gempost
I really hope this works.

View file

@ -0,0 +1 @@
id: "urn:uuid:7826c3b3-fa43-4c55-9b7e-6b49879180ff"

0
markdown/.gitkeep Normal file
View file

View file

@ -0,0 +1,15 @@
---
title: "Echofeed Integration Test"
published: "2024-04-13T22:11:06.000000Z"
updated: "2024-04-13T22:11:06.000000Z"
---
This is a quick post to see if this [absolute nonsense](https://github.com/jbowdre/capsule/blob/main/.github/workflows/markdown2gempost.yml) I have cobbled together actually works.
If it works:
- [EchoFeed](https://echofeed.app/) will see this post in my Scribbles RSS feed, and relay it to my GitHub repo as a Markdown file.
- My new GitHub Actions workflow will see the new Markdown file, use a script and [md2gmi](https://github.com/n0x1m/md2gmi) in a Docker container to convert the Markdown to Gemtext along with a YAML metadata sidecar for gempost, and store the results in the repo.
- The existing workflow will see the new gemtext post and use [gempost](https://github.com/justlark/gempost) to (re)build the site, and then deploy it to my virtual server where it will be made available within Geminispace.
I really hope this works.

View file

View file

@ -0,0 +1,15 @@
---
title: "Echofeed Integration Test"
published: "2024-04-13T23:01:36.000000Z"
updated: "2024-04-13T23:01:36.000000Z"
---
This is a quick post to see if this [absolute nonsense](https://github.com/jbowdre/capsule/blob/main/.github/workflows/markdown2gempost.yml) I have cobbled together actually works.
If it works:
- [EchoFeed](https://echofeed.app/) will see this post in my Scribbles RSS feed, and relay it to my GitHub repo as a Markdown file.
- My new GitHub Actions workflow will see the new Markdown file, use a script and [md2gmi](https://github.com/n0x1m/md2gmi) in a Docker container to convert the Markdown to Gemtext along with a YAML metadata sidecar for gempost, and store the results in the repo.
- The existing workflow will see the new gemtext post and use [gempost](https://github.com/justlark/gempost) to (re)build the site, and then deploy it to my virtual server where it will be made available within Geminispace.
I really hope this works.