Skip to content

Commit cd4514c

Browse files
authored
Merge pull request #4673 from shraddhabang/dynbanner
Add dynamic annoucement banner for live docs
2 parents 7f10a8a + 5f4670f commit cd4514c

File tree

3 files changed

+144
-1
lines changed

3 files changed

+144
-1
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
(function () {
2+
var REPO = "kubernetes-sigs/aws-load-balancer-controller";
3+
var LABEL = "announcement";
4+
var API_URL =
5+
"https://api.github.com/repos/" +
6+
REPO +
7+
"/issues?labels=" +
8+
LABEL +
9+
"&state=open&per_page=5&sort=created&direction=desc";
10+
11+
function escapeHtml(text) {
12+
var div = document.createElement("div");
13+
div.appendChild(document.createTextNode(text));
14+
return div.innerHTML;
15+
}
16+
17+
function renderAnnouncements(issues) {
18+
if (issues.length === 0) return;
19+
20+
var banner = document.getElementById("gh-announcements");
21+
if (!banner) return;
22+
23+
var issueLinks = issues
24+
.map(function (issue) {
25+
return (
26+
'<li class="gh-announcement-item">' +
27+
'<a href="' + issue.html_url + '" target="_blank" rel="noopener">' +
28+
escapeHtml(issue.title) +
29+
"</a>" +
30+
"</li>"
31+
);
32+
})
33+
.join("");
34+
35+
banner.innerHTML =
36+
'<details class="gh-announcement-details">' +
37+
'<summary class="gh-announcement-summary">' +
38+
"⚠️ Known Issues — " +
39+
"We are aware of some issues and are actively working on fixes. " +
40+
"Click to view details and workarounds." +
41+
"</summary>" +
42+
'<div class="gh-announcement-body">' +
43+
'<ul class="gh-announcement-list">' +
44+
issueLinks +
45+
"</ul>" +
46+
"</div>" +
47+
"</details>";
48+
49+
banner.style.display = "block";
50+
}
51+
52+
function fetchAnnouncements() {
53+
fetch(API_URL)
54+
.then(function (res) {
55+
if (!res.ok) throw new Error("GitHub API error: " + res.status);
56+
return res.json();
57+
})
58+
.then(renderAnnouncements)
59+
.catch(function (err) {
60+
console.warn("Could not load announcements:", err);
61+
});
62+
}
63+
64+
if (document.readyState === "loading") {
65+
document.addEventListener("DOMContentLoaded", fetchAnnouncements);
66+
} else {
67+
fetchAnnouncements();
68+
}
69+
})();
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#gh-announcements {
2+
display: none;
3+
position: sticky;
4+
top: 0;
5+
z-index: 2;
6+
background: #fff3e0;
7+
border-bottom: 2px solid #ff9800;
8+
font-size: 0.75rem;
9+
line-height: 1.4;
10+
color: #4e342e;
11+
}
12+
13+
[data-md-color-scheme="slate"] #gh-announcements {
14+
background: #3e2723;
15+
border-bottom-color: #ff9800;
16+
color: #ffe0b2;
17+
}
18+
19+
.gh-announcement-details {
20+
max-width: 61rem;
21+
margin: 0 auto;
22+
padding: 6px 24px;
23+
}
24+
25+
.gh-announcement-summary {
26+
cursor: pointer;
27+
font-weight: 600;
28+
padding: 2px 0;
29+
list-style: none;
30+
user-select: none;
31+
}
32+
33+
.gh-announcement-summary::-webkit-details-marker {
34+
display: none;
35+
}
36+
37+
.gh-announcement-summary::before {
38+
content: "▸ ";
39+
}
40+
41+
.gh-announcement-details[open] > .gh-announcement-summary::before {
42+
content: "▾ ";
43+
}
44+
45+
.gh-announcement-body {
46+
padding: 4px 0 2px;
47+
}
48+
49+
.gh-announcement-list {
50+
margin: 0;
51+
padding-left: 18px;
52+
list-style: disc;
53+
}
54+
55+
.gh-announcement-item {
56+
padding: 1px 0;
57+
}
58+
59+
.gh-announcement-item a {
60+
color: #e65100;
61+
text-decoration: underline;
62+
font-weight: 500;
63+
}
64+
65+
[data-md-color-scheme="slate"] .gh-announcement-item a {
66+
color: #ffb74d;
67+
}

docs/theme_overrides/main.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
{% block styles %}
44
{{ super() }}
55
<link rel="stylesheet" href="{{ 'assets/stylesheets/version-select.css' | url }}">
6+
<link rel="stylesheet" href="{{ 'assets/stylesheets/announcements.css' | url }}">
7+
{% endblock %}
8+
9+
{% block tabs %}
10+
{{ super() }}
11+
<div id="gh-announcements"></div>
612
{% endblock %}
713

814
{% block scripts %}
915
{{ super() }}
1016
<script src="{{ 'assets/javascripts/version-select.js' | url }}"></script>
11-
{% endblock %}
17+
<script src="{{ 'assets/javascripts/announcements.js' | url }}"></script>
18+
{% endblock %}

0 commit comments

Comments
 (0)