Skip to content

Commit 148ab88

Browse files
authored
Style commit dropdown use light,dark,random themes (#310)
1 parent 2c86bd1 commit 148ab88

File tree

3 files changed

+65
-24
lines changed

3 files changed

+65
-24
lines changed

doc/source/_static/css/custom.css

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ body.light-theme {
1515
--search-bg-color: #fff; /* Search Box White */
1616
--footer-bg-color: #000; /* Footer Black */
1717
--footer-text-color: #fff; /* Footer White */
18+
19+
/* Commit Specific Colors (Light) */
20+
--commit-link-color: #0077aa;
21+
--commit-date-color: red;
1822
}
1923

2024
/* Dark Theme Variables */
@@ -31,6 +35,10 @@ body.dark-theme {
3135
--search-bg-color: #3e4451; /* Search Box Dark Gray */
3236
--footer-bg-color: #1a1a1a; /* Footer Dark Gray */
3337
--footer-text-color: #c9c9c9; /* Footer Light Gray */
38+
39+
/* Commit Specific Colors (Dark) */
40+
--commit-link-color: var(--link-color); /* Use standard link color for visibility */
41+
--commit-date-color: orange; /* Better visibility than red on dark background */
3442
}
3543

3644
/* --- 2. Apply Variables to Global Elements --- */
@@ -117,8 +125,6 @@ div.sphinxsidebar ul li a, div.sphinxsidebar p {
117125
}
118126

119127
/* --- 6. Content Wrapper for Background Image Setting --- */
120-
/* When background is ON, bodywrapper background is set to transparent by JS. */
121-
/* When background is OFF, bodywrapper uses the main-bg-color (light/dark). */
122128

123129
.bodywrapper {
124130
background-color: var(--main-bg-color);
@@ -134,7 +140,7 @@ body.dark-theme .bodywrapper .body {
134140
background-color: orange;
135141
}
136142

137-
/* --- New 7. Random Theme Overrides --- */
143+
/* --- 7. Random Theme Overrides --- */
138144

139145
/* Define the new CSS variables for random colors (they will be set via JS) */
140146
:root {
@@ -162,13 +168,18 @@ body.custom-random-theme {
162168
--search-bg-color: var(--random-border-color); /* Use a darker color */
163169
--footer-bg-color: var(--random-footer-bg-color);
164170
--footer-text-color: var(--random-text-color);
171+
172+
/* Commit Specific Colors (Random Theme) */
173+
--commit-link-color: var(--random-link-color);
174+
--commit-date-color: #ffcc00; /* Yellow */
165175
}
176+
166177
/* Ensure the bodywrapper also uses the random background color if background image is off */
167178
body.custom-random-theme .bodywrapper {
168179
background-color: var(--random-main-bg-color);
169180
}
170181

171-
/* --- New 8. Custom Vertical Orange Gradient for bodywrapper --- */
182+
/* --- 8. Custom Vertical Orange Gradient for bodywrapper --- */
172183

173184
/* Target the bodywrapper element for the gradient background */
174185
.bodywrapper .body {
@@ -192,7 +203,8 @@ div.body .caption {
192203
font-size: 16pt;
193204
}
194205

195-
/* _static/custom.css */
206+
/* --- 9. Custom Commit Banner and Dropdown Styles --- */
207+
196208
#full-width-commit-banner {
197209
width: 100%;
198210
background-color: #333; /* Dark background for banner */
@@ -227,19 +239,49 @@ div.body .caption {
227239
padding: 10px;
228240
}
229241

242+
/* Class to control the initial visibility */
243+
#commit-dropdown-content.commit-dropdown-hidden {
244+
display: none;
245+
}
246+
230247
#commit-search {
231248
width: 95%;
232249
padding: 5px;
233250
margin-bottom: 10px;
251+
/* Ensure the search bar respects theme colors */
252+
background-color: var(--search-bg-color);
253+
color: var(--text-color);
254+
border-color: var(--border-color);
234255
}
235256

236-
/* Target the links inside the commit list for consistent styling */
237-
#commit-list a {
238-
text-decoration: none; /* Remove underline */
239-
color: #0077aa !important; /* Ensure consistent color */
240-
font-weight: bold; /* Make the hash stand out */
257+
/* --- 10. CSS Class Styles for Dynamic Content (Commits) --- */
258+
259+
/* Style for the short SHA link (used in renderCommits) */
260+
.commit-sha-link {
261+
color: var(--commit-link-color) !important;
262+
font-weight: bold;
263+
text-decoration: none;
241264
}
242265

243-
#commit-list a:hover {
244-
text-decoration: underline; /* Add underline on hover */
266+
.commit-sha-link:hover {
267+
text-decoration: underline;
268+
}
269+
270+
/* Style for the date span (used in renderCommits) */
271+
.commit-date-span {
272+
color: var(--commit-date-color);
273+
}
274+
275+
/* Style for the Pull Request link (used in formatCommitMessage) */
276+
.commit-pr-link {
277+
color: var(--commit-link-color) !important;
278+
font-weight: bold;
279+
text-decoration: underline;
280+
}
281+
282+
/* Ensure the dropdown content itself uses the theme colors correctly */
283+
body #commit-dropdown-content {
284+
background-color: var(--main-bg-color);
285+
color: var(--text-color);
286+
border-color: var(--border-color);
245287
}

doc/source/_static/js/commit-banner.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ document.addEventListener('DOMContentLoaded', () => {
2929
const prNumber = prTag.substring(1); // e.g., "241"
3030
const prUrl = `${GITHUB_REPO_URL}/pull/${prNumber}`;
3131

32-
// Replace the matched text with the HTML anchor tag
32+
// Replace the matched text with the HTML anchor tag, using the CSS class
3333
formattedMessage = formattedMessage.replace(
3434
prRegex,
3535
// Insert a space before the link for better readability
3636
` (<a
3737
href="${prUrl}"
3838
target="_blank"
3939
rel="noopener noreferrer"
40-
style="color: #0077aa; font-weight: bold; text-decoration: underline;"
40+
class="commit-pr-link"
4141
>${prTag}</a>)`,
4242
);
4343
}
@@ -57,18 +57,16 @@ document.addEventListener('DOMContentLoaded', () => {
5757
// Apply the new formatting function to the commit message
5858
const formattedMessage = formatCommitMessage(commit.message);
5959

60-
// Format for display
61-
// Use the full 'commit.sha' for the link URL
62-
// Use 'commit.short_sha' for the visible text
60+
// Format for display - Use CSS classes for styling
6361
li.innerHTML = `
6462
<a
6563
href="${GITHUB_COMMIT_URL}${commit.sha}"
6664
target="_blank"
67-
style="color: #0077aa; font-weight: bold; text-decoration: none;"
65+
class="commit-sha-link"
6866
>
6967
${commit.short_sha}
7068
</a>
71-
(<span style="color: red;">${commit.date}</span>):
69+
(<span class="commit-date-span">${commit.date}</span>):
7270
${formattedMessage}
7371
`;
7472
commitList.appendChild(li);
@@ -100,11 +98,12 @@ document.addEventListener('DOMContentLoaded', () => {
10098

10199
// 1. Toggle Dropdown and Load Data
102100
button.addEventListener('click', () => {
103-
const isVisible = content.style.display === 'block';
104-
content.style.display = isVisible ? 'none' : 'block';
101+
// Toggle the 'commit-dropdown-hidden' class.
102+
// The toggle() method returns true if the class is added (now hidden), and false if the class is removed (now visible).
103+
const wasHidden = content.classList.toggle('commit-dropdown-hidden');
105104

106-
// Load data only on the first click
107-
if (!isVisible && allCommits.length === 0) {
105+
// Load data only when it is being shown (i.e., when it was hidden before the toggle)
106+
if (!wasHidden && allCommits.length === 0) {
108107
loadCommitData();
109108
}
110109
});

doc/source/_templates/layout.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{% block content %}
88
<div id="full-width-commit-banner">
99
<button id="commit-dropdown-button">View Commits (Build-Time Data)</button>
10-
<div id="commit-dropdown-content" style="display:none;">
10+
<div id="commit-dropdown-content" class="commit-dropdown-hidden">
1111
<input type="text" id="commit-search" placeholder="Filter commit message or SHA...">
1212
<ul id="commit-list">
1313
<li>Loading client-side data...</li>

0 commit comments

Comments
 (0)