Skip to content

feat: Add GitHub button to navigation bar #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 53 additions & 9 deletions sass/_valkey.scss
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ p {
padding: 10px;
padding: 0 20px;

@include respond-min(768px) {
@include respond-min(1024px) {
padding: 0 20px;
}
}
Expand Down Expand Up @@ -164,7 +164,7 @@ p {
padding: .5rem 0;
border-bottom: none;

@include respond-min(768px) {
@include respond-min(1024px) {
border-bottom: 3px solid;
padding: 1rem 0;
border-color: transparent;
Expand All @@ -174,16 +174,16 @@ p {
>a {
&:hover,
&.active {
border-color: inherit;
border-color: inherit;
text-decoration: underline;

@include respond-min(768px) {
@include respond-min(1024px) {
text-decoration: none;
}
}
}

@media (max-width: 768px) {
@media (max-width: 1024px) {
display: none;
gap: 1rem;

Expand Down Expand Up @@ -213,6 +213,50 @@ p {
}
}
}

.github-button {
display: flex;
align-items: center;
padding: 0.5rem 1rem !important;
background-color: #f8f9fa;
border: 1px solid #dfe1e4;
border-radius: 6px;
color: #444;
text-decoration: none;
transition: all 0.2s ease;

img {
filter: brightness(0) saturate(100%) invert(27%) sepia(0%) saturate(0%) hue-rotate(0deg) brightness(0%) contrast(100%);
margin-right: 0.5rem;
}

.star-count {
background: #f1f5f9;
color: #64748b;
font-size: 12px;
padding: 2px 6px;
border-radius: 10px;
margin-left: 0;
font-weight: 500;
white-space: nowrap;
border: 1px solid #e2e8f0;
transition: all 0.2s;
}

&:hover {
background-color: #e9ecef;
border-color: #dee2e6;
text-decoration: none;
border-bottom-color: #e9ecef;
}

@media (max-width: 1024px) {
padding: 0.75rem 1rem !important;
margin-top: 0.5rem;
justify-content: center;
text-align: center;
}
}
}
.btn-menu {
display: none;
Expand Down Expand Up @@ -241,7 +285,7 @@ p {
transition-duration: .2s;
}

@media (max-width: 768px) {
@media (max-width: 1024px) {
display: flex;
}
}
Expand All @@ -252,7 +296,7 @@ p {
display: block;
align-items: center;

@include respond-min(768px) {
@include respond-min(1024px) {
display: flex;
}

Expand All @@ -274,7 +318,7 @@ p {
&:hover {
text-decoration: underline;

@include respond-min(768px) {
@include respond-min(1024px) {
text-decoration: none;
}
}
Expand All @@ -291,7 +335,7 @@ p {
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
padding: .25rem 0;

@include respond-min(768px) {
@include respond-min(1024px) {
display: none;
}

Expand Down
44 changes: 43 additions & 1 deletion static/assets/js/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,45 @@ window.toggleHeaderMenu = function() {
}
};

// Fetch and display GitHub stars count
async function fetchGitHubStars() {
try {
const response = await fetch('https://api.github.com/repos/valkey-io/valkey');
if (response.ok) {
const data = await response.json();
const starCount = data.stargazers_count;

// Find the GitHub button and add star count
const githubButton = document.querySelector('.github-button');
if (githubButton) {
// Create star count element if it doesn't exist
let starCountElement = githubButton.querySelector('.star-count');
if (!starCountElement) {
starCountElement = document.createElement('span');
starCountElement.className = 'star-count';
starCountElement.style.cssText = `
background: #f1f5f9;
color: #64748b;
font-size: 12px;
padding: 2px 6px;
border-radius: 10px;
margin-left: 6px;
font-weight: 500;
white-space: nowrap;
`;
githubButton.appendChild(starCountElement);
}

// Format the number with K for thousands
const formattedCount = starCount >=100? (starCount / 1000).toFixed(1) + 'k' : starCount.toString();
starCountElement.textContent = `${formattedCount} ★`;
}
}
} catch (error) {
console.log('Could not fetch GitHub stars:', error);
}
}

// Set active menu item based on current URL
function setActiveMenuItem() {
const nav = document.querySelector('.header nav');
Expand All @@ -30,7 +69,10 @@ function setActiveMenuItem() {
}

// Run when DOM is loaded
document.addEventListener('DOMContentLoaded', setActiveMenuItem);
document.addEventListener('DOMContentLoaded', function() {
setActiveMenuItem();
fetchGitHubStars();
});

// Class detection function that checks if an element with a given class name exists
// This provides backwards compatibility for older browsers (IE6-8) that don't support getElementsByClassName
Expand Down
6 changes: 6 additions & 0 deletions templates/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
<a role="menuitem" href="/community/">Community</a>
<a role="menuitem" href="/participants/">Participants</a>
<a role="menuitem" href="/try-valkey/">Try Valkey</a>
<a role="menuitem" href="https://github.com/valkey-io" target="_blank" class="github-button">
<img src="/img/IconGithub.svg" alt="GitHub Icon" width="16" height="16" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, I would like to show the current number of stars. I think it adds a lot of legitimacy that the project is real if it has a lot of stars.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement star count fetching from GitHub API

Screenshot 2025-07-16 at 6 52 42 PM

GitHub
<!-- Star count will be injected here by JS -->
</a>

</nav>
</div>
</div>
Expand Down