mirror of
https://github.com/jbowdre/capsule.git
synced 2024-11-22 13:12:19 +00:00
fix action
This commit is contained in:
parent
35edc698f7
commit
f971202e1a
2 changed files with 37 additions and 10 deletions
41
.github/actions/markdown2gempost/convert-dir.sh
vendored
41
.github/actions/markdown2gempost/convert-dir.sh
vendored
|
@ -1,24 +1,49 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
input_dir="$1"
|
# Throw error if required paths are not provided
|
||||||
output_dir="$2"
|
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
|
# Iterate over .md files in input directory
|
||||||
for file in "$input_dir"/*.md; do
|
for file in "$input_dir"/*.md; do
|
||||||
file=$(basename "$file")
|
file=$(basename "$file")
|
||||||
echo "Processing file: $file"
|
|
||||||
|
|
||||||
# Extract frontmatter and dump it to YAML file
|
# Extract frontmatter and dump it to YAML file
|
||||||
echo "id: \"urn:uuid:$(uuidgen)\"" > "$output_dir/${file%.md}.yaml"
|
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"
|
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"
|
echo "Wrote frontmatter file: $output_dir/${file%.md}.yaml"
|
||||||
|
|
||||||
# Remove HTML tags, including those which may span multiple lines
|
# Check for HTML tags
|
||||||
if awk -v RS='^$' -v ORS='' '{gsub(/<[^>]*>/, ""); print}' "$input_dir/$file" > "$input_dir/tmp.md"; then
|
if grep -q '<[^>]*>' "$input_dir/$file"; then
|
||||||
mv "$input_dir/tmp.md" "$input_dir/$file"
|
# 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
|
fi
|
||||||
|
|
||||||
# Convert Markdown to GMI
|
# Convert Markdown to GMI
|
||||||
/usr/local/bin/md2gmi -i "$input_dir/$file" -o "$output_dir/${file%.md}.gmi"
|
/usr/local/bin/md2gmi -i "$input_dir/$file" -o "$output_dir/${file%.md}.gmi"
|
||||||
echo "Wrote file: $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
|
done
|
||||||
|
|
6
.github/workflows/markdown2gempost.yml
vendored
6
.github/workflows/markdown2gempost.yml
vendored
|
@ -1,3 +1,5 @@
|
||||||
|
name: "Markdown to Gempost"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
|
@ -23,10 +25,10 @@ jobs:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: ./.github/actions/markdown2gempost
|
- uses: ./.github/actions/markdown2gempost
|
||||||
with:
|
with:
|
||||||
input-dir: 'markdown'
|
input-dir: 'markdown/incoming'
|
||||||
output-dir: 'gemlog'
|
output-dir: 'gemlog'
|
||||||
|
processed-dir: 'markdown'
|
||||||
- uses: stefanzweifel/git-auto-commit-action@v5
|
- uses: stefanzweifel/git-auto-commit-action@v5
|
||||||
with:
|
with:
|
||||||
commit_message: 'convert Markdown post to Gempost'
|
commit_message: 'convert Markdown post to Gempost'
|
||||||
file_pattern: 'gemlog/*.gmi gemlog/*.yaml'
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue