Skip to content

Commit 7ac0b6a

Browse files
committedDec 20, 2024
Fixed setting first category as default and Introduced new code format
·
v2.0.0v0.5.1
1 parent 71d65fd commit 7ac0b6a

File tree

9 files changed

+439
-51
lines changed

9 files changed

+439
-51
lines changed
 

‎CONTRIBUTING.md‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ Look for the categoryName where your snippet belongs.
3636
{
3737
"title": "Name of the snippet",
3838
"description": "A short explanation of what the snippet does",
39-
"code": "your code goes here",
39+
"code": [
40+
"your code goes here",
41+
" this is a newline with a space"
42+
],
4043
"tags": ["tag1", "tag2", "tag3"],
4144
"author": "your_github_username"
4245
}
@@ -53,7 +56,12 @@ Here’s an example for JavaScript:
5356
{
5457
"title": "Format Date",
5558
"description": "Formats a date in 'YYYY-MM-DD' format.",
56-
"code": "const formatDate = (date) => date.toISOString().split('T')[0];\n\n// Usage:\nconsole.log(formatDate(new Date())); // Output: '2024-12-10'",
59+
"code": [
60+
"const formatDate = (date) => date.toISOString().split('T')[0];",
61+
"",
62+
"// Usage:",
63+
"console.log(formatDate(new Date())); // Output: '2024-12-10'"
64+
],
5765
"tags": ["javascript", "date", "format"],
5866
"author": "technoph1le"
5967
}
@@ -76,7 +84,10 @@ Use this format:
7684
{
7785
"title": "Name of the snippet",
7886
"description": "A short explanation of what it does",
79-
"code": "your code goes here",
87+
"code": [
88+
"your code goes here",
89+
" this is a newline with a space"
90+
],
8091
"tags": ["tag1", "tag2", "tag3"],
8192
"author": "your_github_username"
8293
}

