Skip to content

Commit ace6e74

Browse files
authored
Merge pull request #259 from devsonket/release-3.0.0
Version Updated to Release 3.0.0
2 parents 703938a + 9d1ab0e commit ace6e74

85 files changed

Lines changed: 2433 additions & 2934 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ typings/
5353

5454
# dotenv environment variables file
5555
.env
56+
.env.*
5657

5758
# gatsby files
5859
.cache/

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.cache
2+
package.json
3+
package-lock.json
4+
public
5+
data

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"semi": false,
44
"singleQuote": false,
55
"tabWidth": 2,
6-
"trailingComma": "es5"
6+
"trailingComma": "es5",
7+
"editor.formatOnSave": true
78
}

gatsby-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = {
2525
background_color: `#663399`,
2626
theme_color: `#333`,
2727
display: `minimal-ui`,
28-
icon: `src/images/devsonket-icon.png`,
28+
icon: `src/assets/images/devsonket-icon.png`,
2929
},
3030
},
3131
{

gatsby-node.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
const path = require("path")
2+
const axios = require("axios")
3+
4+
const contributorMap = require("./scripts/contributorMap")
5+
6+
require("dotenv").config({
7+
path: `.env.${process.env.NODE_ENV}`,
8+
})
29

310
exports.createPages = ({ actions, graphql }) => {
411
const { createPage } = actions
5-
const postTemplate = path.resolve("src/templates/cheatsheet.js")
6-
const printTemplate = path.resolve("src/templates/printsheet.js")
12+
const postTemplate = path.resolve("src/templates/CheatSheet.js")
13+
const printTemplate = path.resolve("src/templates/PrintSheet.js")
14+
15+
let contributors = {}
16+
717
return new Promise((resolve, reject) => {
818
graphql(`
919
query {
@@ -22,10 +32,23 @@ exports.createPages = ({ actions, graphql }) => {
2232
}
2333
}
2434
}
25-
`).then(res => {
35+
`).then(async res => {
2636
if (res.errors) {
2737
return Promise.reject(res.errors)
2838
}
39+
const edges = res.data.allFile.edges
40+
for (let i = 0; i < edges.length; i++) {
41+
const filename = edges[i].node.name
42+
const { data: contributorsRaw } = await axios.get(
43+
`https://api.github.com/repos/devsonket/devsonket.github.io/commits?path=data/${filename}.json`,
44+
{
45+
headers: {
46+
Authorization: `Bearer ${process.env.GATSBY_GITHUB_TOKEN}`,
47+
},
48+
}
49+
)
50+
contributors[filename] = contributorMap(contributorsRaw)
51+
}
2952
res.data.allFile.edges.map(({ node }) => {
3053
const filename = node.name
3154
const data = require(`${__dirname}/data/${filename}`)
@@ -36,6 +59,7 @@ exports.createPages = ({ actions, graphql }) => {
3659
id: `${data.id}`,
3760
data,
3861
filename,
62+
contributors: contributors[filename],
3963
},
4064
})
4165
createPage({
@@ -45,6 +69,7 @@ exports.createPages = ({ actions, graphql }) => {
4569
id: `${data.id}`,
4670
data,
4771
filename,
72+
contributors: contributors[filename],
4873
},
4974
})
5075
resolve()

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
"gatsby-source-filesystem": "^2.0.37",
1919
"gatsby-transformer-sharp": "^2.1.20",
2020
"prop-types": "^15.7.2",
21+
"puppeteer": "^2.0.0",
2122
"react": "^16.8.6",
2223
"react-dom": "^16.8.6",
2324
"react-ga": "^2.7.0",
24-
"react-helmet": "^5.2.1"
25+
"react-helmet": "^5.2.1",
26+
"react-icons": "^3.9.0",
27+
"react-masonry-css": "^1.0.14"
2528
},
2629
"devDependencies": {
2730
"husky": "^2.4.1",
@@ -37,7 +40,8 @@
3740
],
3841
"license": "MIT",
3942
"scripts": {
40-
"build": "gatsby build",
43+
"build": "npm run thumbnail && gatsby build",
44+
"thumbnail": "cd scripts && node thumbnail.js",
4145
"develop": "gatsby develop",
4246
"format": "prettier --write src/**/*.{js,jsx}",
4347
"start": "npm run develop",

scripts/contributorMap.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = data => {
2+
const charMap = {}
3+
data.forEach(oneData => {
4+
if (oneData.author) {
5+
const { login } = oneData.author
6+
if (!charMap[login]) {
7+
charMap[login] = {
8+
count: 1,
9+
login: oneData.author.login,
10+
name: oneData.commit.author.name,
11+
avatar_url: oneData.author.avatar_url,
12+
html_url: oneData.author.html_url,
13+
}
14+
} else {
15+
charMap[login].count++
16+
}
17+
}
18+
})
19+
return charMap
20+
}

scripts/isItDark.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module.exports = color => {
2+
// Variables for red, green, blue values
3+
var r, g, b, hsp
4+
5+
// Check the format of the color, HEX or RGB?
6+
if (color.match(/^rgb/)) {
7+
// If HEX --> store the red, green, blue values in separate variables
8+
color = color.match(
9+
/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/
10+
)
11+
12+
r = color[1]
13+
g = color[2]
14+
b = color[3]
15+
} else {
16+
// If RGB --> Convert it to HEX: http://gist.github.com/983661
17+
color = +("0x" + color.slice(1).replace(color.length < 5 && /./g, "$&$&"))
18+
19+
r = color >> 16
20+
g = (color >> 8) & 255
21+
b = color & 255
22+
}
23+
24+
// HSP (Highly Sensitive Poo) equation from http://alienryderflex.com/hsp.html
25+
hsp = Math.sqrt(0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b))
26+
27+
// Using the HSP value, determine whether the color is light or dark
28+
if (hsp > 127.5) {
29+
return false
30+
} else {
31+
return true
32+
}
33+
}

scripts/thumbnail.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
const fs = require("fs")
2+
const puppeteer = require("puppeteer")
3+
4+
const isItDark = require("./isItDark")
5+
6+
const filesRaw = []
7+
const workingFolder = "../data/"
8+
const files = fs.readdirSync(workingFolder)
9+
10+
files.forEach(file => {
11+
if (file.endsWith(".json")) {
12+
const data = require(`../data/${file}`)
13+
filesRaw.push({ id: data.id, title: data.title, color: data.colorPref })
14+
}
15+
})
16+
17+
const main = async () => {
18+
const browser = await puppeteer.launch()
19+
20+
browser.on("disconnected", () => {
21+
return 0
22+
})
23+
24+
const page = await browser.newPage()
25+
26+
await page.setViewport({
27+
width: 1200,
28+
height: 630,
29+
deviceScaleFactor: 1,
30+
})
31+
32+
for (let i = 0; i < filesRaw.length; i++) {
33+
const imgHTML = `
34+
<!DOCTYPE html>
35+
<html lang="en">
36+
<head>
37+
<meta charset="UTF-8" />
38+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
39+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
40+
<title>HTML to Generate Thumbnail</title>
41+
<style>
42+
@font-face {
43+
font-family: "Hind Siliguri";
44+
src: url("./src/assets/fonts/HindSiliguri-Light.woff2") format("woff2"),
45+
url("./src/assets/fonts/HindSiliguri-Light.woff") format("woff");
46+
font-weight: 300;
47+
font-style: normal;
48+
}
49+
50+
@font-face {
51+
font-family: "Hind Siliguri";
52+
src: url("./src/assets/fonts/HindSiliguri-Regular.woff2") format("woff2"),
53+
url("./src/assets/fonts/HindSiliguri-Regular.woff") format("woff");
54+
font-weight: 400;
55+
font-style: normal;
56+
}
57+
58+
@font-face {
59+
font-family: "Hind Siliguri";
60+
src: url("./src/assets/fonts/HindSiliguri-Bold.woff2") format("woff2"),
61+
url("./src/assets/fonts/HindSiliguri-Bold.woff") format("woff");
62+
font-weight: 800;
63+
font-style: normal;
64+
}
65+
66+
* {
67+
margin: 0;
68+
padding: 0;
69+
box-sizing: border-box;
70+
}
71+
72+
body {
73+
font-family: "Hind Siliguri";
74+
background: ${filesRaw[i].color};
75+
color: ${isItDark(filesRaw[i].color) ? "#fffeff" : "#201f22"}
76+
}
77+
</style>
78+
</head>
79+
<body>
80+
<div
81+
style="height: 100vh; width: 100vw; display: flex; flex-direction: column; align-items: center; justify-content: space-evenly"
82+
>
83+
<div style="font-size: 36px; font-weight: bold;">
84+
<span
85+
style="display:inline-block; background-color: ${
86+
isItDark(filesRaw[i].color) ? "#fffeff" : "#201f22"
87+
}; color: ${
88+
filesRaw[i].color
89+
}; padding: 0 8px; border-radius: 4px; margin-right: 5px;"
90+
>ডেভ</span
91+
>সংকেত
92+
</div>
93+
<div style="text-align: center; padding: 0 120px;">
94+
<h2 style="font-size: 72px; line-height: 78px;">${
95+
filesRaw[i].title
96+
}</h2>
97+
<p style="font-size: 22px;">বাংলা ডেভেলপার চিটশিট</p>
98+
</div>
99+
<pre style="font-family: consolas; font-weight: bold; font-size: 26px;">
100+
https://devsonket.com/${filesRaw[i].id}</pre
101+
>
102+
</div>
103+
</body>
104+
</html>
105+
`
106+
await page.setContent(imgHTML)
107+
await page.screenshot({
108+
type: "jpeg",
109+
path: `../static/static/thumbnail/${filesRaw[i].id}.jpg`,
110+
quality: 85,
111+
})
112+
}
113+
await browser.close()
114+
}
115+
116+
main()
121 KB
Binary file not shown.

0 commit comments

Comments
 (0)