|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +function generateReleaseNotesUrl(name) { |
| 4 | + // Match "Python X.Y.Z[aN]" |
| 5 | + const match = name.match(/^Python (\d+)\.(\d+)\.(\d+)((?:a|b|rc)\d*)?$/); |
| 6 | + if (!match) { |
| 7 | + return ''; |
| 8 | + } |
| 9 | + |
| 10 | + const major = match[1]; |
| 11 | + const minor = match[2]; |
| 12 | + const patch = match[3]; |
| 13 | + const prerelease = match[4]; // e.g., "a2", "b1", "rc1" or undefined |
| 14 | + |
| 15 | + if (prerelease) { |
| 16 | + // Prerelease: https://docs.python.org/3.15/whatsnew/3.15.html |
| 17 | + return `https://docs.python.org/${major}.${minor}/whatsnew/${major}.${minor}.html`; |
| 18 | + } else { |
| 19 | + // Regular release: https://docs.python.org/release/3.13.9/whatsnew/changelog.html |
| 20 | + return `https://docs.python.org/release/${major}.${minor}.${patch}/whatsnew/changelog.html`; |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +document.addEventListener('DOMContentLoaded', function() { |
| 25 | + // Only run on add page, not edit |
| 26 | + if (!window.location.pathname.endsWith('/add/')) { |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + const nameField = document.getElementById('id_name'); |
| 31 | + const releaseNotesUrlField = document.getElementById('id_release_notes_url'); |
| 32 | + |
| 33 | + if (!nameField || !releaseNotesUrlField) { |
| 34 | + return; |
| 35 | + } |
| 36 | + |
| 37 | + // Track if user has manually edited the field |
| 38 | + let changed = false; |
| 39 | + releaseNotesUrlField.addEventListener('change', function() { |
| 40 | + changed = true; |
| 41 | + }); |
| 42 | + |
| 43 | + nameField.addEventListener('keyup', populate); |
| 44 | + nameField.addEventListener('change', populate); |
| 45 | + nameField.addEventListener('focus', populate); |
| 46 | + |
| 47 | + function populate() { |
| 48 | + if (changed) { |
| 49 | + return; |
| 50 | + } |
| 51 | + releaseNotesUrlField.value = generateReleaseNotesUrl(nameField.value); |
| 52 | + } |
| 53 | +}); |
0 commit comments