‎README.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ If you’d like to add a snippet for an **existing language** and **category**,
2626
```json
2727
{
2828
"title": "Name of the snippet",
29-
"description": "A brief description of what it does",
30-
"code": "code goes here",
29+
"description": "A short explanation of what the snippet does",
30+
"code": [
31+
"your code goes here",
32+
" this is a newline with a space"
33+
],
3134
"tags": ["tag1", "tag2", "tag3"],
3235
"author": "your_github_username"
3336
}

‎public/data/css.json‎

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
{
66
"title": "Responsive Font Sizing",
77
"description": "Adjusts font size based on viewport width.",
8-
"code": "h1 {\n font-size: calc(1.5rem + 2vw);\n}",
8+
"code": ["h1 {", " font-size: calc(1.5rem + 2vw);", "}"],
99
"tags": ["css", "font", "responsive", "typography"],
1010
"author": "dostonnabotov"
1111
},
1212
{
1313
"title": "Letter Spacing",
1414
"description": "Adds space between letters for better readability.",
15-
"code": "p {\n letter-spacing: 0.05em;\n}",
15+
"code": ["p {", " letter-spacing: 0.05em;", "}"],
1616
"tags": ["css", "typography", "spacing"],
1717
"author": "dostonnabotov"
1818
}
@@ -24,14 +24,34 @@
2424
{
2525
"title": "Sticky Footer",
2626
"description": "Ensures the footer always stays at the bottom of the page.",
27-
"code": "body {\n display: flex;\n flex-direction: column;\n min-height: 100vh;\n}\n\nfooter {\n margin-top: auto;\n}",
27+
"code": [
28+
"body {",
29+
" display: flex;",
30+
" flex-direction: column;",
31+
" min-height: 100vh;",
32+
"}",
33+
"",
34+
"footer {",
35+
" margin-top: auto;",
36+
"}"
37+
],
2838
"tags": ["css", "layout", "footer", "sticky"],
2939
"author": "dostonnabotov"
3040
},
3141
{
3242
"title": "Equal-Width Columns",
3343
"description": "Creates columns with equal widths using flexbox.",
34-
"code": ".columns {\n display: flex;\n justify-content: space-between;\n}\n\n.column {\n flex: 1;\n margin: 0 10px;\n}",
44+
"code": [
45+
".columns {",
46+
" display: flex;",
47+
" justify-content: space-between;",
48+
"}",
49+
"",
50+
".column {",
51+
" flex: 1;",
52+
" margin: 0 10px;",
53+
"}"
54+
],
3555
"tags": ["css", "flexbox", "columns", "layout"],
3656
"author": "dostonnabotov"
3757
}
@@ -43,14 +63,43 @@
4363
{
4464
"title": "Button Hover Effect",
4565
"description": "Creates a hover effect with a color transition.",
46-
"code": ".button {\n background-color: #007bff;\n color: white;\n padding: 10px 20px;\n border: none;\n border-radius: 5px;\n cursor: pointer;\n transition: background-color 0.3s ease;\n}\n\n.button:hover {\n background-color: #0056b3;\n}",
66+
"code": [
67+
".button {",
68+
" background-color: #007bff;",
69+
" color: white;",
70+
" padding: 10px 20px;",
71+
" border: none;",
72+
" border-radius: 5px;",
73+
" cursor: pointer;",
74+
" transition: background-color 0.3s ease;",
75+
"}",
76+
"",
77+
".button:hover {",
78+
" background-color: #0056b3;",
79+
"}"
80+
],
4781
"tags": ["css", "button", "hover", "transition"],
4882
"author": "dostonnabotov"
4983
},
5084
{
5185
"title": "3D Button Effect",
5286
"description": "Adds a 3D effect to a button when clicked.",
53-
"code": ".button {\n background-color: #28a745;\n color: white;\n padding: 10px 20px;\n border: none;\n border-radius: 5px;\n box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);\n transition: transform 0.1s;\n}\n\n.button:active {\n transform: translateY(2px);\n box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);\n}",
87+
"code": [
88+
".button {",
89+
" background-color: #28a745;",
90+
" color: white;",
91+
" padding: 10px 20px;",
92+
" border: none;",
93+
" border-radius: 5px;",
94+
" box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);",
95+
" transition: transform 0.1s;",
96+
"}",
97+
"",
98+
".button:active {",
99+
" transform: translateY(2px);",
100+
" box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);",
101+
"}"
102+
],
54103
"tags": ["css", "button", "3D", "effect"],
55104
"author": "dostonnabotov"
56105
}
@@ -62,14 +111,30 @@
62111
{
63112
"title": "Blur Background",
64113
"description": "Applies a blur effect to the background of an element.",
65-
"code": ".blur-background {\n backdrop-filter: blur(10px);\n background: rgba(255, 255, 255, 0.5);\n}",
114+
"code": [
115+
".blur-background {",
116+
" backdrop-filter: blur(10px);",
117+
" background: rgba(255, 255, 255, 0.5);",
118+
"}"
119+
],
66120
"tags": ["css", "blur", "background", "effects"],
67121
"author": "dostonnabotov"
68122
},
69123
{
70124
"title": "Hover Glow Effect",
71125
"description": "Adds a glowing effect on hover.",
72-
"code": ".glow {\n background-color: #f39c12;\n padding: 10px 20px;\n border-radius: 5px;\n transition: box-shadow 0.3s ease;\n}\n\n.glow:hover {\n box-shadow: 0 0 15px rgba(243, 156, 18, 0.8);\n}",
126+
"code": [
127+
".glow {",
128+
" background-color: #f39c12;",
129+
" padding: 10px 20px;",
130+
" border-radius: 5px;",
131+
" transition: box-shadow 0.3s ease;",
132+
"}",
133+
"",
134+
".glow:hover {",
135+
" box-shadow: 0 0 15px rgba(243, 156, 18, 0.8);",
136+
"}"
137+
],
73138
"tags": ["css", "hover", "glow", "effects"],
74139
"author": "dostonnabotov"
75140
}

‎public/data/javascript.json‎

Lines changed: 97 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,26 @@
55
{
66
"title": "Remove Duplicates",
77
"description": "Removes duplicate values from an array.",
8-
"code": "const removeDuplicates = (arr) => [...new Set(arr)];\n\n// Usage:\nconst numbers = [1, 2, 2, 3, 4, 4, 5];\nconsole.log(removeDuplicates(numbers)); // Output: [1, 2, 3, 4, 5]",
8+
"code": [
9+
"const removeDuplicates = (arr) => [...new Set(arr)];",
10+
"",
11+
"// Usage:",
12+
"const numbers = [1, 2, 2, 3, 4, 4, 5];",
13+
"console.log(removeDuplicates(numbers)); // Output: [1, 2, 3, 4, 5]"
14+
],
915
"tags": ["javascript", "array", "deduplicate", "utility"],
1016
"author": "dostonnabotov"
1117
},
1218
{
1319
"title": "Flatten Array",
1420
"description": "Flattens a multi-dimensional array.",
15-
"code": "const flattenArray = (arr) => arr.flat(Infinity);\n\n// Usage:\nconst nestedArray = [1, [2, [3, [4]]]];\nconsole.log(flattenArray(nestedArray)); // Output: [1, 2, 3, 4]",
21+
"code": [
22+
"const flattenArray = (arr) => arr.flat(Infinity);",
23+
"",
24+
"// Usage:",
25+
"const nestedArray = [1, [2, [3, [4]]]];",
26+
"console.log(flattenArray(nestedArray)); // Output: [1, 2, 3, 4]"
27+
],
1628
"tags": ["javascript", "array", "flatten", "utility"],
1729
"author": "dostonnabotov"
1830
}
@@ -24,14 +36,24 @@
2436
{
2537
"title": "Capitalize String",
2638
"description": "Capitalizes the first letter of a string.",
27-
"code": "const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);\n\n// Usage:\nconsole.log(capitalize('hello')); // Output: 'Hello'",
39+
"code": [
40+
"const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);",
41+
"",
42+
"// Usage:",
43+
"console.log(capitalize('hello')); // Output: 'Hello'"
44+
],
2845
"tags": ["javascript", "string", "capitalize", "utility"],
2946
"author": "dostonnabotov"
3047
},
3148
{
3249
"title": "Reverse String",
3350
"description": "Reverses the characters in a string.",
34-
"code": "const reverseString = (str) => str.split('').reverse().join('');\n\n// Usage:\nconsole.log(reverseString('hello')); // Output: 'olleh'",
51+
"code": [
52+
"const reverseString = (str) => str.split('').reverse().join('');",
53+
"",
54+
"// Usage:",
55+
"console.log(reverseString('hello')); // Output: 'olleh'"
56+
],
3557
"tags": ["javascript", "string", "reverse", "utility"],
3658
"author": "dostonnabotov"
3759
}
@@ -43,14 +65,29 @@
4365
{
4466
"title": "Format Date",
4567
"description": "Formats a date in 'YYYY-MM-DD' format.",
46-
"code": "const formatDate = (date) => date.toISOString().split('T')[0];\n\n// Usage:\nconsole.log(formatDate(new Date())); // Output: '2024-12-10'",
68+
"code": [
69+
"const formatDate = (date) => date.toISOString().split('T')[0];",
70+
"",
71+
"// Usage:",
72+
"console.log(formatDate(new Date())); // Output: '2024-12-10'"
73+
],
4774
"tags": ["javascript", "date", "format", "utility"],
4875
"author": "dostonnabotov"
4976
},
5077
{
5178
"title": "Get Time Difference",
5279
"description": "Calculates the time difference in days between two dates.",
53-
"code": "const getTimeDifference = (date1, date2) => {\n const diff = Math.abs(date2 - date1);\n return Math.ceil(diff / (1000 * 60 * 60 * 24));\n};\n\n// Usage:\nconst date1 = new Date('2024-01-01');\nconst date2 = new Date('2024-12-31');\nconsole.log(getTimeDifference(date1, date2)); // Output: 365",
80+
"code": [
81+
"const getTimeDifference = (date1, date2) => {",
82+
" const diff = Math.abs(date2 - date1);",
83+
" return Math.ceil(diff / (1000 * 60 * 60 * 24));",
84+
"};",
85+
"",
86+
"// Usage:",
87+
"const date1 = new Date('2024-01-01');",
88+
"const date2 = new Date('2024-12-31');",
89+
"console.log(getTimeDifference(date1, date2)); // Output: 365"
90+
],
5491
"tags": ["javascript", "date", "time-difference", "utility"],
5592
"author": "dostonnabotov"
5693
}
@@ -62,14 +99,48 @@
6299
{
63100
"title": "Debounce Function",
64101
"description": "Delays a function execution until after a specified time.",
65-
"code": "const debounce = (func, delay) => {\n let timeout;\n return (...args) => {\n clearTimeout(timeout);\n timeout = setTimeout(() => func(...args), delay);\n };\n};\n\n// Usage:\nwindow.addEventListener('resize', debounce(() => console.log('Resized!'), 500));",
102+
"code": [
103+
"const debounce = (func, delay) => {",
104+
" let timeout;",
105+
" return (...args) => {",
106+
" clearTimeout(timeout);",
107+
" timeout = setTimeout(() => func(...args), delay);",
108+
" };",
109+
"};",
110+
"",
111+
"// Usage:",
112+
"window.addEventListener('resize', debounce(() => console.log('Resized!'), 500));"
113+
],
66114
"tags": ["javascript", "utility", "debounce", "performance"],
67115
"author": "dostonnabotov"
68116
},
69117
{
70118
"title": "Throttle Function",
71119
"description": "Limits a function execution to once every specified time interval.",
72-
"code": "const throttle = (func, limit) => {\n let lastFunc;\n let lastRan;\n return (...args) => {\n const context = this;\n if (!lastRan) {\n func.apply(context, args);\n lastRan = Date.now();\n } else {\n clearTimeout(lastFunc);\n lastFunc = setTimeout(() => {\n if (Date.now() - lastRan >= limit) {\n func.apply(context, args);\n lastRan = Date.now();\n }\n }, limit - (Date.now() - lastRan));\n }\n };\n};\n\n// Usage:\ndocument.addEventListener('scroll', throttle(() => console.log('Scrolled!'), 1000));",
120+
"code": [
121+
"const throttle = (func, limit) => {",
122+
" let lastFunc;",
123+
" let lastRan;",
124+
" return (...args) => {",
125+
" const context = this;",
126+
" if (!lastRan) {",
127+
" func.apply(context, args);",
128+
" lastRan = Date.now();",
129+
" } else {",
130+
" clearTimeout(lastFunc);",
131+
" lastFunc = setTimeout(() => {",
132+
" if (Date.now() - lastRan >= limit) {",
133+
" func.apply(context, args);",
134+
" lastRan = Date.now();",
135+
" }",
136+
" }, limit - (Date.now() - lastRan));",
137+
" }",
138+
" };",
139+
"};",
140+
"",
141+
"// Usage:",
142+
"document.addEventListener('scroll', throttle(() => console.log('Scrolled!'), 1000));"
143+
],
73144
"tags": ["javascript", "utility", "throttle", "performance"],
74145
"author": "dostonnabotov"
75146
}
@@ -81,14 +152,30 @@
81152
{
82153
"title": "Toggle Class",
83154
"description": "Toggles a class on an element.",
84-
"code": "const toggleClass = (element, className) => {\n element.classList.toggle(className);\n};\n\n// Usage:\nconst element = document.querySelector('.my-element');\ntoggleClass(element, 'active');",
155+
"code": [
156+
"const toggleClass = (element, className) => {",
157+
" element.classList.toggle(className);",
158+
"};",
159+
"",
160+
"// Usage:",
161+
"const element = document.querySelector('.my-element');",
162+
"toggleClass(element, 'active');"
163+
],
85164
"tags": ["javascript", "dom", "class", "utility"],
86165
"author": "dostonnabotov"
87166
},
88167
{
89168
"title": "Smooth Scroll to Element",
90169
"description": "Scrolls smoothly to a specified element.",
91-
"code": "const smoothScroll = (element) => {\n element.scrollIntoView({ behavior: 'smooth' });\n};\n\n// Usage:\nconst target = document.querySelector('#target');\nsmoothScroll(target);",
170+
"code": [
171+
"const smoothScroll = (element) => {",
172+
" element.scrollIntoView({ behavior: 'smooth' });",
173+
"};",
174+
"",
175+
"// Usage:",
176+
"const target = document.querySelector('#target');",
177+
"smoothScroll(target);"
178+
],
92179
"tags": ["javascript", "dom", "scroll", "ui"],
93180
"author": "dostonnabotov"
94181
}

‎public/data/python.json‎

Lines changed: 95 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,27 @@
55
{
66
"title": "Reverse String",
77
"description": "Reverses the characters in a string.",
8-
"code": "def reverse_string(s):\n return s[::-1]\n\n# Usage:\nprint(reverse_string('hello')) # Output: 'olleh'",
8+
"code": [
9+
"def reverse_string(s):",
10+
" return s[::-1]",
11+
"",
12+
"# Usage:",
13+
"print(reverse_string('hello')) # Output: 'olleh'"
14+
],
915
"tags": ["python", "string", "reverse", "utility"],
1016
"author": "dostonnabotov"
1117
},
1218
{
1319
"title": "Check Palindrome",
1420
"description": "Checks if a string is a palindrome.",
15-
"code": "def is_palindrome(s):\n s = s.lower().replace(' ', '')\n return s == s[::-1]\n\n# Usage:\nprint(is_palindrome('A man a plan a canal Panama')) # Output: True",
21+
"code": [
22+
"def is_palindrome(s):",
23+
" s = s.lower().replace(' ', '')",
24+
" return s == s[::-1]",
25+
"",
26+
"# Usage:",
27+
"print(is_palindrome('A man a plan a canal Panama')) # Output: True"
28+
],
1629
"tags": ["python", "string", "palindrome", "utility"],
1730
"author": "dostonnabotov"
1831
}
@@ -24,14 +37,27 @@
2437
{
2538
"title": "Flatten Nested List",
2639
"description": "Flattens a multi-dimensional list into a single list.",
27-
"code": "def flatten_list(lst):\n return [item for sublist in lst for item in sublist]\n\n# Usage:\nnested_list = [[1, 2], [3, 4], [5]]\nprint(flatten_list(nested_list)) # Output: [1, 2, 3, 4, 5]",
40+
"code": [
41+
"def flatten_list(lst):",
42+
" return [item for sublist in lst for item in sublist]",
43+
"",
44+
"# Usage:",
45+
"nested_list = [[1, 2], [3, 4], [5]]",
46+
"print(flatten_list(nested_list)) # Output: [1, 2, 3, 4, 5]"
47+
],
2848
"tags": ["python", "list", "flatten", "utility"],
2949
"author": "dostonnabotov"
3050
},
3151
{
3252
"title": "Remove Duplicates",
3353
"description": "Removes duplicate elements from a list while maintaining order.",
34-
"code": "def remove_duplicates(lst):\n return list(dict.fromkeys(lst))\n\n# Usage:\nprint(remove_duplicates([1, 2, 2, 3, 4, 4, 5])) # Output: [1, 2, 3, 4, 5]",
54+
"code": [
55+
"def remove_duplicates(lst):",
56+
" return list(dict.fromkeys(lst))",
57+
"",
58+
"# Usage:",
59+
"print(remove_duplicates([1, 2, 2, 3, 4, 4, 5])) # Output: [1, 2, 3, 4, 5]"
60+
],
3561
"tags": ["python", "list", "duplicates", "utility"],
3662
"author": "dostonnabotov"
3763
}
@@ -43,14 +69,29 @@
4369
{
4470
"title": "Read File Lines",
4571
"description": "Reads all lines from a file and returns them as a list.",
46-
"code": "def read_file_lines(filepath):\n with open(filepath, 'r') as file:\n return file.readlines()\n\n# Usage:\nlines = read_file_lines('example.txt')\nprint(lines)",
72+
"code": [
73+
"def read_file_lines(filepath):",
74+
" with open(filepath, 'r') as file:",
75+
" return file.readlines()",
76+
"",
77+
"# Usage:",
78+
"lines = read_file_lines('example.txt')",
79+
"print(lines)"
80+
],
4781
"tags": ["python", "file", "read", "utility"],
4882
"author": "dostonnabotov"
4983
},
5084
{
5185
"title": "Write to File",
5286
"description": "Writes content to a file.",
53-
"code": "def write_to_file(filepath, content):\n with open(filepath, 'w') as file:\n file.write(content)\n\n# Usage:\nwrite_to_file('example.txt', 'Hello, World!')",
87+
"code": [
88+
"def write_to_file(filepath, content):",
89+
" with open(filepath, 'w') as file:",
90+
" file.write(content)",
91+
"",
92+
"# Usage:",
93+
"write_to_file('example.txt', 'Hello, World!')"
94+
],
5495
"tags": ["python", "file", "write", "utility"],
5596
"author": "dostonnabotov"
5697
}
@@ -62,14 +103,33 @@
62103
{
63104
"title": "Find Factorial",
64105
"description": "Calculates the factorial of a number.",
65-
"code": "def factorial(n):\n if n == 0:\n return 1\n return n * factorial(n - 1)\n\n# Usage:\nprint(factorial(5)) # Output: 120",
106+
"code": [
107+
"def factorial(n):",
108+
" if n == 0:",
109+
" return 1",
110+
" return n * factorial(n - 1)",
111+
"",
112+
"# Usage:",
113+
"print(factorial(5)) # Output: 120"
114+
],
66115
"tags": ["python", "math", "factorial", "utility"],
67116
"author": "dostonnabotov"
68117
},
69118
{
70119
"title": "Check Prime Number",
71120
"description": "Checks if a number is a prime number.",
72-
"code": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True\n\n# Usage:\nprint(is_prime(17)) # Output: True",
121+
"code": [
122+
"def is_prime(n):",
123+
" if n <= 1:",
124+
" return False",
125+
" for i in range(2, int(n**0.5) + 1):",
126+
" if n % i == 0:",
127+
" return False",
128+
" return True",
129+
"",
130+
"# Usage:",
131+
"print(is_prime(17)) # Output: True"
132+
],
73133
"tags": ["python", "math", "prime", "check"],
74134
"author": "dostonnabotov"
75135
}
@@ -81,14 +141,39 @@
81141
{
82142
"title": "Measure Execution Time",
83143
"description": "Measures the execution time of a code block.",
84-
"code": "import time\n\ndef measure_time(func, *args):\n start = time.time()\n result = func(*args)\n end = time.time()\n print(f'Execution time: {end - start:.6f} seconds')\n return result\n\n# Usage:\ndef slow_function():\n time.sleep(2)\n\nmeasure_time(slow_function)",
144+
"code": [
145+
"import time",
146+
"",
147+
"def measure_time(func, *args):",
148+
" start = time.time()",
149+
" result = func(*args)",
150+
" end = time.time()",
151+
" print(f'Execution time: {end - start:.6f} seconds')",
152+
" return result",
153+
"",
154+
"# Usage:",
155+
"def slow_function():",
156+
" time.sleep(2)",
157+
"",
158+
"measure_time(slow_function)"
159+
],
85160
"tags": ["python", "time", "execution", "utility"],
86161
"author": "dostonnabotov"
87162
},
88163
{
89164
"title": "Generate Random String",
90165
"description": "Generates a random alphanumeric string.",
91-
"code": "import random\nimport string\n\ndef random_string(length):\n letters_and_digits = string.ascii_letters + string.digits\n return ''.join(random.choice(letters_and_digits) for _ in range(length))\n\n# Usage:\nprint(random_string(10)) # Output: Random 10-character string",
166+
"code": [
167+
"import random",
168+
"import string",
169+
"",
170+
"def random_string(length):",
171+
" letters_and_digits = string.ascii_letters + string.digits",
172+
" return ''.join(random.choice(letters_and_digits) for _ in range(length))",
173+
"",
174+
"# Usage:",
175+
"print(random_string(10)) # Output: Random 10-character string"
176+
],
92177
"tags": ["python", "random", "string", "utility"],
93178
"author": "dostonnabotov"
94179
}

‎public/data/scss.json‎

Lines changed: 135 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,57 @@
55
{
66
"title": "Line Clamp Mixin",
77
"description": "A Sass mixin to clamp text to a specific number of lines.",
8-
"code": "@mixin line-clamp($number) {\n display: -webkit-box;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: $number;\n overflow: hidden;\n}",
8+
"code": [
9+
"@mixin line-clamp($number) {",
10+
" display: -webkit-box;",
11+
" -webkit-box-orient: vertical;",
12+
" -webkit-line-clamp: $number;",
13+
" overflow: hidden;",
14+
"}"
15+
],
916
"tags": ["sass", "mixin", "typography", "css"],
1017
"author": "dostonnabotov"
1118
},
1219
{
1320
"title": "Text Overflow Ellipsis",
1421
"description": "Ensures long text is truncated with an ellipsis.",
15-
"code": "@mixin text-ellipsis {\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n}",
22+
"code": [
23+
"@mixin text-ellipsis {",
24+
" overflow: hidden;",
25+
" white-space: nowrap;",
26+
" text-overflow: ellipsis;",
27+
"}"
28+
],
1629
"tags": ["sass", "mixin", "text", "css"],
1730
"author": "dostonnabotov"
1831
},
1932
{
2033
"title": "Font Import Helper",
2134
"description": "Simplifies importing custom fonts in Sass.",
22-
"code": "@mixin import-font($family, $weight: 400, $style: normal) {\n @font-face {\n font-family: #{$family};\n font-weight: #{$weight};\n font-style: #{$style};\n src: url('/fonts/#{$family}-#{$weight}.woff2') format('woff2'),\n url('/fonts/#{$family}-#{$weight}.woff') format('woff');\n }\n}",
35+
"code": [
36+
"@mixin import-font($family, $weight: 400, $style: normal) {",
37+
" @font-face {",
38+
" font-family: #{$family};",
39+
" font-weight: #{$weight};",
40+
" font-style: #{$style};",
41+
" src: url('/fonts/#{$family}-#{$weight}.woff2') format('woff2'),",
42+
" url('/fonts/#{$family}-#{$weight}.woff') format('woff');",
43+
" }",
44+
"}"
45+
],
2346
"tags": ["sass", "mixin", "fonts", "css"],
2447
"author": "dostonnabotov"
2548
},
2649
{
2750
"title": "Text Gradient",
2851
"description": "Adds a gradient color effect to text.",
29-
"code": "@mixin text-gradient($from, $to) {\n background: linear-gradient(to right, $from, $to);\n -webkit-background-clip: text;\n -webkit-text-fill-color: transparent;\n}",
52+
"code": [
53+
"@mixin text-gradient($from, $to) {",
54+
" background: linear-gradient(to right, $from, $to);",
55+
" -webkit-background-clip: text;",
56+
" -webkit-text-fill-color: transparent;",
57+
"}"
58+
],
3059
"tags": ["sass", "mixin", "gradient", "text", "css"],
3160
"author": "dostonnabotov"
3261
}
@@ -38,21 +67,46 @@
3867
{
3968
"title": "Grid Container",
4069
"description": "Creates a responsive grid container with customizable column counts.",
41-
"code": "@mixin grid-container($columns: 12, $gap: 1rem) {\n display: grid;\n grid-template-columns: repeat($columns, 1fr);\n gap: $gap;\n}",
70+
"code": [
71+
"@mixin grid-container($columns: 12, $gap: 1rem) {",
72+
" display: grid;",
73+
" grid-template-columns: repeat($columns, 1fr);",
74+
" gap: $gap;",
75+
"}"
76+
],
4277
"tags": ["scss", "grid", "layout", "css"],
4378
"author": "dostonnabotov"
4479
},
4580
{
4681
"title": "Flex Center",
4782
"description": "A mixin to center content using flexbox.",
48-
"code": "@mixin flex-center {\n display: flex;\n justify-content: center;\n align-items: center;\n}",
83+
"code": [
84+
"@mixin flex-center {",
85+
" display: flex;",
86+
" justify-content: center;",
87+
" align-items: center;",
88+
"}"
89+
],
4990
"tags": ["scss", "flex", "center", "css"],
5091
"author": "dostonnabotov"
5192
},
5293
{
5394
"title": "Aspect Ratio",
5495
"description": "Ensures elements maintain a specific aspect ratio.",
55-
"code": "@mixin aspect-ratio($width, $height) {\n position: relative;\n width: 100%;\n padding-top: ($height / $width) * 100%;\n > * {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n }\n}",
96+
"code": [
97+
"@mixin aspect-ratio($width, $height) {",
98+
" position: relative;",
99+
" width: 100%;",
100+
" padding-top: ($height / $width) * 100%;",
101+
" > * {",
102+
" position: absolute;",
103+
" top: 0;",
104+
" left: 0;",
105+
" width: 100%;",
106+
" height: 100%;",
107+
" }",
108+
"}"
109+
],
56110
"tags": ["scss", "aspect-ratio", "layout", "css"],
57111
"author": "dostonnabotov"
58112
}
@@ -64,14 +118,40 @@
64118
{
65119
"title": "Fade In Animation",
66120
"description": "Animates the fade-in effect.",
67-
"code": "@keyframes fade-in {\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n}\n\n@mixin fade-in($duration: 1s, $easing: ease-in-out) {\n animation: fade-in $duration $easing;\n}",
121+
"code": [
122+
"@keyframes fade-in {",
123+
" from {",
124+
" opacity: 0;",
125+
" }",
126+
" to {",
127+
" opacity: 1;",
128+
" }",
129+
"}",
130+
"",
131+
"@mixin fade-in($duration: 1s, $easing: ease-in-out) {",
132+
" animation: fade-in $duration $easing;",
133+
"}"
134+
],
68135
"tags": ["scss", "animation", "fade", "css"],
69136
"author": "dostonnabotov"
70137
},
71138
{
72139
"title": "Slide In From Left",
73140
"description": "Animates content sliding in from the left.",
74-
"code": "@keyframes slide-in-left {\n from {\n transform: translateX(-100%);\n }\n to {\n transform: translateX(0);\n }\n}\n\n@mixin slide-in-left($duration: 0.5s, $easing: ease-out) {\n animation: slide-in-left $duration $easing;\n}",
141+
"code": [
142+
"@keyframes slide-in-left {",
143+
" from {",
144+
" transform: translateX(-100%);",
145+
" }",
146+
" to {",
147+
" transform: translateX(0);",
148+
" }",
149+
"}",
150+
"",
151+
"@mixin slide-in-left($duration: 0.5s, $easing: ease-out) {",
152+
" animation: slide-in-left $duration $easing;",
153+
"}"
154+
],
75155
"tags": ["scss", "animation", "slide", "css"],
76156
"author": "dostonnabotov"
77157
}
@@ -83,14 +163,34 @@
83163
{
84164
"title": "Responsive Breakpoints",
85165
"description": "Generates media queries for responsive design.",
86-
"code": "@mixin breakpoint($breakpoint) {\n @if $breakpoint == sm {\n @media (max-width: 576px) { @content; }\n } @else if $breakpoint == md {\n @media (max-width: 768px) { @content; }\n } @else if $breakpoint == lg {\n @media (max-width: 992px) { @content; }\n } @else if $breakpoint == xl {\n @media (max-width: 1200px) { @content; }\n }\n}",
166+
"code": [
167+
"@mixin breakpoint($breakpoint) {",
168+
" @if $breakpoint == sm {",
169+
" @media (max-width: 576px) { @content; }",
170+
" } @else if $breakpoint == md {",
171+
" @media (max-width: 768px) { @content; }",
172+
" } @else if $breakpoint == lg {",
173+
" @media (max-width: 992px) { @content; }",
174+
" } @else if $breakpoint == xl {",
175+
" @media (max-width: 1200px) { @content; }",
176+
" }",
177+
"}"
178+
],
87179
"tags": ["scss", "responsive", "media-queries", "css"],
88180
"author": "dostonnabotov"
89181
},
90182
{
91183
"title": "Clearfix",
92184
"description": "Provides a clearfix utility for floating elements.",
93-
"code": "@mixin clearfix {\n &::after {\n content: '';\n display: block;\n clear: both;\n }\n}",
185+
"code": [
186+
"@mixin clearfix {",
187+
" &::after {",
188+
" content: '';",
189+
" display: block;",
190+
" clear: both;",
191+
" }",
192+
"}"
193+
],
94194
"tags": ["scss", "clearfix", "utility", "css"],
95195
"author": "dostonnabotov"
96196
}
@@ -102,14 +202,22 @@
102202
{
103203
"title": "Border Radius Helper",
104204
"description": "Applies a customizable border-radius.",
105-
"code": "@mixin border-radius($radius: 4px) {\n border-radius: $radius;\n}",
205+
"code": [
206+
"@mixin border-radius($radius: 4px) {",
207+
" border-radius: $radius;",
208+
"}"
209+
],
106210
"tags": ["scss", "border", "radius", "css"],
107211
"author": "dostonnabotov"
108212
},
109213
{
110214
"title": "Box Shadow Helper",
111215
"description": "Generates a box shadow with customizable values.",
112-
"code": "@mixin box-shadow($x: 0px, $y: 4px, $blur: 10px, $spread: 0px, $color: rgba(0, 0, 0, 0.1)) {\n box-shadow: $x $y $blur $spread $color;\n}",
216+
"code": [
217+
"@mixin box-shadow($x: 0px, $y: 4px, $blur: 10px, $spread: 0px, $color: rgba(0, 0, 0, 0.1)) {",
218+
" box-shadow: $x $y $blur $spread $color;",
219+
"}"
220+
],
113221
"tags": ["scss", "box-shadow", "css", "effects"],
114222
"author": "dostonnabotov"
115223
}
@@ -121,7 +229,20 @@
121229
{
122230
"title": "Primary Button",
123231
"description": "Generates a styled primary button.",
124-
"code": "@mixin primary-button($bg: #007bff, $color: #fff) {\n background-color: $bg;\n color: $color;\n padding: 0.5rem 1rem;\n border: none;\n border-radius: 4px;\n cursor: pointer;\n\n &:hover {\n background-color: darken($bg, 10%);\n }\n}",
232+
"code": [
233+
"@mixin primary-button($bg: #007bff, $color: #fff) {",
234+
" background-color: $bg;",
235+
" color: $color;",
236+
" padding: 0.5rem 1rem;",
237+
" border: none;",
238+
" border-radius: 4px;",
239+
" cursor: pointer;",
240+
"",
241+
" &:hover {",
242+
" background-color: darken($bg, 10%);",
243+
" }",
244+
"}"
245+
],
125246
"tags": ["scss", "button", "primary", "css"],
126247
"author": "dostonnabotov"
127248
}

‎src/components/CategoryList.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { useAppContext } from "../contexts/AppContext";
22
import { useCategories } from "../hooks/useCategories";
33

4+
let oldCategories = [] as string[];
5+
46
const CategoryList = () => {
57
const { category, setCategory } = useAppContext();
68
const { fetchedCategories, loading, error } = useCategories();
@@ -9,6 +11,15 @@ const CategoryList = () => {
911

1012
if (error) return <div>Error occured: {error}</div>;
1113

14+
// NOTE: set the first element as selected
15+
// switching between categories
16+
// Just a temporary solution.
17+
// If you've better solution, I would appreciate it :)
18+
if (oldCategories !== fetchedCategories) {
19+
setCategory(fetchedCategories[0]);
20+
oldCategories = fetchedCategories;
21+
}
22+
1223
return (
1324
<ul role="list" className="categories">
1425
{fetchedCategories.map((name, idx) => (

‎src/components/CodePreview.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@ import CopyToClipboard from "./CopyToClipboard";
44

55
type Props = {
66
language: string;
7-
children: string;
7+
children: string[];
88
};
99

1010
const CodePreview = ({ language = "markdown", children }: Props) => {
11+
const codeString = children.join("\n");
12+
1113
return (
1214
<div className="code-preview">
13-
<CopyToClipboard text={children} className="modal__copy" />
15+
<CopyToClipboard text={codeString} className="modal__copy" />
1416
<SyntaxHighlighter
1517
language={language}
1618
style={oneDark}
1719
wrapLines={true}
1820
customStyle={{ margin: "0" }}
1921
>
20-
{children}
22+
{codeString}
2123
</SyntaxHighlighter>
2224
</div>
2325
);

‎src/hooks/useCategories.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useFetch } from "./useFetch";
22
import { useAppContext } from "../contexts/AppContext";
33
import { SnippetType } from "../types";
44
import slugify from "../utils/slugify";
5+
import { useMemo } from "react";
56

67
type CategoryData = {
78
categoryName: string;
@@ -14,7 +15,9 @@ export const useCategories = () => {
1415
`/data/${slugify(language.lang)}.json`
1516
);
1617

17-
const fetchedCategories = data ? data.map((item) => item.categoryName) : [];
18+
const fetchedCategories = useMemo(() => {
19+
return data ? data.map((item) => item.categoryName) : [];
20+
}, [data]);
1821

1922
return { fetchedCategories, loading, error };
2023
};

0 commit comments

Comments
 (0)
Please sign in to comment.