|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Generate a markdown changelog for WordPress hooks |
| 4 | +# Lists new actions, new filters, and parameter changes for specified versions |
| 5 | + |
| 6 | +ACTIONS_FILE="hooks/actions.json" |
| 7 | +FILTERS_FILE="hooks/filters.json" |
| 8 | +OUTPUT_FILE="CHANGELOG.md" |
| 9 | + |
| 10 | +# Extract all versions from both files and sort them in descending order |
| 11 | +VERSIONS=($(jq -r ' |
| 12 | + [.hooks[].doc.tags[] | select(.name == "since") | .content] |
| 13 | + | unique |
| 14 | + | map(select(test("^[0-9]+\\.[0-9]+\\.?[0-9]*$"))) |
| 15 | + | map(split(".")[0:2] | join(".")) |
| 16 | + | unique |
| 17 | + | .[] |
| 18 | +' "$ACTIONS_FILE" "$FILTERS_FILE" | sort -u | while read v; do |
| 19 | + # Convert to sortable format and print |
| 20 | + major=$(echo "$v" | cut -d. -f1) |
| 21 | + minor=$(echo "$v" | cut -d. -f2) |
| 22 | + printf "%03d.%03d %s\n" "$major" "$minor" "$v" |
| 23 | +done | sort -rn | cut -d' ' -f2)) |
| 24 | + |
| 25 | +echo "# WordPress Hooks Changelog" > "$OUTPUT_FILE" |
| 26 | +echo "" >> "$OUTPUT_FILE" |
| 27 | +echo "This document lists new actions, new filters, and parameter changes by WordPress version." >> "$OUTPUT_FILE" |
| 28 | +echo "" >> "$OUTPUT_FILE" |
| 29 | + |
| 30 | +for VERSION in "${VERSIONS[@]}"; do |
| 31 | + echo "Processing version $VERSION..." |
| 32 | + |
| 33 | + echo "## WordPress $VERSION" >> "$OUTPUT_FILE" |
| 34 | + echo "" >> "$OUTPUT_FILE" |
| 35 | + |
| 36 | + # Find new actions (first @since tag matches the version) |
| 37 | + echo "### New Actions" >> "$OUTPUT_FILE" |
| 38 | + echo "" >> "$OUTPUT_FILE" |
| 39 | + |
| 40 | + NEW_ACTIONS=$(jq -r --arg ver "${VERSION}" ' |
| 41 | + # Function to convert hook name to URL slug |
| 42 | + def slug: gsub("\\{\\$"; "") | gsub("\\}"; "") | gsub("\\$"; "") | gsub("->"; "-") | gsub("<"; "") | gsub(">"; ""); |
| 43 | + .hooks[] |
| 44 | + | select( |
| 45 | + .doc.tags |
| 46 | + | map(select(.name == "since")) |
| 47 | + | .[0].content |
| 48 | + | startswith($ver) |
| 49 | + ) |
| 50 | + | . as $hook |
| 51 | + | ($hook.doc.tags | map(select(.name == "since")) | .[0].content) as $since |
| 52 | + | ($hook.name | slug) as $url_slug |
| 53 | + | if ($since | test("^[0-9]+\\.[0-9]+\\.[1-9]")) then |
| 54 | + "- [`\($hook.name)`](https://developer.wordpress.org/reference/hooks/\($url_slug)/) (\($since)) - \($hook.doc.description)" |
| 55 | + else |
| 56 | + "- [`\($hook.name)`](https://developer.wordpress.org/reference/hooks/\($url_slug)/) - \($hook.doc.description)" |
| 57 | + end |
| 58 | + ' "$ACTIONS_FILE") |
| 59 | + |
| 60 | + if [ -n "$NEW_ACTIONS" ]; then |
| 61 | + echo "$NEW_ACTIONS" >> "$OUTPUT_FILE" |
| 62 | + else |
| 63 | + echo "_No new actions in this version._" >> "$OUTPUT_FILE" |
| 64 | + fi |
| 65 | + |
| 66 | + echo "" >> "$OUTPUT_FILE" |
| 67 | + |
| 68 | + # Find new filters (first @since tag matches the version) |
| 69 | + echo "### New Filters" >> "$OUTPUT_FILE" |
| 70 | + echo "" >> "$OUTPUT_FILE" |
| 71 | + |
| 72 | + NEW_FILTERS=$(jq -r --arg ver "${VERSION}" ' |
| 73 | + # Function to convert hook name to URL slug |
| 74 | + def slug: gsub("\\{\\$"; "") | gsub("\\}"; "") | gsub("\\$"; "") | gsub("->"; "-") | gsub("<"; "") | gsub(">"; ""); |
| 75 | + .hooks[] |
| 76 | + | select( |
| 77 | + .doc.tags |
| 78 | + | map(select(.name == "since")) |
| 79 | + | .[0].content |
| 80 | + | startswith($ver) |
| 81 | + ) |
| 82 | + | . as $hook |
| 83 | + | ($hook.doc.tags | map(select(.name == "since")) | .[0].content) as $since |
| 84 | + | ($hook.name | slug) as $url_slug |
| 85 | + | if ($since | test("^[0-9]+\\.[0-9]+\\.[1-9]")) then |
| 86 | + "- [`\($hook.name)`](https://developer.wordpress.org/reference/hooks/\($url_slug)/) (\($since)) - \($hook.doc.description)" |
| 87 | + else |
| 88 | + "- [`\($hook.name)`](https://developer.wordpress.org/reference/hooks/\($url_slug)/) - \($hook.doc.description)" |
| 89 | + end |
| 90 | + ' "$FILTERS_FILE") |
| 91 | + |
| 92 | + if [ -n "$NEW_FILTERS" ]; then |
| 93 | + echo "$NEW_FILTERS" >> "$OUTPUT_FILE" |
| 94 | + else |
| 95 | + echo "_No new filters in this version._" >> "$OUTPUT_FILE" |
| 96 | + fi |
| 97 | + |
| 98 | + echo "" >> "$OUTPUT_FILE" |
| 99 | + |
| 100 | + # Find changes from both actions and filters |
| 101 | + echo "### Changes" >> "$OUTPUT_FILE" |
| 102 | + echo "" >> "$OUTPUT_FILE" |
| 103 | + |
| 104 | + ACTION_PARAM_CHANGES=$(jq -r --arg ver "${VERSION}" ' |
| 105 | + # Function to convert hook name to URL slug |
| 106 | + def slug: gsub("\\{\\$"; "") | gsub("\\}"; "") | gsub("\\$"; "") | gsub("->"; "-") | gsub("<"; "") | gsub(">"; ""); |
| 107 | + # Function to wrap $param style strings in <code> tags if not already wrapped |
| 108 | + def format_params: gsub("(?<p>\\$[a-z_]+)"; "<code>\(.p)</code>") | gsub("<code><code>"; "<code>") | gsub("</code></code>"; "</code>"); |
| 109 | + .hooks[] |
| 110 | + | select( |
| 111 | + .doc.tags |
| 112 | + | any(.name == "since" and .description != null and (.content | startswith($ver))) |
| 113 | + ) |
| 114 | + | . as $hook |
| 115 | + | ($hook.name | slug) as $url_slug |
| 116 | + | .doc.tags |
| 117 | + | map(select(.name == "since" and .description != null and (.content | startswith($ver)))) |
| 118 | + | map( |
| 119 | + (.description | format_params) as $desc |
| 120 | + | if (.content | test("^[0-9]+\\.[0-9]+\\.[1-9]")) then |
| 121 | + "- [`\($hook.name)`](https://developer.wordpress.org/reference/hooks/\($url_slug)/) (\(.content)) - \($desc)" |
| 122 | + else |
| 123 | + "- [`\($hook.name)`](https://developer.wordpress.org/reference/hooks/\($url_slug)/) - \($desc)" |
| 124 | + end |
| 125 | + ) |
| 126 | + | .[] |
| 127 | + ' "$ACTIONS_FILE") |
| 128 | + |
| 129 | + FILTER_PARAM_CHANGES=$(jq -r --arg ver "${VERSION}" ' |
| 130 | + # Function to convert hook name to URL slug |
| 131 | + def slug: gsub("\\{\\$"; "") | gsub("\\}"; "") | gsub("\\$"; "") | gsub("->"; "-") | gsub("<"; "") | gsub(">"; ""); |
| 132 | + # Function to wrap $param style strings in <code> tags if not already wrapped |
| 133 | + def format_params: gsub("(?<p>\\$[a-z_]+)"; "<code>\(.p)</code>") | gsub("<code><code>"; "<code>") | gsub("</code></code>"; "</code>"); |
| 134 | + .hooks[] |
| 135 | + | select( |
| 136 | + .doc.tags |
| 137 | + | any(.name == "since" and .description != null and (.content | startswith($ver))) |
| 138 | + ) |
| 139 | + | . as $hook |
| 140 | + | ($hook.name | slug) as $url_slug |
| 141 | + | .doc.tags |
| 142 | + | map(select(.name == "since" and .description != null and (.content | startswith($ver)))) |
| 143 | + | map( |
| 144 | + (.description | format_params) as $desc |
| 145 | + | if (.content | test("^[0-9]+\\.[0-9]+\\.[1-9]")) then |
| 146 | + "- [`\($hook.name)`](https://developer.wordpress.org/reference/hooks/\($url_slug)/) (\(.content)) - \($desc)" |
| 147 | + else |
| 148 | + "- [`\($hook.name)`](https://developer.wordpress.org/reference/hooks/\($url_slug)/) - \($desc)" |
| 149 | + end |
| 150 | + ) |
| 151 | + | .[] |
| 152 | + ' "$FILTERS_FILE") |
| 153 | + |
| 154 | + PARAM_CHANGES=$(echo -e "${ACTION_PARAM_CHANGES}\n${FILTER_PARAM_CHANGES}" | grep -v '^$' | sort) |
| 155 | + |
| 156 | + if [ -n "$PARAM_CHANGES" ]; then |
| 157 | + echo "$PARAM_CHANGES" >> "$OUTPUT_FILE" |
| 158 | + else |
| 159 | + echo "_No changes in this version._" >> "$OUTPUT_FILE" |
| 160 | + fi |
| 161 | + |
| 162 | + echo "" >> "$OUTPUT_FILE" |
| 163 | +done |
| 164 | + |
| 165 | +echo "Generated $OUTPUT_FILE" |
0 commit comments