mirror of
https://github.com/jbowdre/capsule.git
synced 2024-11-26 14:42:19 +00:00
Compare commits
27 commits
bb60e90662
...
fa7f0b3157
Author | SHA1 | Date | |
---|---|---|---|
fa7f0b3157 | |||
|
12169e24e9 | ||
6651185bc6 | |||
f4abf7d7b8 | |||
c68026a748 | |||
|
0521ce3e3a | ||
7a68658e8e | |||
46c5d8c961 | |||
559dca65fc | |||
|
10e8fdce8e | ||
60838bfaa9 | |||
cf7ab8f039 | |||
b708e77b74 | |||
18888dbb6a | |||
d42c7bc12a | |||
|
3bfd21ab79 | ||
da8f044d60 | |||
0e33a32350 | |||
eaf0295091 | |||
f971202e1a | |||
35edc698f7 | |||
af61f3a539 | |||
|
6fd22acf34 | ||
0edff6a784 | |||
|
0b508628ac | ||
|
4af396753e | ||
54d21b2b32 |
10 changed files with 177 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"]
|
19
.github/actions/markdown2gempost/action.yml
vendored
Normal file
19
.github/actions/markdown2gempost/action.yml
vendored
Normal 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 }}
|
52
.github/actions/markdown2gempost/convert-dir.sh
vendored
Normal file
52
.github/actions/markdown2gempost/convert-dir.sh
vendored
Normal 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
35
.github/workflows/markdown2gempost.yml
vendored
Normal 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'
|
||||||
|
|
||||||
|
|
17
gemlog/echofeed-integration-test.gmi
Normal file
17
gemlog/echofeed-integration-test.gmi
Normal 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.
|
||||||
|
|
1
gemlog/echofeed-integration-test.yaml
Normal file
1
gemlog/echofeed-integration-test.yaml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
id: "urn:uuid:7826c3b3-fa43-4c55-9b7e-6b49879180ff"
|
0
markdown/.gitkeep
Normal file
0
markdown/.gitkeep
Normal file
15
markdown/echofeed-integration-test.md
Normal file
15
markdown/echofeed-integration-test.md
Normal 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.
|
0
markdown/incoming/.gitkeep
Normal file
0
markdown/incoming/.gitkeep
Normal file
15
markdown/incoming/echofeed-integration-test.md
Normal file
15
markdown/incoming/echofeed-integration-test.md
Normal 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.
|
Loading…
Reference in a new issue