Skip to content

Commit

Permalink
add github link to top nav
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Apr 13, 2024
1 parent d41797c commit 8fc265d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/images/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import './js/components/learn-more-scroll';
import './js/components/demo';
import './js/components/tabs';
import './js/components/cursors';
import './js/components/github-button';
import './index.scss';
27 changes: 27 additions & 0 deletions src/js/components/github-button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const fetchStars = async () => {
const response = await fetch(
'https://api.github.com/repos/anycable/anycable'
);
const data = await response.json();
return data.stargazers_count;
};

const el = document.getElementById('gh-stars-counter');

if (el) {
fetchStars().then(stars => {
if (!stars) return;

let starsK = Math.round(stars / 100);

starsK = starsK / 10;

if (starsK >= 10) {
starsK = starsK | 0;
} else if (starsK == starsK - Math.floor(starsK)) {
starsK = starsK | 0;
}

el.textContent = `${starsK}K`;
});
}
24 changes: 24 additions & 0 deletions src/modules/blocks/header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ $className: 'header';
align-items: center;
}

&__right {
display: flex;
flex-direction: row;
align-items: center;
}

&__stars {
margin-right: 40px;
display: flex;
flex-direction: row;
align-items: center;
text-decoration: none;
color: $fontSecondaryColor;
transition: color 200ms ease-in-out;

&:hover {
color: $fontPrimaryColor;
}

&__count {
margin-left: 8px;
}
}

&__links {
margin-left: 64px;

Expand Down
14 changes: 10 additions & 4 deletions src/partials/header.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
<nav class='header__content'>
<div class='header__left'>
<p class='header__logo'>AnyCable</p>
<div class='header__links'>
<a href="https://docs.anycable.io" target="_blank" class="header__link no-mobile" data-ph-capture-attribute-link-id="nav-docs">Docs</a>
<a href="https://blog.anycable.io" target="_blank" class="header__link no-mobile" data-ph-capture-attribute-link-id="nav-blog">Blog</a>
<div class='header__links no-mobile'>
<a href="https://docs.anycable.io" target="_blank" class="header__link" data-ph-capture-attribute-link-id="nav-docs">Docs</a>
<a href="https://blog.anycable.io" target="_blank" class="header__link" data-ph-capture-attribute-link-id="nav-blog">Blog</a>
<a href="#pricing" class="header__link" data-ph-capture-attribute-link-id="nav-pricing">Pricing</a>
</div>
</div>
<a href="https://plus.anycable.io/pro" target="_blank" class="button" data-ph-capture-attribute-link-id='go-pro'>Sign up</a>
<div class='header__right'>
<a class='header__stars' href="https://github.com/anycable/anycable" target="_blank" data-ph-capture-attribute-link-id="nav-github">
{{inline 'images/github.svg'}}
<span class='header__stars__count' id="gh-stars-counter">1.9K</span>
</a>
<a href="https://plus.anycable.io/pro" target="_blank" class="button" data-ph-capture-attribute-link-id='go-pro'>Sign up</a>
</div>
</nav>
</header>

0 comments on commit 8fc265d

Please sign in to comment.