Skip to content

Commit d9469f4

Browse files
authored
Merge pull request #325 from DenverCoderOne/add-github-streak-stats
[add]: GitHub streak stats
2 parents 4ffebfb + c7c7e1c commit d9469f4

File tree

10 files changed

+127
-54
lines changed

10 files changed

+127
-54
lines changed

.eslintrc.json

Lines changed: 0 additions & 26 deletions
This file was deleted.

.prettierrc

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
11
{
22
"arrowParens": "avoid",
3-
"bracketSpacing": false,
4-
"endOfLine": "lf",
5-
"htmlWhitespaceSensitivity": "css",
6-
"jsxBracketSameLine": false,
7-
"printWidth": 80,
8-
"proseWrap": "preserve",
9-
"requirePragma": false,
10-
"semi": true,
11-
"singleQuote": true,
12-
"tabWidth": 2,
13-
"trailingComma": "all",
14-
"useTabs": false,
15-
"overrides": [
16-
{
17-
"files": "*.json",
18-
"options": {
19-
"printWidth": 200
20-
}
21-
}
22-
]
23-
}
3+
"semi": false
4+
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ Just fill in the details such as `Name`, `Tagline`, `Dev Platforms Username`, `C
7676

7777
- **GitHub Top Skills**
7878

79+
- **GitHub Streak Stats**
80+
7981
- **Dynamic Dev(.)to Blogs** (GitHub Action)
8082

8183
- **Dynamic Medium Blogs** (GitHub Action)
@@ -132,6 +134,7 @@ Please read [`CONTRIBUTING`](CONTRIBUTING.md) for details on our [`CODE OF CONDU
132134
- [Anurag Hazra](https://github.com/anuraghazra) for amazing [github-readme-stats](https://github.com/anuraghazra/github-readme-stats)
133135
- [Anton Komarev](https://github.com/antonkomarev) for super cool [github-profile-views-counter](https://github.com/antonkomarev/github-profile-views-counter)
134136
- [Gautam Krishna R](https://github.com/gautamkrishnar) for the awesome [blog post workflow](https://github.com/gautamkrishnar/blog-post-workflow)
137+
- [Jonah Lawrence](https://github.com/DenverCoder1) for the incredible [github-readme-streak-stats](https://github.com/DenverCoder1/github-readme-streak-stats)
135138
- [Julien Monty](https://github.com/konpa) for super useful [devicon](https://github.com/konpa/devicon)
136139

137140
## 🙇 Sponsors

package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
"devDependencies": {
3131
"babel-jest": "26.3.0",
3232
"babel-preset-gatsby": "0.5.11",
33-
"eslint": "^7.12.1",
34-
"eslint-plugin-react": "^7.21.5",
3533
"gatsby-plugin-postcss": "^2.3.11",
3634
"gatsby-plugin-purgecss": "^5.0.0",
3735
"gatsby-plugin-twitter": "^2.3.10",
@@ -50,8 +48,6 @@
5048
"build": "gatsby build",
5149
"develop": "gatsby develop",
5250
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
53-
"lint": "eslint .",
54-
"lint:fix": "eslint --fix .",
5551
"start": "npm run develop",
5652
"serve": "gatsby serve",
5753
"clean": "gatsby clean",

src/components/addons.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,23 @@ const CustomizeGithubStatsBase = ({ prefix, options, onUpdate }) =>
186186
</label>
187187
</>
188188

189+
const CustomizeStreakStats = ({ prefix, options, onUpdate }) => (
190+
<>
191+
<label htmlFor={`${prefix}-theme`}>
192+
Theme:&nbsp;
193+
<select
194+
id={`${prefix}-theme`}
195+
onChange={({ target: { value } }) => onUpdate("theme", value)}
196+
defaultValue={options.theme}
197+
>
198+
<option value="default">default</option>
199+
<option value="dark">dark</option>
200+
<option value="highcontrast">highcontrast</option>
201+
</select>
202+
</label>
203+
</>
204+
)
205+
189206
const Addons = props => {
190207
const [debounce, setDebounce] = useState(undefined);
191208
const [badgeOptions, setBadgeOptions] = useState({
@@ -222,6 +239,16 @@ const Addons = props => {
222239
})
223240
}, [props.data.topLanguagesOptions])
224241

242+
const [streakStatsOptions, setStreakStatsOptions] = useState({
243+
...props.data.streakStatsOptions,
244+
});
245+
246+
useEffect(() => {
247+
setStreakStatsOptions({
248+
...props.data.streakStatsOptions
249+
})
250+
}, [props.data.streakStatsOptions])
251+
225252
const blogPostPorkflow = () => {
226253
let payload = {
227254
dev: {
@@ -272,6 +299,12 @@ const Addons = props => {
272299
props.handleDataChange("topLanguagesOptions", {target: {value: newLangOptions}})
273300
}
274301

302+
const onStreakStatsUpdate = (option, value) => {
303+
const newStreakStatsOptions = {...streakStatsOptions, [option]: value}
304+
setStreakStatsOptions(newStreakStatsOptions)
305+
props.handleDataChange("streakStatsOptions", {target: {value: newStreakStatsOptions}})
306+
}
307+
275308
return (
276309
<div className="flex justify-center items-start flex-col w-full px-2 sm:px-6 mb-10">
277310
<div className="text-xl sm:text-2xl font-bold font-title mt-2 mb-2">
@@ -333,6 +366,21 @@ const Addons = props => {
333366
>
334367
display top skills
335368
</AddonsItem>
369+
<AddonsItem
370+
inputId="streak-stats"
371+
inputChecked={props.data.streakStats}
372+
onInputChange={() => props.handleCheckChange("streakStats")}
373+
Options={
374+
<CustomizeOptions
375+
title="Customize Streak Stats Card"
376+
CustomizationOptions={
377+
<CustomizeStreakStats prefix="streak-stats" options={streakStatsOptions} onUpdate={onStreakStatsUpdate}/>
378+
}
379+
/>
380+
}
381+
>
382+
display streak stats
383+
</AddonsItem>
336384
<AddonsItem
337385
inputId="twitter-badge"
338386
inputChecked={props.data.twitterBadge}

src/components/markdown.js

Lines changed: 23 additions & 1 deletion
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 => {
@@ -238,7 +239,21 @@ const Markdown = props => {
238239
}
239240
return ""
240241
}
241-
242+
const DisplayStreakStats = props => {
243+
if (props.show) {
244+
return (
245+
<>
246+
{`<p><img align="center" src="${streakStatsLinkGenerator({
247+
github: props.github,
248+
options: props.options,
249+
})}" alt="${props.github}" /></p>`}
250+
<br />
251+
<br />
252+
</>
253+
)
254+
}
255+
return ""
256+
}
242257
return (
243258
<div id="markdown-content" className="break-words">
244259
<>
@@ -524,6 +539,13 @@ const Markdown = props => {
524539
options={props.data.githubStatsOptions}
525540
/>
526541
</>
542+
<>
543+
<DisplayStreakStats
544+
show={props.data.streakStats}
545+
github={props.social.github}
546+
options={props.data.streakStatsOptions}
547+
/>
548+
</>
527549
</div>
528550
)
529551
}

src/components/markdownPreview.js

Lines changed: 20 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
export const TitlePreview = props => {
@@ -322,6 +323,20 @@ export const TopLanguagesPreview = ({ github, options, show }) => {
322323
return <div className="text-center mx-4 mb-4"> &nbsp;</div>
323324
}
324325

326+
export const StreakStatsPreview = ({ github, options, show }) => {
327+
if (show) {
328+
return (
329+
<div className="text-center mx-4 mb-4">
330+
<img
331+
src={streakStatsLinkGenerator({ github, options })}
332+
alt={github}
333+
/>
334+
</div>
335+
)
336+
}
337+
return null
338+
}
339+
325340
export const SkillsPreview = props => {
326341
var listSkills = []
327342
skills.forEach(skill => {
@@ -385,6 +400,11 @@ const MarkdownPreview = props => {
385400
github={props.social.github}
386401
options={props.data.githubStatsOptions}
387402
/>
403+
<StreakStatsPreview
404+
show={props.data.streakStats}
405+
github={props.social.github}
406+
options={props.data.streakStatsOptions}
407+
/>
388408
</div>
389409
</div>
390410
)

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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,19 @@ const githubStatsStylingQueryString = options => {
1313
return query_string
1414
}
1515

16+
const streakStatsStylingQueryString = options => {
17+
const params = {
18+
...(options.theme && options.theme !== "none") && { theme: options.theme },
19+
}
20+
const query_string = Object.entries(params).map(([key, value]) => `${key}=${value}`).join("&")
21+
return query_string
22+
}
23+
1624
export const githubStatsLinkGenerator = ({github, options}) =>
1725
`https://github-readme-stats.vercel.app/api?username=${github}&${githubStatsStylingQueryString(options)}`
1826

1927
export const topLanguagesLinkGenerator = ({github, options}) =>
2028
`https://github-readme-stats.vercel.app/api/top-langs?username=${github}&${githubStatsStylingQueryString(options)}&layout=compact`
29+
30+
export const streakStatsLinkGenerator = ({github, options}) =>
31+
`https://github-readme-streak-stats.herokuapp.com/?user=${github}&${streakStatsStylingQueryString(options)}`

0 commit comments

Comments
 (0)