Skip to content

Commit 25a1bf4

Browse files
committed
Add GitHub Streak Stats
1 parent d7bf06c commit 25a1bf4

File tree

7 files changed

+97
-3
lines changed

7 files changed

+97
-3
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/addons.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,16 @@ const Addons = props => {
221221
})
222222
}, [props.data.topLanguagesOptions])
223223

224+
const [streakStatsOptions, setStreakStatsOptions] = useState({
225+
...props.data.streakStatsOptions,
226+
});
227+
228+
useEffect(() => {
229+
setStreakStatsOptions({
230+
...props.data.streakStatsOptions
231+
})
232+
}, [props.data.streakStatsOptions])
233+
224234
const blogPostPorkflow = () => {
225235
let payload = {
226236
dev: {
@@ -271,6 +281,12 @@ const Addons = props => {
271281
props.handleDataChange("topLanguagesOptions", {target: {value: newLangOptions}})
272282
}
273283

284+
const onStreakStatsUpdate = (option, value) => {
285+
const newStreakStatsOptions = {...streakStatsOptions, [option]: value}
286+
setStreakStatsOptions(newStreakStatsOptions)
287+
props.handleDataChange("streakStatsOptions", {target: {value: newStreakStatsOptions}})
288+
}
289+
274290
return (
275291
<div className="flex justify-center items-start flex-col w-full px-2 sm:px-6 mb-10">
276292
<div className="text-xl sm:text-2xl font-bold font-title mt-2 mb-2">
@@ -332,6 +348,21 @@ const Addons = props => {
332348
>
333349
display top skills
334350
</AddonsItem>
351+
<AddonsItem
352+
inputId="streak-stats"
353+
inputChecked={props.data.streakStats}
354+
onInputChange={() => props.handleCheckChange("streakStats")}
355+
Options={
356+
<CustomizeOptions
357+
title="Customize Streak Stats Card"
358+
CustomizationOptions={
359+
<CustomizeGithubStatsBase prefix="streak-stats" options={streakStatsOptions} onUpdate={onStreakStatsUpdate}/>
360+
}
361+
/>
362+
}
363+
>
364+
display streak stats
365+
</AddonsItem>
335366
<AddonsItem
336367
inputId="twitter-badge"
337368
inputChecked={props.data.twitterBadge}

src/components/markdown.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { icons, skills, skillWebsites } from "../constants/skills"
44
import {
55
githubStatsLinkGenerator,
66
topLanguagesLinkGenerator,
7+
streakStatsLinkGenerator
78
} from "../utils/link-generators"
89

910
const Markdown = props => {
@@ -146,6 +147,21 @@ const Markdown = props => {
146147
}
147148
return ""
148149
}
150+
const DisplayStreakStats = ({ show, github, options }) => {
151+
if (show) {
152+
return (
153+
<>
154+
{`<p>&nbsp;<img align="center" src="${streakStatsLinkGenerator({
155+
github: github,
156+
options,
157+
})}" alt="${github}" /></p>`}
158+
<br />
159+
<br />
160+
</>
161+
)
162+
}
163+
return ""
164+
}
149165
const isSocial = social => {
150166
return (
151167
social.dev ||
@@ -523,6 +539,13 @@ const Markdown = props => {
523539
options={props.data.githubStatsOptions}
524540
/>
525541
</>
542+
<>
543+
<DisplayStreakStats
544+
show={props.data.streakStats}
545+
github={props.social.github}
546+
options={props.data.streakStatsOptions}
547+
/>
548+
</>
526549
</div>
527550
)
528551
}

src/components/markdownPreview.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { icons, skills, skillWebsites } from "../constants/skills"
33
import {
44
githubStatsLinkGenerator,
55
topLanguagesLinkGenerator,
6+
streakStatsLinkGenerator
67
} from "../utils/link-generators"
78

89
const MarkdownPreview = props => {
@@ -299,6 +300,19 @@ const MarkdownPreview = props => {
299300
}
300301
return null
301302
}
303+
const StreakStatsPreview = ({ github, options, show }) => {
304+
if (show) {
305+
return (
306+
<div className="text-center mx-4 mb-4">
307+
<img
308+
src={streakStatsLinkGenerator({ github, options })}
309+
alt={github}
310+
/>
311+
</div>
312+
)
313+
}
314+
return null
315+
}
302316
const TopLanguagesPreview = ({ github, options, show }) => {
303317
if (show) {
304318
return (
@@ -372,6 +386,11 @@ const MarkdownPreview = props => {
372386
github={props.social.github}
373387
options={props.data.githubStatsOptions}
374388
/>
389+
<StreakStatsPreview
390+
show={props.data.streakStats}
391+
github={props.social.github}
392+
options={props.data.streakStatsOptions}
393+
/>
375394
</div>
376395
</div>
377396
)

src/markdown-pages/addons.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ You can customize the theme too. See how to customize yours [here](https://githu
2828

2929
<br/>
3030

31+
## [GitHub Readme Streak Stats](https://github.com/DenverCoder1/github-readme-streak-stats)
32+
33+
Stay motivated while contributing to open source by displaying your current contribution streak
34+
35+
![rahuldkjain](https://github-readme-streak-stats.herokuapp.com/?user=rahuldkjain)
36+
37+
Developed by by [Jonah Lawrence](https://github.com/DenverCoder1).
38+
39+
See how to customize the theme [here](https://github.com/DenverCoder1/github-readme-streak-stats)
40+
41+
<br/>
42+
3143
## [GitHub Profile Views Counter](https://github.com/antonkomarev/github-profile-views-counter)
3244

3345
It counts how many times your GitHub profile has been viewed. Free cloud micro-service.

src/pages/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ const DEFAULT_DATA = {
8181
cacheSeconds: null,
8282
locale: "en",
8383
},
84+
streakStats: false,
85+
streakStatsOptions: {
86+
theme: "",
87+
},
8488
devDynamicBlogs: false,
8589
mediumDynamicBlogs: false,
8690
rssDynamicBlogs: false,
@@ -253,7 +257,8 @@ const IndexPage = () => {
253257
data.visitorsBadge ||
254258
data.githubProfileTrophy ||
255259
data.githubStats ||
256-
data.topLanguages
260+
data.topLanguages ||
261+
data.streakStats
257262
) {
258263
if (social.github && isGitHubUsernameValid(social.github)) {
259264
generate()
@@ -520,7 +525,8 @@ const IndexPage = () => {
520525
{(data.visitorsBadge ||
521526
data.githubProfileTrophy ||
522527
data.githubStats ||
523-
data.topLanguages) &&
528+
data.topLanguages ||
529+
data.streakStats) &&
524530
!social.github ? (
525531
<div className="warning">
526532
* Please add github username to use these add-ons

src/utils/link-generators.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ export const githubStatsLinkGenerator = ({github, options}) =>
1818

1919
export const topLanguagesLinkGenerator = ({github, options}) =>
2020
`https://github-readme-stats.vercel.app/api/top-langs?username=${github}&${githubStatsStylingQueryString(options)}&layout=compact`
21+
22+
export const githubStreakLinkGenerator = ({github, options}) =>
23+
`https://github-readme-streak-stats.herokuapp.com/?user=${github}`

0 commit comments

Comments
 (0)