Skip to content
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

Fetch our own stars! #28

Merged
merged 5 commits into from
Jul 5, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
19 changes: 5 additions & 14 deletions website/core/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
*/

const React = require('react')
const GitHubStarButton = require('./GitHubStarButton')

class Footer extends React.Component {
docUrl (doc, language) {
docUrl(doc, language) {
const baseUrl = this.props.config.baseUrl
return baseUrl + 'docs/' + (language ? language + '/' : '') + doc
}

pageUrl (doc, language) {
pageUrl(doc, language) {
const baseUrl = this.props.config.baseUrl
return baseUrl + (language ? language + '/' : '') + doc
}

render () {
render() {
const currentYear = new Date().getFullYear()
return (
<footer className='nav-footer' id='footer'>
Expand Down Expand Up @@ -47,17 +48,7 @@ class Footer extends React.Component {
User Showcase
</a>
<a href='https://gitter.im/isomorphic-git/Lobby'>Project Chat</a>
<a
className='github-button'
href={this.props.config.repoUrl}
data-icon='octicon-star'
data-count-href='/isomorphic-git/isomorphic-git/stargazers'
data-show-count
data-count-aria-label='# stargazers on GitHub'
aria-label='Star this project on GitHub'
>
Github
</a>
<GitHubStarButton />
</div>
<div>
<h5>More</h5>
Expand Down
25 changes: 25 additions & 0 deletions website/core/GitHubStarButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const React = require('react')

const script = `
void async function() {
const response = await fetch('https://api.github.com/repos/isomorphic-git/isomorphic-git', {
headers: { accept: 'application/vnd.github.v3+json' }
})
const data = await response.json()
document.querySelector('#gitHubStars').textContent = '(' + data.stargazers_count + ' stars)'
Copy link
Member

Choose a reason for hiding this comment

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

maybe ⭐ emoji instead of the word "stars"?

}()
`

class GitHubStarButton extends React.Component {
render() {
// "Server-side" rendered, so `componentDidMount` wouldn't be called
return (
<div>
<a href="https://github.com/isomorphic-git/isomorphic-git">GitHub <span id="gitHubStars" /></a>
<script dangerouslySetInnerHTML={{ __html: script }} />
Copy link
Member

Choose a reason for hiding this comment

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

Hahaha this is so not the "right" way to populate a React component, but I love it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm actually not sure if I understand this right, I just wasn't getting any invocations on componentDidMount and I figured Docusaurus just runs the server method of the rendering pipeline and stores the serialized result in static files. I've documented this in the comment but if this is not accurate I'd love to fix it up because this is dirty - but let dirty than having the script in the HTML template I think because at least it's collocated with what it mutates. :-D

</div>
);
}
}

module.exports = GitHubStarButton
4 changes: 0 additions & 4 deletions website/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@
"checkout": "checkout",
"clone": "clone",
"commit": "commit",
"compare": "How does it compare with X?",
"Compare with X": "Compare with X",
"config": "config",
"currentBranch": "currentBranch",
"dir-vs-gitdir": "`dir` vs `gitdir`",
"dir vs gitdir": "dir vs gitdir",
"faq": "Frequently Asked Questions",
"FAQ": "FAQ",
"fetch": "fetch",
"findRoot": "findRoot",
"getRemoteInfo": "getRemoteInfo",
Expand Down
Loading