News for hackers. Stuff that matters.
Re:How to Build a Composable Blog by malkosta on Thursday April 14, 2022 @08:03PM (#31035084)
Here is my composable blog with cURL and awk

#!/bin/sh

process() {

  output="${1%.*}".html

  # Convert markdown to html and save
  curl \
    -sS \
    -u "${GITHUB_USERNAME}:${GITHUB_TOKEN}" \
    -X POST \
    -H "Content-Type: text/plain" -H "Accept: application/vnd.github.v3+json" \
    https://api.github.com/markdown/raw \
    --data "$(cat $1)" > $output

  # Apply layout and save
  html=$(awk 'NR==FNR { a[n++]=$0; next } /{{ content }}/ { for (i=0;i<n;++i) print a[i]; next } 1' $output layout.html)
  printf "%s" "$html" > "$output"

  echo "Processed ${output}"
}

for file in *.md; do process "$file" & done wait

There are no comments on this comment yet.