diff --git a/scripts/scheduled b/scripts/scheduled new file mode 100755 index 0000000..d587402 --- /dev/null +++ b/scripts/scheduled @@ -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//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 diff --git a/scripts/show_drafts b/scripts/show_drafts new file mode 100755 index 0000000..7b8d2e2 --- /dev/null +++ b/scripts/show_drafts @@ -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