|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Configuration |
| 4 | +CHANGELOG_FILE="docs/cloud/reference/01_changelog/01_changelog.md" |
| 5 | +OUTPUT_FILE="static/cloud/changelog-rss.xml" |
| 6 | +FEED_URL="https://clickhouse.com/docs/cloud/changelog-rss.xml" |
| 7 | +SITE_URL="https://clickhouse.com/docs/cloud/whats-new/cloud" |
| 8 | + |
| 9 | +# XML escape function |
| 10 | +escape_xml() { |
| 11 | + echo "$1" | sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'\''/\'/g' |
| 12 | +} |
| 13 | + |
| 14 | +# Convert date to RFC822 format |
| 15 | +date_to_rfc822() { |
| 16 | + local date_str="$1" |
| 17 | + date -d "$date_str" -R 2>/dev/null || date -j -f "%B %d, %Y" "$date_str" "+%a, %d %b %Y 00:00:00 %z" 2>/dev/null |
| 18 | +} |
| 19 | + |
| 20 | +# Remove markdown formatting |
| 21 | +clean_markdown() { |
| 22 | + local text="$1" |
| 23 | + echo "$text" | perl -pe ' |
| 24 | + s/\[([^\]]+)\]\([^\)]+\)/$1/g; |
| 25 | + s/`([^`]+)`/$1/g; |
| 26 | + s/\*\*([^\*]+)\*\*/$1/g; |
| 27 | + s/\*([^\*]+)\*/$1/g; |
| 28 | + s/_{2}([^_]+)_{2}/$1/g; |
| 29 | + s/_([^_]+)_/$1/g; |
| 30 | + ' |
| 31 | +} |
| 32 | + |
| 33 | +# Extract features from content as plain text |
| 34 | +extract_features() { |
| 35 | + local content="$1" |
| 36 | + local output="" |
| 37 | + local current_section="" |
| 38 | + |
| 39 | + while IFS= read -r line; do |
| 40 | + # Match section headers: ### Section Name |
| 41 | + if [[ "$line" =~ ^###[[:space:]]+(.+) ]]; then |
| 42 | + section="${BASH_REMATCH[1]}" |
| 43 | + section=$(echo "$section" | sed 's/ {#[^}]*}$//') |
| 44 | + section=$(clean_markdown "$section") |
| 45 | + |
| 46 | + if [ -n "$current_section" ]; then |
| 47 | + output="${output}\n" |
| 48 | + fi |
| 49 | + current_section="$section" |
| 50 | + output="${output}${section}:\n" |
| 51 | + |
| 52 | + # Match bold bullet points: - **Title** description |
| 53 | + elif [[ "$line" =~ ^[[:space:]]*[-*][[:space:]]+\*\*([^*]+)\*\*[[:space:]]*(.*) ]]; then |
| 54 | + title="${BASH_REMATCH[1]}" |
| 55 | + desc="${BASH_REMATCH[2]}" |
| 56 | + |
| 57 | + desc=$(clean_markdown "$desc" | tr '\n' ' ' | sed 's/ */ /g' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') |
| 58 | + |
| 59 | + if [ -n "$title" ]; then |
| 60 | + if [ -n "$desc" ]; then |
| 61 | + output="${output}- ${title}: ${desc}\n" |
| 62 | + else |
| 63 | + output="${output}- ${title}\n" |
| 64 | + fi |
| 65 | + fi |
| 66 | + |
| 67 | + # Match simple bullets |
| 68 | + elif [[ "$line" =~ ^[[:space:]]*[-*][[:space:]]+([^*].+) ]]; then |
| 69 | + bullet="${BASH_REMATCH[1]}" |
| 70 | + bullet=$(clean_markdown "$bullet" | tr '\n' ' ' | sed 's/ */ /g' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') |
| 71 | + |
| 72 | + if [ ${#bullet} -gt 3 ]; then |
| 73 | + output="${output}- ${bullet}\n" |
| 74 | + fi |
| 75 | + fi |
| 76 | + done <<< "$content" |
| 77 | + |
| 78 | + if [ -n "$output" ]; then |
| 79 | + echo -e "$output" |
| 80 | + else |
| 81 | + echo "See full changelog for details." |
| 82 | + fi |
| 83 | +} |
| 84 | + |
| 85 | +# Generate RSS feed |
| 86 | +generate_rss() { |
| 87 | + local entries="$1" |
| 88 | + |
| 89 | + cat > "$OUTPUT_FILE" << EOF |
| 90 | +<?xml version="1.0" encoding="UTF-8" ?> |
| 91 | +<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> |
| 92 | + <channel> |
| 93 | + <title>ClickHouse Cloud Changelog</title> |
| 94 | + <link>${SITE_URL}</link> |
| 95 | + <description>Latest updates and features in ClickHouse Cloud</description> |
| 96 | + <language>en-us</language> |
| 97 | + <lastBuildDate>$(date -R 2>/dev/null || date "+%a, %d %b %Y %H:%M:%S %z")</lastBuildDate> |
| 98 | + <atom:link href="${FEED_URL}" rel="self" type="application/rss+xml" /> |
| 99 | +${entries} |
| 100 | + </channel> |
| 101 | +</rss> |
| 102 | +EOF |
| 103 | +} |
| 104 | + |
| 105 | +# Main processing |
| 106 | +main() { |
| 107 | + if ! command -v perl &> /dev/null; then |
| 108 | + echo "Error: perl is required but not installed." |
| 109 | + exit 1 |
| 110 | + fi |
| 111 | + |
| 112 | + if [ ! -f "$CHANGELOG_FILE" ]; then |
| 113 | + echo "Error: Changelog file not found: $CHANGELOG_FILE" |
| 114 | + exit 1 |
| 115 | + fi |
| 116 | + |
| 117 | + echo "Parsing changelog: $CHANGELOG_FILE" |
| 118 | + |
| 119 | + local items="" |
| 120 | + local count=0 |
| 121 | + local in_release=0 |
| 122 | + local current_title="" |
| 123 | + local current_slug="" |
| 124 | + local current_date="" |
| 125 | + local current_content="" |
| 126 | + |
| 127 | + while IFS= read -r line; do |
| 128 | + if [[ "$line" =~ ^##[[:space:]]+(.+)[[:space:]]+\{#([^}]+)\} ]]; then |
| 129 | + if [ $in_release -eq 1 ]; then |
| 130 | + description=$(extract_features "$current_content") |
| 131 | + description=$(escape_xml "$description") |
| 132 | + rfc_date=$(date_to_rfc822 "$current_date") |
| 133 | + |
| 134 | + items="${items} <item> |
| 135 | + <title>$(escape_xml "ClickHouse Cloud - $current_title")</title> |
| 136 | + <link>${SITE_URL}#${current_slug}</link> |
| 137 | + <description>${description}</description> |
| 138 | + <pubDate>${rfc_date}</pubDate> |
| 139 | + <guid isPermaLink=\"true\">${SITE_URL}#${current_slug}</guid> |
| 140 | + </item> |
| 141 | +" |
| 142 | + ((count++)) |
| 143 | + fi |
| 144 | + |
| 145 | + current_title="${BASH_REMATCH[1]}" |
| 146 | + current_slug="${BASH_REMATCH[2]}" |
| 147 | + current_date="$current_title" |
| 148 | + current_content="" |
| 149 | + in_release=1 |
| 150 | + |
| 151 | + elif [ $in_release -eq 1 ]; then |
| 152 | + current_content="${current_content}${line}"$'\n' |
| 153 | + fi |
| 154 | + |
| 155 | + done < "$CHANGELOG_FILE" |
| 156 | + |
| 157 | + if [ $in_release -eq 1 ]; then |
| 158 | + description=$(extract_features "$current_content") |
| 159 | + description=$(escape_xml "$description") |
| 160 | + rfc_date=$(date_to_rfc822 "$current_date") |
| 161 | + |
| 162 | + items="${items} <item> |
| 163 | + <title>$(escape_xml "ClickHouse Cloud - $current_title")</title> |
| 164 | + <link>${SITE_URL}#${current_slug}</link> |
| 165 | + <description>${description}</description> |
| 166 | + <pubDate>${rfc_date}</pubDate> |
| 167 | + <guid isPermaLink=\"true\">${SITE_URL}#${current_slug}</guid> |
| 168 | + </item> |
| 169 | +" |
| 170 | + fi |
| 171 | + |
| 172 | + echo "Generated $count entries" |
| 173 | + |
| 174 | + mkdir -p "$(dirname "$OUTPUT_FILE")" |
| 175 | + |
| 176 | + generate_rss "$items" |
| 177 | + |
| 178 | + echo "RSS feed written to $OUTPUT_FILE" |
| 179 | + echo "Feed will be available at: ${FEED_URL}" |
| 180 | +} |
| 181 | + |
| 182 | +main |
0 commit comments