Post date
This commit is contained in:
parent
c283c47cef
commit
ebc2de4190
@ -39,6 +39,7 @@ Copy the posting script to e.g. `/usr/local/bin/wordpress-post` so that you can
|
|||||||
* `--file PATH` — use PATH as the post content instead of opening `$EDITOR`.
|
* `--file PATH` — use PATH as the post content instead of opening `$EDITOR`.
|
||||||
* `--publish` — shortcut for `STATUS=publish`, posts live immediately.
|
* `--publish` — shortcut for `STATUS=publish`, posts live immediately.
|
||||||
* `--edit POST_ID` — update an existing post instead of creating a new one.
|
* `--edit POST_ID` — update an existing post instead of creating a new one.
|
||||||
|
* `--date DATE` — backdate the post to DATE, an ISO 8601 UTC timestamp (e.g. `2026-07-27T10:00:00Z`, matching a Gitea commit date) — sent as the post's `date_gmt`.
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
`tests/run_tests.sh` runs post.sh against a local mock of the WordPress REST
|
`tests/run_tests.sh` runs post.sh against a local mock of the WordPress REST
|
||||||
|
|||||||
13
post.sh
13
post.sh
@ -22,10 +22,14 @@ CONFIG_DIR="${WORDPRESS_REST_CURL_CONFIG_DIR:-$HOME/.config/wordpress-rest-curl}
|
|||||||
# --edit POST_ID update an existing post instead of creating a new one
|
# --edit POST_ID update an existing post instead of creating a new one
|
||||||
# --publish shortcut for STATUS=publish
|
# --publish shortcut for STATUS=publish
|
||||||
# --file PATH use PATH as the post source instead of opening $EDITOR
|
# --file PATH use PATH as the post source instead of opening $EDITOR
|
||||||
|
# --date DATE backdate the post to DATE, an ISO 8601 UTC timestamp
|
||||||
|
# (e.g. 2026-07-27T10:00:00Z, matching a Gitea commit
|
||||||
|
# date) — sent as the post's date_gmt
|
||||||
SITE=""
|
SITE=""
|
||||||
POST_ID=""
|
POST_ID=""
|
||||||
SOURCE_FILE=""
|
SOURCE_FILE=""
|
||||||
PUBLISH=0
|
PUBLISH=0
|
||||||
|
DATE=""
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--site)
|
--site)
|
||||||
@ -36,6 +40,8 @@ while [[ $# -gt 0 ]]; do
|
|||||||
PUBLISH=1; shift ;;
|
PUBLISH=1; shift ;;
|
||||||
--file)
|
--file)
|
||||||
SOURCE_FILE="$2"; shift 2 ;;
|
SOURCE_FILE="$2"; shift 2 ;;
|
||||||
|
--date)
|
||||||
|
DATE="$2"; shift 2 ;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown argument: $1" >&2
|
echo "Unknown argument: $1" >&2
|
||||||
exit 1 ;;
|
exit 1 ;;
|
||||||
@ -104,6 +110,9 @@ echo "Server: $SERVER"
|
|||||||
echo "Status: $STATUS"
|
echo "Status: $STATUS"
|
||||||
echo "Categories: $CATEGORIES"
|
echo "Categories: $CATEGORIES"
|
||||||
echo "Tags: $TAGS"
|
echo "Tags: $TAGS"
|
||||||
|
if [[ -n "$DATE" ]]; then
|
||||||
|
echo "Date: $DATE"
|
||||||
|
fi
|
||||||
if [[ -n "$POST_ID" ]]; then
|
if [[ -n "$POST_ID" ]]; then
|
||||||
echo "Editing post: $POST_ID"
|
echo "Editing post: $POST_ID"
|
||||||
fi
|
fi
|
||||||
@ -126,7 +135,9 @@ PAYLOAD=$(jq -n \
|
|||||||
--arg status "$STATUS" \
|
--arg status "$STATUS" \
|
||||||
--argjson categories "$CATEGORIES_JSON" \
|
--argjson categories "$CATEGORIES_JSON" \
|
||||||
--argjson tags "$TAGS_JSON" \
|
--argjson tags "$TAGS_JSON" \
|
||||||
'{title: $title, content: $content, status: $status, categories: $categories, tags: $tags}')
|
--arg date_gmt "${DATE%Z}" \
|
||||||
|
'{title: $title, content: $content, status: $status, categories: $categories, tags: $tags}
|
||||||
|
+ (if $date_gmt != "" then {date_gmt: $date_gmt} else {} end)')
|
||||||
|
|
||||||
BASE_URL="$SERVER"
|
BASE_URL="$SERVER"
|
||||||
[[ "$BASE_URL" != http://* && "$BASE_URL" != https://* ]] && BASE_URL="https://$BASE_URL"
|
[[ "$BASE_URL" != http://* && "$BASE_URL" != https://* ]] && BASE_URL="https://$BASE_URL"
|
||||||
|
|||||||
@ -97,6 +97,18 @@ assert_eq "trailing slash: exit code" "0" "$?"
|
|||||||
REQ=$(cat "$MOCK_WP_REQUEST_FILE")
|
REQ=$(cat "$MOCK_WP_REQUEST_FILE")
|
||||||
assert_eq "trailing slash: path has no double slash" "/wp-json/wp/v2/posts/" "$(jq -r '.path' <<<"$REQ")"
|
assert_eq "trailing slash: path has no double slash" "/wp-json/wp/v2/posts/" "$(jq -r '.path' <<<"$REQ")"
|
||||||
|
|
||||||
|
# --- --date backdates the post via date_gmt ---
|
||||||
|
rm -f "$MOCK_WP_REQUEST_FILE" "$MOCK_WP_CONTROL_FILE"
|
||||||
|
run_post_sh --file "$POST_FILE" --date "2026-07-27T10:00:00Z" >/dev/null
|
||||||
|
assert_eq "date: exit code" "0" "$?"
|
||||||
|
REQ=$(cat "$MOCK_WP_REQUEST_FILE")
|
||||||
|
assert_eq "date: date_gmt sent, trailing Z stripped" "2026-07-27T10:00:00" "$(jq -r '.payload.date_gmt' <<<"$REQ")"
|
||||||
|
|
||||||
|
rm -f "$MOCK_WP_REQUEST_FILE" "$MOCK_WP_CONTROL_FILE"
|
||||||
|
run_post_sh --file "$POST_FILE" >/dev/null
|
||||||
|
REQ=$(cat "$MOCK_WP_REQUEST_FILE")
|
||||||
|
assert_eq "no date: date_gmt omitted" "true" "$(jq -r '.payload | has("date_gmt") | not' <<<"$REQ")"
|
||||||
|
|
||||||
# --- edit an existing post ---
|
# --- edit an existing post ---
|
||||||
rm -f "$MOCK_WP_REQUEST_FILE" "$MOCK_WP_CONTROL_FILE"
|
rm -f "$MOCK_WP_REQUEST_FILE" "$MOCK_WP_CONTROL_FILE"
|
||||||
run_post_sh --file "$POST_FILE" --edit 99 >/dev/null
|
run_post_sh --file "$POST_FILE" --edit 99 >/dev/null
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user