11document . addEventListener ( 'DOMContentLoaded' , ( ) => {
2- const button = document . getElementById ( 'commit-dropdown-button' ) ;
3- const content = document . getElementById ( 'commit-dropdown-content' ) ;
4- const searchBar = document . getElementById ( 'commit-search' ) ;
5- const commitList = document . getElementById ( 'commit-list' ) ;
6- let allCommits = [ ] ;
7-
8- // Define the base URL for your GitHub repository
9- const GITHUB_REPO_URL = 'https://github.com/64-shades/64-shades.github.io' ;
10-
11- // Base commit URL (used for short_sha link)
12- const GITHUB_COMMIT_URL = `${ GITHUB_REPO_URL } /commit/` ;
13-
14- // Regex to find '#<number>' at the end of a commit message
15- const prRegex = / \( ( # \d + ) \) \s * $ / ;
16-
17- /**
18- * Processes the commit message to convert a trailing PR number
19- * (e.g., "#241") into an HTML link to the GitHub Pull Request page.
20- * @param {string } message - The original commit message.
21- * @returns {string } The formatted message with a linked PR number, if found.
22- */
23- function formatCommitMessage ( message ) {
24- let formattedMessage = message ;
25- const match = formattedMessage . match ( prRegex ) ;
26-
27- if ( match ) {
28- const prTag = match [ 1 ] ; // e.g., "#241"
29- const prNumber = prTag . substring ( 1 ) ; // e.g., "241"
30- const prUrl = `${ GITHUB_REPO_URL } /pull/${ prNumber } ` ;
31-
32- // Replace the matched text with the HTML anchor tag
33- formattedMessage = formattedMessage . replace (
34- prRegex ,
35- // Insert a space before the link for better readability
36- ` (<a
2+ const button = document . getElementById ( 'commit-dropdown-button' ) ;
3+ const content = document . getElementById ( 'commit-dropdown-content' ) ;
4+ const searchBar = document . getElementById ( 'commit-search' ) ;
5+ const commitList = document . getElementById ( 'commit-list' ) ;
6+ let allCommits = [ ] ;
7+
8+ // Define the base URL for your GitHub repository
9+ const GITHUB_REPO_URL = 'https://github.com/64-shades/64-shades.github.io' ;
10+
11+ // Base commit URL (used for short_sha link)
12+ const GITHUB_COMMIT_URL = `${ GITHUB_REPO_URL } /commit/` ;
13+
14+ // Regex to find '#<number>' at the end of a commit message
15+ const prRegex = / \( ( # \d + ) \) \s * $ / ;
16+
17+ /**
18+ * Processes the commit message to convert a trailing PR number
19+ * (e.g., "#241") into an HTML link to the GitHub Pull Request page.
20+ * @param {string } message - The original commit message.
21+ * @returns {string } The formatted message with a linked PR number, if found.
22+ */
23+ function formatCommitMessage ( message ) {
24+ let formattedMessage = message ;
25+ const match = formattedMessage . match ( prRegex ) ;
26+
27+ if ( match ) {
28+ const prTag = match [ 1 ] ; // e.g., "#241"
29+ const prNumber = prTag . substring ( 1 ) ; // e.g., "241"
30+ const prUrl = `${ GITHUB_REPO_URL } /pull/${ prNumber } ` ;
31+
32+ // Replace the matched text with the HTML anchor tag
33+ formattedMessage = formattedMessage . replace (
34+ prRegex ,
35+ // Insert a space before the link for better readability
36+ ` (<a
3737 href="${ prUrl } "
3838 target="_blank"
3939 rel="noopener noreferrer"
4040 style="color: #0077aa; font-weight: bold; text-decoration: underline;"
41- >${ prTag } </a>)`
42- ) ;
43- }
44- return formattedMessage ;
41+ >${ prTag } </a>)` ,
42+ ) ;
4543 }
44+ return formattedMessage ;
45+ }
46+
47+ // Function to render the list of commits
48+ function renderCommits ( commits ) {
49+ commitList . innerHTML = '' ;
50+ if ( commits . length === 0 ) {
51+ commitList . innerHTML = '<li>No commits found.</li>' ;
52+ return ;
53+ }
54+ commits . forEach ( ( commit ) => {
55+ const li = document . createElement ( 'li' ) ;
4656
57+ // Apply the new formatting function to the commit message
58+ const formattedMessage = formatCommitMessage ( commit . message ) ;
4759
48- // Function to render the list of commits
49- function renderCommits ( commits ) {
50- commitList . innerHTML = '' ;
51- if ( commits . length === 0 ) {
52- commitList . innerHTML = '<li>No commits found.</li>' ;
53- return ;
54- }
55- commits . forEach ( commit => {
56- const li = document . createElement ( 'li' ) ;
57-
58- // Apply the new formatting function to the commit message
59- const formattedMessage = formatCommitMessage ( commit . message ) ;
60-
61- // Format for display
62- // Use the full 'commit.sha' for the link URL
63- // Use 'commit.short_sha' for the visible text
64- li . innerHTML = `
60+ // Format for display
61+ // Use the full 'commit.sha' for the link URL
62+ // Use 'commit.short_sha' for the visible text
63+ li . innerHTML = `
6564 <a
6665 href="${ GITHUB_COMMIT_URL } ${ commit . sha } "
6766 target="_blank"
@@ -72,56 +71,58 @@ document.addEventListener('DOMContentLoaded', () => {
7271 (${ commit . date } ):
7372 ${ formattedMessage }
7473 ` ;
75- commitList . appendChild ( li ) ;
76- } ) ;
77- }
78-
79- // Function to load the static JSON data
80- function loadCommitData ( ) {
81- // Fetch the file generated during the Sphinx build
82- fetch ( 'commits.json' )
83- . then ( response => {
84- if ( ! response . ok ) {
85- throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
86- }
87- return response . json ( ) ;
88- } )
89- . then ( data => {
90- allCommits = data ;
91- renderCommits ( allCommits ) ;
92- } )
93- . catch ( error => {
94- commitList . innerHTML = '<li>Error loading static commit data. Check build process and file path.</li>' ;
95- console . error ( 'Error loading static commits.json:' , error ) ;
96- } ) ;
97- }
98-
99- // --- Event Listeners ---
100-
101- // 1. Toggle Dropdown and Load Data
102- button . addEventListener ( 'click' , ( ) => {
103- const isVisible = content . style . display === 'block' ;
104- content . style . display = isVisible ? 'none' : 'block' ;
105-
106- // Load data only on the first click
107- if ( ! isVisible && allCommits . length === 0 ) {
108- loadCommitData ( ) ;
109- }
74+ commitList . appendChild ( li ) ;
11075 } ) ;
76+ }
77+
78+ // Function to load the static JSON data
79+ function loadCommitData ( ) {
80+ // Fetch the file generated during the Sphinx build
81+ fetch ( 'commits.json' )
82+ . then ( ( response ) => {
83+ if ( ! response . ok ) {
84+ throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
85+ }
86+ return response . json ( ) ;
87+ } )
88+ . then ( ( data ) => {
89+ allCommits = data ;
90+ renderCommits ( allCommits ) ;
91+ } )
92+ . catch ( ( error ) => {
93+ commitList . innerHTML =
94+ '<li>Error loading static commit data. Check build process and file path.</li>' ;
95+ console . error ( 'Error loading static commits.json:' , error ) ;
96+ } ) ;
97+ }
98+
99+ // --- Event Listeners ---
100+
101+ // 1. Toggle Dropdown and Load Data
102+ button . addEventListener ( 'click' , ( ) => {
103+ const isVisible = content . style . display === 'block' ;
104+ content . style . display = isVisible ? 'none' : 'block' ;
105+
106+ // Load data only on the first click
107+ if ( ! isVisible && allCommits . length === 0 ) {
108+ loadCommitData ( ) ;
109+ }
110+ } ) ;
111111
112- // 2. Search and Filter Functionality
113- searchBar . addEventListener ( 'keyup' , ( e ) => {
114- const searchTerm = e . target . value . toLowerCase ( ) . trim ( ) ;
112+ // 2. Search and Filter Functionality
113+ searchBar . addEventListener ( 'keyup' , ( e ) => {
114+ const searchTerm = e . target . value . toLowerCase ( ) . trim ( ) ;
115115
116- if ( searchTerm === "" ) {
117- renderCommits ( allCommits ) ; // Show all if search is empty
118- return ;
119- }
116+ if ( searchTerm === '' ) {
117+ renderCommits ( allCommits ) ; // Show all if search is empty
118+ return ;
119+ }
120120
121- const filteredCommits = allCommits . filter ( commit =>
122- commit . message . toLowerCase ( ) . includes ( searchTerm ) ||
123- commit . sha . toLowerCase ( ) . includes ( searchTerm )
124- ) ;
125- renderCommits ( filteredCommits ) ;
126- } ) ;
121+ const filteredCommits = allCommits . filter (
122+ ( commit ) =>
123+ commit . message . toLowerCase ( ) . includes ( searchTerm ) ||
124+ commit . sha . toLowerCase ( ) . includes ( searchTerm ) ,
125+ ) ;
126+ renderCommits ( filteredCommits ) ;
127+ } ) ;
127128} ) ;
0 commit comments