Skip to content

Commit 4766bc0

Browse files
authored
Make website responsive (#18)
1 parent 52cf340 commit 4766bc0

34 files changed

+613
-410
lines changed

.eslintrc.js

+33-50
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,54 @@
11
module.exports = {
2-
"env": {
3-
"browser": true,
4-
"es2021": true,
2+
env: {
3+
browser: true,
4+
es2021: true,
55
},
6-
"extends": [
6+
extends: [
77
"eslint:recommended",
88
"plugin:@typescript-eslint/recommended",
99
"plugin:react/recommended",
10-
"next/core-web-vitals"
10+
"next/core-web-vitals",
1111
],
12-
"overrides": [
12+
overrides: [
1313
{
14-
"env": {
15-
"node": true
14+
env: {
15+
node: true,
16+
},
17+
files: [".eslintrc.{js,cjs}"],
18+
parserOptions: {
19+
sourceType: "script",
1620
},
17-
"files": [
18-
".eslintrc.{js,cjs}"
19-
],
20-
"parserOptions": {
21-
"sourceType": "script"
22-
}
2321
},
2422
{
25-
"env": {
26-
"node": true,
27-
"es2021": false,
28-
"amd": true
23+
env: {
24+
node: true,
25+
es2021: false,
26+
amd: true,
2927
},
30-
"files": [
31-
"generateAssets.js"
32-
],
33-
"rules": {
28+
files: ["generateAssets.js"],
29+
rules: {
3430
"no-require-imports": "off",
35-
"@typescript-eslint/no-var-requires": "off"
36-
}
37-
}
31+
"@typescript-eslint/no-var-requires": "off",
32+
},
33+
},
3834
],
39-
"parser": "@typescript-eslint/parser",
40-
"parserOptions": {
41-
"ecmaVersion": "latest",
42-
"sourceType": "module"
35+
parser: "@typescript-eslint/parser",
36+
parserOptions: {
37+
ecmaVersion: "latest",
38+
sourceType: "module",
4339
},
44-
"plugins": [
45-
"@typescript-eslint",
46-
"react",
47-
"import"
48-
],
49-
"rules": {
50-
"quotes": [
51-
"error",
52-
"double"
53-
],
54-
"semi": [
55-
"error",
56-
"always"
57-
],
40+
plugins: ["@typescript-eslint", "react", "import"],
41+
rules: {
42+
quotes: ["error", "double"],
43+
semi: ["error", "always"],
5844
"no-multiple-empty-lines": [
5945
"error",
6046
{
61-
max: 1
62-
}
47+
max: 1,
48+
},
6349
],
6450
"react/react-in-jsx-scope": "off",
6551
"import/newline-after-import": "error",
66-
"padding-line-between-statements": [
67-
"error",
68-
{ "blankLine": "always", "prev": "if", "next": "*" }
69-
]
70-
}
52+
"padding-line-between-statements": ["error", { blankLine: "always", prev: "if", next: "*" }],
53+
},
7154
};

.prettierrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"printWidth": 100
2+
"printWidth": 120
33
}

generateAssets.js

+83-80
Original file line numberDiff line numberDiff line change
@@ -4,112 +4,115 @@ const { createTokenAuth } = require("@octokit/auth-token");
44
const sharp = require("sharp");
55

66
const fullLogo = {
7-
light: "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Long.svg",
8-
dark: "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Long-Inverted.svg"
7+
light: "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Long.svg",
8+
dark: "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Long-Inverted.svg",
99
};
1010
const shortLogo = {
11-
light: "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Short.svg",
12-
dark: "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Short-Inverted.svg"
11+
light: "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Short.svg",
12+
dark: "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Short-Inverted.svg",
1313
};
1414
const githubLogo = {
15-
light: "prebuild_assets/github-mark.svg",
16-
dark: "prebuild_assets/github-mark-white.svg"
15+
light: "prebuild_assets/github-mark.svg",
16+
dark: "prebuild_assets/github-mark-white.svg",
1717
};
1818
const emojis = [];
1919

2020
async function main() {
21-
if (!fs.existsSync("public/generated")) {
22-
fs.mkdirSync("public/generated", { recursive: true });
23-
}
21+
if (!fs.existsSync("public/generated")) {
22+
fs.mkdirSync("public/generated", { recursive: true });
23+
}
2424

25-
await downloadThemedImage(fullLogo, "public/generated/Logo-Long.svg", true);
26-
await downloadThemedImage(shortLogo, "public/generated/Logo-Short.svg", true);
27-
await downloadThemedImage(githubLogo, "public/generated/github-logo.svg", false);
28-
await downloadAndConvertSvgToPng("https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Short-Inverted-Outline.svg", "public/generated/Logo-Short-Inverted-Outline.png");
29-
await download("https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Derpy-Outlined.svg", "public/generated/derpy.svg");
30-
emojis.push("derpy");
31-
let octokit;
32-
if (process.env.GITHUB_TOKEN !== undefined && process.env.GITHUB_TOKEN.length > 0) {
33-
const auth = createTokenAuth(process.env.GITHUB_TOKEN);
34-
const authentication = await auth();
35-
octokit = new Octokit({
36-
auth: authentication.token
37-
});
38-
} else {
39-
octokit = new Octokit();
40-
}
41-
42-
const response = await octokit.repos.getContent({
43-
owner: "Draco-lang",
44-
repo: "Language-suggestions",
45-
path: "Resources/Emojis"
25+
await downloadThemedImage(fullLogo, "public/generated/Logo-Long.svg", true);
26+
await downloadThemedImage(shortLogo, "public/generated/Logo-Short.svg", true);
27+
await downloadThemedImage(githubLogo, "public/generated/github-logo.svg", false);
28+
await downloadAndConvertSvgToPng(
29+
"https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Short-Inverted-Outline.svg",
30+
"public/generated/Logo-Short-Inverted-Outline.png"
31+
);
32+
await download(
33+
"https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Derpy-Outlined.svg",
34+
"public/generated/derpy.svg"
35+
);
36+
emojis.push("derpy");
37+
let octokit;
38+
if (process.env.GITHUB_TOKEN !== undefined && process.env.GITHUB_TOKEN.length > 0) {
39+
const auth = createTokenAuth(process.env.GITHUB_TOKEN);
40+
const authentication = await auth();
41+
octokit = new Octokit({
42+
auth: authentication.token,
4643
});
44+
} else {
45+
octokit = new Octokit();
46+
}
4747

48-
const promises = response.data.map(async element => {
49-
console.log(`Downloading ${element.name}...`);
50-
const resp = await fetch(element.download_url);
51-
const emoji = await resp.text();
52-
await fs.promises.writeFile(`public/generated/${element.name}`, emoji);
53-
});
54-
await Promise.all(promises);
48+
const response = await octokit.repos.getContent({
49+
owner: "Draco-lang",
50+
repo: "Language-suggestions",
51+
path: "Resources/Emojis",
52+
});
5553

56-
response.data
57-
.map(s => s.name.replace(/\.[^/.]+$/, ""))
58-
.forEach(s => emojis.push(s));
59-
await fs.promises.writeFile(
60-
"src/generated/emojiTypes.ts",
61-
`export type EmojiName = ${emojis.map(s => `"${s}"`).join(" | ")};`
62-
);
54+
const promises = response.data.map(async (element) => {
55+
console.log(`Downloading ${element.name}...`);
56+
const resp = await fetch(element.download_url);
57+
const emoji = await resp.text();
58+
await fs.promises.writeFile(`public/generated/${element.name}`, emoji);
59+
});
60+
await Promise.all(promises);
61+
62+
response.data.map((s) => s.name.replace(/\.[^/.]+$/, "")).forEach((s) => emojis.push(s));
63+
await fs.promises.writeFile(
64+
"src/generated/emojiTypes.ts",
65+
`export type EmojiName = ${emojis.map((s) => `"${s}"`).join(" | ")};`
66+
);
6367
}
6468
main();
6569

6670
async function download(url, path) {
67-
const resp = await fetch(url);
68-
const text = await resp.text();
69-
await fs.promises.writeFile(path, text);
71+
const resp = await fetch(url);
72+
const text = await resp.text();
73+
await fs.promises.writeFile(path, text);
7074
}
7175

7276
async function downloadThemedImage(urls, outputPath, isUrl) {
73-
const svg = await createThemeBasedLogo(urls.light, urls.dark, isUrl);
74-
await fs.promises.writeFile(outputPath, svg);
75-
console.log(`Image downloaded and saved as ${outputPath}`);
77+
const svg = await createThemeBasedLogo(urls.light, urls.dark, isUrl);
78+
await fs.promises.writeFile(outputPath, svg);
79+
console.log(`Image downloaded and saved as ${outputPath}`);
7680
}
7781

7882
function stripXMLHeader(xml) {
79-
const regex = /<\??xml[^>]*>/;
80-
return xml.replace(regex, "");
83+
const regex = /<\??xml[^>]*>/;
84+
return xml.replace(regex, "");
8185
}
8286

8387
function stripViewBox(xml) {
84-
const regex = /viewBox="[^"]*"/;
85-
return xml.replace(regex, "");
88+
const regex = /viewBox="[^"]*"/;
89+
return xml.replace(regex, "");
8690
}
8791

8892
function extractOpeningSvgTag(svgContent) {
89-
const openingSvgTagRegex = /<svg\b[^>]*>/;
90-
const openingSvgTagMatch = svgContent.match(openingSvgTagRegex);
91-
return openingSvgTagMatch ? openingSvgTagMatch[0] : "<svg xmlns=\"http://www.w3.org/2000/svg\">";
93+
const openingSvgTagRegex = /<svg\b[^>]*>/;
94+
const openingSvgTagMatch = svgContent.match(openingSvgTagRegex);
95+
return openingSvgTagMatch ? openingSvgTagMatch[0] : '<svg xmlns="http://www.w3.org/2000/svg">';
9296
}
9397

9498
async function createThemeBasedLogo(lightUrl, darkUrl, isUrl) {
95-
let bodyLight, bodyDark;
96-
if (isUrl) {
97-
const responseLight = await fetch(lightUrl);
98-
const responseDark = await fetch(darkUrl);
99-
bodyLight = await responseLight.text();
100-
bodyDark = await responseDark.text();
101-
} else {
102-
bodyLight = await fs.promises.readFile(lightUrl, "utf-8");
103-
bodyDark = await fs.promises.readFile(darkUrl, "utf-8");
104-
}
99+
let bodyLight, bodyDark;
100+
if (isUrl) {
101+
const responseLight = await fetch(lightUrl);
102+
const responseDark = await fetch(darkUrl);
103+
bodyLight = await responseLight.text();
104+
bodyDark = await responseDark.text();
105+
} else {
106+
bodyLight = await fs.promises.readFile(lightUrl, "utf-8");
107+
bodyDark = await fs.promises.readFile(darkUrl, "utf-8");
108+
}
105109

106-
let logoLight = stripXMLHeader(bodyLight);
107-
logoLight = stripViewBox(logoLight);
108-
let logoDark = stripXMLHeader(bodyDark);
109-
logoDark = stripViewBox(logoDark);
110-
const openingSvgTag = extractOpeningSvgTag(bodyLight);
111-
const logoSvg =
112-
`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
110+
let logoLight = stripXMLHeader(bodyLight);
111+
logoLight = stripViewBox(logoLight);
112+
let logoDark = stripXMLHeader(bodyDark);
113+
logoDark = stripViewBox(logoDark);
114+
const openingSvgTag = extractOpeningSvgTag(bodyLight);
115+
const logoSvg = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
113116
${openingSvgTag}
114117
<style>
115118
@media (prefers-color-scheme: dark) {
@@ -132,12 +135,12 @@ ${logoLight}
132135
</g>
133136
</svg>
134137
`;
135-
return logoSvg;
138+
return logoSvg;
136139
}
137140

138141
async function downloadAndConvertSvgToPng(url, outputPath) {
139-
const resp = await fetch(url);
140-
const svgContent = await resp.text();
141-
await sharp(Buffer.from(svgContent)).png().toFile(outputPath);
142-
console.log(`SVG converted and saved as ${outputPath}`);
143-
}
142+
const resp = await fetch(url);
143+
const svgContent = await resp.text();
144+
await sharp(Buffer.from(svgContent)).png().toFile(outputPath);
145+
console.log(`SVG converted and saved as ${outputPath}`);
146+
}

next.config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
/** @type {import('next').NextConfig} */
44
const nextConfig = {
5-
output: "export",
6-
images: {
7-
unoptimized: true,
8-
}
5+
output: "export",
6+
images: {
7+
unoptimized: true,
8+
},
99
};
1010

1111
module.exports = nextConfig;

0 commit comments

Comments
 (0)