add scripts/show_drafts and scripts/scheduled for listing unpublished blog posts

This commit is contained in:
Firehose Bot 2026-05-13 21:48:32 +01:00
parent 061787e897
commit b2d3bdef19
2 changed files with 75 additions and 0 deletions

42
scripts/scheduled Executable file
View File

@ -0,0 +1,42 @@
#!/usr/bin/env bash
# Show all blog post files that are scheduled (published: true, future-dated).
# Usage: scripts/scheduled (from repo root)
set -euo pipefail
# Resolve repo root: scripts/ is one level below the repo root
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
BLOG_DIR="$REPO_ROOT/app/priv/blog"
if [ ! -d "$BLOG_DIR" ]; then
echo "Error: blog directory not found at $BLOG_DIR" >&2
exit 1
fi
# Get today's date as YYYY-MM-DD for comparison
TODAY=$(date +%Y-%m-%d)
found=0
while IFS= read -r -d '' file; do
# Extract frontmatter (between first line and first ---)
frontmatter=$(sed -n '1,/^---$/p' "$file" | sed '$d')
# Skip drafts (published: false)
if echo "$frontmatter" | grep -q 'published: *false'; then
continue
fi
# Extract year from the path: .../blog/<blog>/YYYY/...
year=$(echo "$file" | sed -n 's|.*/blog/[^/]*/\([0-9]\{4\}\)/.*|\1|p')
if [ -n "$year" ] && [ "$year" -gt "$(date +%Y)" ] 2>/dev/null; then
echo "$file"
found=$((found + 1))
fi
done < <(find "$BLOG_DIR" -name '*.md' -type f -print0 | sort -z)
if [ "$found" -eq 0 ]; then
echo "(no scheduled posts found)"
fi

33
scripts/show_drafts Executable file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env bash
# Show all blog post files that are drafts (published: false in frontmatter).
# Usage: make show-drafts (from repo root)
set -euo pipefail
# Resolve repo root: script/ is one level below the repo root
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
BLOG_DIR="$REPO_ROOT/app/priv/blog"
if [ ! -d "$BLOG_DIR" ]; then
echo "Error: blog directory not found at $BLOG_DIR" >&2
exit 1
fi
# Find .md files with frontmatter containing published: false
# Uses a multi-line grep approach: find files where the frontmatter block
# (between first --- markers) contains published: false
found=0
while IFS= read -r -d '' file; do
# Extract frontmatter (between first line and first ---)
frontmatter=$(sed -n '1,/^---$/p' "$file" | sed '$d')
if echo "$frontmatter" | grep -q 'published: *false'; then
echo "$file"
found=$((found + 1))
fi
done < <(find "$BLOG_DIR" -name '*.md' -type f -print0 | sort -z)
if [ "$found" -eq 0 ]; then
echo "(no drafts found)"
fi