Skip to content

Commit 7a7461e

Browse files
authored
feat(detect): add target_date input for specifying which date to search (#4)
Adds optional target_date input to detect-new-blog-post workflow. When provided, searches for posts matching that date instead of the current date. Defaults to current date if not specified.
1 parent 6c67897 commit 7a7461e

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

.github/workflows/detect-new-blog-post.yml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ on:
3131
required: false
3232
type: string
3333
default: 'categories'
34+
target_date:
35+
description: 'Date to look for posts (YYYY-MM-DD format). Defaults to current date.'
36+
required: false
37+
type: string
3438
outputs:
3539
has_new_post:
3640
description: 'Whether a new post was detected'
@@ -70,8 +74,14 @@ jobs:
7074
- name: Detect new blog post
7175
id: check
7276
run: |
73-
TODAY=$(date -u +"%Y-%m-%d")
74-
echo "Today's date: $TODAY"
77+
# Use target_date if provided, otherwise default to current date
78+
if [ -n "${{ inputs.target_date }}" ]; then
79+
TARGET_DATE="${{ inputs.target_date }}"
80+
echo "Using provided target date: $TARGET_DATE"
81+
else
82+
TARGET_DATE=$(date -u +"%Y-%m-%d")
83+
echo "Using current date: $TARGET_DATE"
84+
fi
7585
7686
CONTENT_PATH="${{ inputs.content_path }}"
7787
POST_FILENAME="${{ inputs.post_filename }}"
@@ -81,7 +91,7 @@ jobs:
8191
CATEGORIES_FIELD="${{ inputs.categories_field }}"
8292
8393
if [ "$EVENT_NAME" == "push" ]; then
84-
echo "=== Push event: checking for new posts dated today or earlier ==="
94+
echo "=== Push event: checking for new posts dated $TARGET_DATE or earlier ==="
8595
8696
# Get list of added files in this push
8797
ADDED_FILES=$(git diff --name-only --diff-filter=A HEAD~1 HEAD)
@@ -105,29 +115,29 @@ jobs:
105115
echo "Post date: $POST_DATE"
106116
107117
# Compare dates - skip if future dated
108-
if [[ "$POST_DATE" > "$TODAY" ]]; then
109-
echo "Post is future-dated ($POST_DATE > $TODAY), skipping"
118+
if [[ "$POST_DATE" > "$TARGET_DATE" ]]; then
119+
echo "Post is future-dated ($POST_DATE > $TARGET_DATE), skipping"
110120
echo "has_new_post=false" >> $GITHUB_OUTPUT
111121
exit 0
112122
fi
113123
114124
else
115-
echo "=== Scheduled/manual event: checking for posts dated today ==="
125+
echo "=== Scheduled/manual event: checking for posts dated $TARGET_DATE ==="
116126
117-
# Find all blog posts and check for ones dated today
127+
# Find all blog posts and check for ones matching target date
118128
NEW_POST=""
119129
for POST_FILE in $(find "$CONTENT_PATH" -name "$POST_FILENAME" 2>/dev/null); do
120130
POST_DATE=$(sed -n '/^---$/,/^---$/p' "$POST_FILE" | grep -E '^date:' | sed 's/^date:[[:space:]]*//' | sed 's/["\x27]//g' | cut -dT -f1)
121131
122-
if [ "$POST_DATE" == "$TODAY" ]; then
123-
echo "Found post dated today: $POST_FILE"
132+
if [ "$POST_DATE" == "$TARGET_DATE" ]; then
133+
echo "Found post dated $TARGET_DATE: $POST_FILE"
124134
NEW_POST="$POST_FILE"
125135
break
126136
fi
127137
done
128138
129139
if [ -z "$NEW_POST" ]; then
130-
echo "No posts dated today found"
140+
echo "No posts dated $TARGET_DATE found"
131141
echo "has_new_post=false" >> $GITHUB_OUTPUT
132142
exit 0
133143
fi

0 commit comments

Comments
 (0)