From 3d76aefc32c9f59a62ed5d98454593642ecad035 Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Fri, 2 Aug 2024 14:00:37 +0300
Subject: [PATCH 01/31] Categories
---
src/db/codesnippets/categories.json | 106 ++++++++++++++++++++++++++++
1 file changed, 106 insertions(+)
create mode 100644 src/db/codesnippets/categories.json
diff --git a/src/db/codesnippets/categories.json b/src/db/codesnippets/categories.json
new file mode 100644
index 00000000..c7ffffcb
--- /dev/null
+++ b/src/db/codesnippets/categories.json
@@ -0,0 +1,106 @@
+{
+ "languages": [
+ {
+ "name": "JavaScript",
+ "icon": "https://example.com/javascript-icon.png",
+ "description": "JavaScript is a versatile, high-level programming language primarily used for web development.",
+ "librariesFrameworks": [
+ "React",
+ "Angular",
+ "Vue.js",
+ "Node.js",
+ "Express"
+ ]
+ },
+ {
+ "name": "Python",
+ "icon": "https://example.com/python-icon.png",
+ "description": "Python is a high-level, interpreted programming language known for its readability and versatility.",
+ "librariesFrameworks": [
+ "Django",
+ "Flask",
+ "Pandas",
+ "NumPy",
+ "TensorFlow"
+ ]
+ },
+ {
+ "name": "Java",
+ "icon": "https://example.com/java-icon.png",
+ "description": "Java is a high-level, class-based programming language designed for portability and cross-platform compatibility.",
+ "librariesFrameworks": ["Spring", "Hibernate", "Maven", "JUnit", "Struts"]
+ },
+ {
+ "name": "C#",
+ "icon": "https://example.com/csharp-icon.png",
+ "description": "C# is a modern, object-oriented programming language developed by Microsoft, widely used for developing Windows applications.",
+ "librariesFrameworks": [
+ "ASP.NET",
+ "Entity Framework",
+ "Xamarin",
+ "Unity",
+ "NUnit"
+ ]
+ },
+ {
+ "name": "Ruby",
+ "icon": "https://example.com/ruby-icon.png",
+ "description": "Ruby is a dynamic, open-source programming language with a focus on simplicity and productivity.",
+ "librariesFrameworks": [
+ "Ruby on Rails",
+ "Sinatra",
+ "RSpec",
+ "Capybara",
+ "Puma"
+ ]
+ },
+ {
+ "name": "PHP",
+ "icon": "https://example.com/php-icon.png",
+ "description": "PHP is a widely-used open-source scripting language that is especially suited for web development and can be embedded into HTML.",
+ "librariesFrameworks": [
+ "Laravel",
+ "Symfony",
+ "CodeIgniter",
+ "Zend Framework",
+ "Phalcon"
+ ]
+ },
+ {
+ "name": "TypeScript",
+ "icon": "https://example.com/typescript-icon.png",
+ "description": "TypeScript is a strongly typed, open-source programming language that builds on JavaScript, giving you better tooling at any scale.",
+ "librariesFrameworks": ["Angular", "NestJS", "TypeORM", "RxJS", "ts-node"]
+ },
+ {
+ "name": "Swift",
+ "icon": "https://example.com/swift-icon.png",
+ "description": "Swift is a powerful and intuitive programming language for iOS, iPadOS, macOS, watchOS, and tvOS.",
+ "librariesFrameworks": [
+ "SwiftUI",
+ "Combine",
+ "Vapor",
+ "Kitura",
+ "RxSwift"
+ ]
+ },
+ {
+ "name": "Go",
+ "icon": "https://example.com/go-icon.png",
+ "description": "Go is an open-source programming language designed for simplicity, reliability, and efficiency.",
+ "librariesFrameworks": ["Gin", "Echo", "Beego", "Buffalo", "Gorm"]
+ },
+ {
+ "name": "Kotlin",
+ "icon": "https://example.com/kotlin-icon.png",
+ "description": "Kotlin is a modern, statically typed programming language that boosts productivity and is fully interoperable with Java.",
+ "librariesFrameworks": [
+ "Spring",
+ "Ktor",
+ "Exposed",
+ "Koin",
+ "Jetpack Compose"
+ ]
+ }
+ ]
+}
From 24eb99c2389a8b2a080768f2ae09791d99575df7 Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Fri, 2 Aug 2024 14:06:52 +0300
Subject: [PATCH 02/31] Categories
---
src/app/api/cs/route.js | 8 ++++++++
1 file changed, 8 insertions(+)
create mode 100644 src/app/api/cs/route.js
diff --git a/src/app/api/cs/route.js b/src/app/api/cs/route.js
new file mode 100644
index 00000000..01a4846a
--- /dev/null
+++ b/src/app/api/cs/route.js
@@ -0,0 +1,8 @@
+import categoris from "@/db/codesnippets/categories.json";
+import { NextResponse } from "next/server";
+
+export async function GET(req) {
+ const response = NextResponse.json(categoris, { status: 200 });
+ response.headers.set("Cache-Control", "public, max-age=3600"); // Cache for 1 hour
+ return response;
+}
From 34a0618f0c3a0a89cb278158414a16a6fdb9552e Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Sun, 4 Aug 2024 13:00:28 +0300
Subject: [PATCH 03/31] Tool page
---
src/app/cs/page.jsx | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
create mode 100644 src/app/cs/page.jsx
diff --git a/src/app/cs/page.jsx b/src/app/cs/page.jsx
new file mode 100644
index 00000000..10e2ef0c
--- /dev/null
+++ b/src/app/cs/page.jsx
@@ -0,0 +1,27 @@
+"use client"
+import { useState, useEffect } from "react"
+import { NavBar } from "../components/navbar";
+
+export default function CodingSnippets(){
+ const [isDarkMode, setIsDarkMode] = useState(false)
+ // Toggle theme and save preference in localStorage
+ const toggleTheme = () => {
+ const newTheme = !isDarkMode;
+ setIsDarkMode(newTheme);
+ localStorage.setItem("theme", JSON.stringify(newTheme));
+ };
+ useEffect(() => {
+ const storedTheme = JSON.parse(localStorage.getItem("theme"));
+ if (storedTheme !== null) {
+ setIsDarkMode(storedTheme);
+ }
+ }, []);
+ return(
+
+
+
+
+ )
+}
\ No newline at end of file
From c406595adb17911dec7ccce91107352b504f12ae Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Mon, 5 Aug 2024 12:51:36 +0300
Subject: [PATCH 04/31] New Tool
---
src/db/tools.json | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/db/tools.json b/src/db/tools.json
index 8981b7df..e0014330 100644
--- a/src/db/tools.json
+++ b/src/db/tools.json
@@ -107,5 +107,11 @@
"link": "/convert/img-svg",
"ctg": "other"
}
-
+ ,
+ {
+ "id": 19,
+ "name": "Coding Snippets",
+ "link": "/cs",
+ "ctg": "other"
+ }
]
From 14cb2950dbf3eb86ab6e3a29891cf62a32600f4d Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Mon, 5 Aug 2024 14:41:45 +0300
Subject: [PATCH 05/31] Removed Icons
---
src/db/codesnippets/categories.json | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/src/db/codesnippets/categories.json b/src/db/codesnippets/categories.json
index c7ffffcb..0d182c18 100644
--- a/src/db/codesnippets/categories.json
+++ b/src/db/codesnippets/categories.json
@@ -2,7 +2,6 @@
"languages": [
{
"name": "JavaScript",
- "icon": "https://example.com/javascript-icon.png",
"description": "JavaScript is a versatile, high-level programming language primarily used for web development.",
"librariesFrameworks": [
"React",
@@ -14,7 +13,6 @@
},
{
"name": "Python",
- "icon": "https://example.com/python-icon.png",
"description": "Python is a high-level, interpreted programming language known for its readability and versatility.",
"librariesFrameworks": [
"Django",
@@ -26,13 +24,11 @@
},
{
"name": "Java",
- "icon": "https://example.com/java-icon.png",
"description": "Java is a high-level, class-based programming language designed for portability and cross-platform compatibility.",
"librariesFrameworks": ["Spring", "Hibernate", "Maven", "JUnit", "Struts"]
},
{
"name": "C#",
- "icon": "https://example.com/csharp-icon.png",
"description": "C# is a modern, object-oriented programming language developed by Microsoft, widely used for developing Windows applications.",
"librariesFrameworks": [
"ASP.NET",
@@ -44,7 +40,6 @@
},
{
"name": "Ruby",
- "icon": "https://example.com/ruby-icon.png",
"description": "Ruby is a dynamic, open-source programming language with a focus on simplicity and productivity.",
"librariesFrameworks": [
"Ruby on Rails",
@@ -56,7 +51,6 @@
},
{
"name": "PHP",
- "icon": "https://example.com/php-icon.png",
"description": "PHP is a widely-used open-source scripting language that is especially suited for web development and can be embedded into HTML.",
"librariesFrameworks": [
"Laravel",
@@ -68,13 +62,11 @@
},
{
"name": "TypeScript",
- "icon": "https://example.com/typescript-icon.png",
"description": "TypeScript is a strongly typed, open-source programming language that builds on JavaScript, giving you better tooling at any scale.",
"librariesFrameworks": ["Angular", "NestJS", "TypeORM", "RxJS", "ts-node"]
},
{
"name": "Swift",
- "icon": "https://example.com/swift-icon.png",
"description": "Swift is a powerful and intuitive programming language for iOS, iPadOS, macOS, watchOS, and tvOS.",
"librariesFrameworks": [
"SwiftUI",
@@ -86,13 +78,11 @@
},
{
"name": "Go",
- "icon": "https://example.com/go-icon.png",
"description": "Go is an open-source programming language designed for simplicity, reliability, and efficiency.",
"librariesFrameworks": ["Gin", "Echo", "Beego", "Buffalo", "Gorm"]
},
{
"name": "Kotlin",
- "icon": "https://example.com/kotlin-icon.png",
"description": "Kotlin is a modern, statically typed programming language that boosts productivity and is fully interoperable with Java.",
"librariesFrameworks": [
"Spring",
From 896806dfa94b5c4efd1a1110f51987ec3b37662a Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Mon, 5 Aug 2024 14:59:15 +0300
Subject: [PATCH 06/31] Categories
---
src/app/cs/page.jsx | 46 +++++++++++++++++++++++++++++++++++----------
1 file changed, 36 insertions(+), 10 deletions(-)
diff --git a/src/app/cs/page.jsx b/src/app/cs/page.jsx
index 10e2ef0c..796222ef 100644
--- a/src/app/cs/page.jsx
+++ b/src/app/cs/page.jsx
@@ -1,27 +1,53 @@
-"use client"
-import { useState, useEffect } from "react"
+"use client";
+import { useState, useEffect } from "react";
import { NavBar } from "../components/navbar";
+import languages from "@/db/codesnippets/categories.json";
-export default function CodingSnippets(){
- const [isDarkMode, setIsDarkMode] = useState(false)
- // Toggle theme and save preference in localStorage
+export default function CodingSnippets() {
+ const [isDarkMode, setIsDarkMode] = useState(false);
+
+ // Toggle theme and save preference in localStorage
const toggleTheme = () => {
const newTheme = !isDarkMode;
setIsDarkMode(newTheme);
localStorage.setItem("theme", JSON.stringify(newTheme));
};
+
useEffect(() => {
const storedTheme = JSON.parse(localStorage.getItem("theme"));
if (storedTheme !== null) {
setIsDarkMode(storedTheme);
}
}, []);
- return(
-
-
+
+
+
+ Coding Snippets
+ A free collection of coding snippets
-
- )
+ Please choose a category:
+
+ {languages.languages.map((language, index) => (
+
+
{language.name}
+
{language.description}
+
+ ))}
+
+
+
+
+ );
}
\ No newline at end of file
From 704ac0e7360ea7643264d75d3365c0ea2c122d4f Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Tue, 6 Aug 2024 13:24:18 +0300
Subject: [PATCH 07/31] Hyperlink
---
src/app/cs/page.jsx | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/app/cs/page.jsx b/src/app/cs/page.jsx
index 796222ef..37c045b8 100644
--- a/src/app/cs/page.jsx
+++ b/src/app/cs/page.jsx
@@ -2,6 +2,7 @@
import { useState, useEffect } from "react";
import { NavBar } from "../components/navbar";
import languages from "@/db/codesnippets/categories.json";
+import Link from "next/link";
export default function CodingSnippets() {
const [isDarkMode, setIsDarkMode] = useState(false);
@@ -37,13 +38,14 @@ export default function CodingSnippets() {
Please choose a category:
{languages.languages.map((language, index) => (
-
{language.name}
{language.description}
-
+
))}
From 6b5017163baafb49d029dc2f50d1ef7bfc7cb360 Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Tue, 6 Aug 2024 13:24:29 +0300
Subject: [PATCH 08/31] Dynamic routing
---
src/app/cs/[language]/page.jsx | 45 ++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
create mode 100644 src/app/cs/[language]/page.jsx
diff --git a/src/app/cs/[language]/page.jsx b/src/app/cs/[language]/page.jsx
new file mode 100644
index 00000000..ed28c8a6
--- /dev/null
+++ b/src/app/cs/[language]/page.jsx
@@ -0,0 +1,45 @@
+"use client";
+import { useState, useEffect } from "react";
+import { NavBar } from "../../components/navbar";
+import Link from "next/link";
+
+export default function CodingSnippetsTopic({params}) {
+ const [isDarkMode, setIsDarkMode] = useState(false);
+
+ // Toggle theme and save preference in localStorage
+ const toggleTheme = () => {
+ const newTheme = !isDarkMode;
+ setIsDarkMode(newTheme);
+ localStorage.setItem("theme", JSON.stringify(newTheme));
+ };
+
+ useEffect(() => {
+ const storedTheme = JSON.parse(localStorage.getItem("theme"));
+ if (storedTheme !== null) {
+ setIsDarkMode(storedTheme);
+ }
+ }, []);
+ const title = (text)=>{
+ return text.toLowerCase().replace(/\b\w/g, char => char.toUpperCase());
+ }
+
+ return (
+
+
+
+
+ {title(params.language)} Snippets
+ A free collection of {title(params.language)} snippets
+
+
+
+
+
+ );
+}
\ No newline at end of file
From 32254f14b83c34f7c0f5eb9778732ff58a868d3a Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Tue, 6 Aug 2024 13:34:08 +0300
Subject: [PATCH 09/31] chore: make sure the category exists
---
src/app/cs/[language]/page.jsx | 65 ++++++++++++++++++++++------------
1 file changed, 43 insertions(+), 22 deletions(-)
diff --git a/src/app/cs/[language]/page.jsx b/src/app/cs/[language]/page.jsx
index ed28c8a6..ec41893e 100644
--- a/src/app/cs/[language]/page.jsx
+++ b/src/app/cs/[language]/page.jsx
@@ -1,10 +1,13 @@
"use client";
import { useState, useEffect } from "react";
import { NavBar } from "../../components/navbar";
+import languages from "@/db/codesnippets/categories.json";
import Link from "next/link";
+import NotFound from "@/app/not-found";
-export default function CodingSnippetsTopic({params}) {
+export default function CodingSnippetsTopic({ params }) {
const [isDarkMode, setIsDarkMode] = useState(false);
+ const [notfound, setNotfound] = useState(false);
// Toggle theme and save preference in localStorage
const toggleTheme = () => {
@@ -19,27 +22,45 @@ export default function CodingSnippetsTopic({params}) {
setIsDarkMode(storedTheme);
}
}, []);
- const title = (text)=>{
- return text.toLowerCase().replace(/\b\w/g, char => char.toUpperCase());
- }
- return (
-
-
-
-
- {title(params.language)} Snippets
- A free collection of {title(params.language)} snippets
+ useEffect(() => {
+ const languageExists = languages.languages.some((language) => {
+ return language.name.toLowerCase() === params.language.toLowerCase();
+ });
+ if (!languageExists) {
+ setNotfound(true);
+ }
+ }, [languages.languages, params.language]);
-
-
-
-
+ const title = (text) => {
+ return text.toLowerCase().replace(/\b\w/g, (char) => char.toUpperCase());
+ };
+
+ return (
+ <>
+ {notfound ? (
+
+ ) : (
+
+
+
+
+
+ {title(params.language)} Snippets
+
+
+ A free collection of {title(params.language)} snippets
+
+
+
+
+ )}
+ >
);
-}
\ No newline at end of file
+}
From e41516dc45a108ae7c264f8fc5026f188ea014c1 Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Tue, 6 Aug 2024 13:43:48 +0300
Subject: [PATCH 10/31] Removed categories
---
src/db/codesnippets/categories.json | 73 ++++-------------------------
1 file changed, 10 insertions(+), 63 deletions(-)
diff --git a/src/db/codesnippets/categories.json b/src/db/codesnippets/categories.json
index 0d182c18..8e2b64a9 100644
--- a/src/db/codesnippets/categories.json
+++ b/src/db/codesnippets/categories.json
@@ -2,95 +2,42 @@
"languages": [
{
"name": "JavaScript",
- "description": "JavaScript is a versatile, high-level programming language primarily used for web development.",
- "librariesFrameworks": [
- "React",
- "Angular",
- "Vue.js",
- "Node.js",
- "Express"
- ]
+ "description": "JavaScript is a versatile, high-level programming language primarily used for web development."
},
{
"name": "Python",
- "description": "Python is a high-level, interpreted programming language known for its readability and versatility.",
- "librariesFrameworks": [
- "Django",
- "Flask",
- "Pandas",
- "NumPy",
- "TensorFlow"
- ]
+ "description": "Python is a high-level, interpreted programming language known for its readability and versatility."
},
{
"name": "Java",
- "description": "Java is a high-level, class-based programming language designed for portability and cross-platform compatibility.",
- "librariesFrameworks": ["Spring", "Hibernate", "Maven", "JUnit", "Struts"]
+ "description": "Java is a high-level, class-based programming language designed for portability and cross-platform compatibility."
},
{
"name": "C#",
- "description": "C# is a modern, object-oriented programming language developed by Microsoft, widely used for developing Windows applications.",
- "librariesFrameworks": [
- "ASP.NET",
- "Entity Framework",
- "Xamarin",
- "Unity",
- "NUnit"
- ]
+ "description": "C# is a modern, object-oriented programming language developed by Microsoft, widely used for developing Windows applications."
},
{
"name": "Ruby",
- "description": "Ruby is a dynamic, open-source programming language with a focus on simplicity and productivity.",
- "librariesFrameworks": [
- "Ruby on Rails",
- "Sinatra",
- "RSpec",
- "Capybara",
- "Puma"
- ]
+ "description": "Ruby is a dynamic, open-source programming language with a focus on simplicity and productivity."
},
{
"name": "PHP",
- "description": "PHP is a widely-used open-source scripting language that is especially suited for web development and can be embedded into HTML.",
- "librariesFrameworks": [
- "Laravel",
- "Symfony",
- "CodeIgniter",
- "Zend Framework",
- "Phalcon"
- ]
+ "description": "PHP is a widely-used open-source scripting language that is especially suited for web development and can be embedded into HTML."
},
{
"name": "TypeScript",
- "description": "TypeScript is a strongly typed, open-source programming language that builds on JavaScript, giving you better tooling at any scale.",
- "librariesFrameworks": ["Angular", "NestJS", "TypeORM", "RxJS", "ts-node"]
- },
+ "description": "TypeScript is a strongly typed, open-source programming language that builds on JavaScript, giving you better tooling at any scale." },
{
"name": "Swift",
- "description": "Swift is a powerful and intuitive programming language for iOS, iPadOS, macOS, watchOS, and tvOS.",
- "librariesFrameworks": [
- "SwiftUI",
- "Combine",
- "Vapor",
- "Kitura",
- "RxSwift"
- ]
+ "description": "Swift is a powerful and intuitive programming language for iOS, iPadOS, macOS, watchOS, and tvOS."
},
{
"name": "Go",
- "description": "Go is an open-source programming language designed for simplicity, reliability, and efficiency.",
- "librariesFrameworks": ["Gin", "Echo", "Beego", "Buffalo", "Gorm"]
+ "description": "Go is an open-source programming language designed for simplicity, reliability, and efficiency."
},
{
"name": "Kotlin",
- "description": "Kotlin is a modern, statically typed programming language that boosts productivity and is fully interoperable with Java.",
- "librariesFrameworks": [
- "Spring",
- "Ktor",
- "Exposed",
- "Koin",
- "Jetpack Compose"
- ]
+ "description": "Kotlin is a modern, statically typed programming language that boosts productivity and is fully interoperable with Java."
}
]
}
From 2f1966326dc93bd0a8ec5d5d40a8df1d0c01cfdc Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Tue, 6 Aug 2024 13:45:02 +0300
Subject: [PATCH 11/31] Removed old route
---
src/app/snippet/page.jsx | 13 -------------
1 file changed, 13 deletions(-)
delete mode 100644 src/app/snippet/page.jsx
diff --git a/src/app/snippet/page.jsx b/src/app/snippet/page.jsx
deleted file mode 100644
index 9cd1749b..00000000
--- a/src/app/snippet/page.jsx
+++ /dev/null
@@ -1,13 +0,0 @@
-"use client";
-
-import Nav from "@/app/components/nav";
-
-export default function ButtonCustomizer() {
- return (
-
-
- Under Development
- If you would like to contribute it go to the main repo
-
- );
-}
From dde4be43db017f048fc0c634afbcb5dea8fdcbdb Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Thu, 8 Aug 2024 10:52:45 +0300
Subject: [PATCH 12/31] Fromat
---
src/app/api/cs/route.js | 2 +-
src/app/cs/page.jsx | 10 +++++-----
src/db/codesnippets/categories.json | 3 ++-
src/db/codesnippets/posts/c#/content.json | 7 +++++++
src/db/codesnippets/posts/generate.sh | 16 ++++++++++++++++
src/db/codesnippets/posts/go/content.json | 7 +++++++
src/db/codesnippets/posts/java/content.json | 7 +++++++
.../codesnippets/posts/javascript/content.json | 7 +++++++
src/db/codesnippets/posts/kotlin/content.json | 7 +++++++
src/db/codesnippets/posts/php/content.json | 7 +++++++
src/db/codesnippets/posts/python/content.json | 7 +++++++
src/db/codesnippets/posts/ruby/content.json | 7 +++++++
src/db/codesnippets/posts/swift/content.json | 7 +++++++
.../codesnippets/posts/typescript/content.json | 7 +++++++
src/db/tools.json | 15 +++++++--------
15 files changed, 101 insertions(+), 15 deletions(-)
create mode 100644 src/db/codesnippets/posts/c#/content.json
create mode 100644 src/db/codesnippets/posts/generate.sh
create mode 100644 src/db/codesnippets/posts/go/content.json
create mode 100644 src/db/codesnippets/posts/java/content.json
create mode 100644 src/db/codesnippets/posts/javascript/content.json
create mode 100644 src/db/codesnippets/posts/kotlin/content.json
create mode 100644 src/db/codesnippets/posts/php/content.json
create mode 100644 src/db/codesnippets/posts/python/content.json
create mode 100644 src/db/codesnippets/posts/ruby/content.json
create mode 100644 src/db/codesnippets/posts/swift/content.json
create mode 100644 src/db/codesnippets/posts/typescript/content.json
diff --git a/src/app/api/cs/route.js b/src/app/api/cs/route.js
index 01a4846a..a8df3f36 100644
--- a/src/app/api/cs/route.js
+++ b/src/app/api/cs/route.js
@@ -1,7 +1,7 @@
import categoris from "@/db/codesnippets/categories.json";
import { NextResponse } from "next/server";
-export async function GET(req) {
+export async function GET(req) {
const response = NextResponse.json(categoris, { status: 200 });
response.headers.set("Cache-Control", "public, max-age=3600"); // Cache for 1 hour
return response;
diff --git a/src/app/cs/page.jsx b/src/app/cs/page.jsx
index 37c045b8..67af8cbc 100644
--- a/src/app/cs/page.jsx
+++ b/src/app/cs/page.jsx
@@ -39,10 +39,10 @@ export default function CodingSnippets() {
{languages.languages.map((language, index) => (
+ href={"/cs/" + language.name}
+ key={index}
+ className={`${isDarkMode ? "bg-gray-700 text-white" : "bg-gray-100 text-black"} rounded-lg p-4 flex flex-col items-center justify-center hover:shadow-card-shadow cursor-pointer transition-all duration-500 ease-in`}
+ >
{language.name}
{language.description}
@@ -52,4 +52,4 @@ export default function CodingSnippets() {
);
-}
\ No newline at end of file
+}
diff --git a/src/db/codesnippets/categories.json b/src/db/codesnippets/categories.json
index 8e2b64a9..702fc12a 100644
--- a/src/db/codesnippets/categories.json
+++ b/src/db/codesnippets/categories.json
@@ -26,7 +26,8 @@
},
{
"name": "TypeScript",
- "description": "TypeScript is a strongly typed, open-source programming language that builds on JavaScript, giving you better tooling at any scale." },
+ "description": "TypeScript is a strongly typed, open-source programming language that builds on JavaScript, giving you better tooling at any scale."
+ },
{
"name": "Swift",
"description": "Swift is a powerful and intuitive programming language for iOS, iPadOS, macOS, watchOS, and tvOS."
diff --git a/src/db/codesnippets/posts/c#/content.json b/src/db/codesnippets/posts/c#/content.json
new file mode 100644
index 00000000..5744e88e
--- /dev/null
+++ b/src/db/codesnippets/posts/c#/content.json
@@ -0,0 +1,7 @@
+[
+ {
+ "title": "",
+ "author": { "name": "", "githubLink": "", "about": "" },
+ "doc": ""
+ }
+]
diff --git a/src/db/codesnippets/posts/generate.sh b/src/db/codesnippets/posts/generate.sh
new file mode 100644
index 00000000..2b8c8622
--- /dev/null
+++ b/src/db/codesnippets/posts/generate.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+# Directory to scan
+TARGET_DIR="/mnt/d/dev/Webdevtools/src/db/codesnippets/posts"
+
+# Iterate over each subdirectory in the directory
+for DIR in "$TARGET_DIR"/*; do
+ if [ -d "$DIR" ]; then
+ # Create content.json with the template details in each subdirectory
+ cat < "$DIR/content.json"
+[{"title":"","author":{"name":"","githubLink":"", "about":""},"doc":""}]
+EOF
+
+ echo "Created content.json in $DIR"
+ fi
+done
diff --git a/src/db/codesnippets/posts/go/content.json b/src/db/codesnippets/posts/go/content.json
new file mode 100644
index 00000000..5744e88e
--- /dev/null
+++ b/src/db/codesnippets/posts/go/content.json
@@ -0,0 +1,7 @@
+[
+ {
+ "title": "",
+ "author": { "name": "", "githubLink": "", "about": "" },
+ "doc": ""
+ }
+]
diff --git a/src/db/codesnippets/posts/java/content.json b/src/db/codesnippets/posts/java/content.json
new file mode 100644
index 00000000..5744e88e
--- /dev/null
+++ b/src/db/codesnippets/posts/java/content.json
@@ -0,0 +1,7 @@
+[
+ {
+ "title": "",
+ "author": { "name": "", "githubLink": "", "about": "" },
+ "doc": ""
+ }
+]
diff --git a/src/db/codesnippets/posts/javascript/content.json b/src/db/codesnippets/posts/javascript/content.json
new file mode 100644
index 00000000..5744e88e
--- /dev/null
+++ b/src/db/codesnippets/posts/javascript/content.json
@@ -0,0 +1,7 @@
+[
+ {
+ "title": "",
+ "author": { "name": "", "githubLink": "", "about": "" },
+ "doc": ""
+ }
+]
diff --git a/src/db/codesnippets/posts/kotlin/content.json b/src/db/codesnippets/posts/kotlin/content.json
new file mode 100644
index 00000000..5744e88e
--- /dev/null
+++ b/src/db/codesnippets/posts/kotlin/content.json
@@ -0,0 +1,7 @@
+[
+ {
+ "title": "",
+ "author": { "name": "", "githubLink": "", "about": "" },
+ "doc": ""
+ }
+]
diff --git a/src/db/codesnippets/posts/php/content.json b/src/db/codesnippets/posts/php/content.json
new file mode 100644
index 00000000..5744e88e
--- /dev/null
+++ b/src/db/codesnippets/posts/php/content.json
@@ -0,0 +1,7 @@
+[
+ {
+ "title": "",
+ "author": { "name": "", "githubLink": "", "about": "" },
+ "doc": ""
+ }
+]
diff --git a/src/db/codesnippets/posts/python/content.json b/src/db/codesnippets/posts/python/content.json
new file mode 100644
index 00000000..5744e88e
--- /dev/null
+++ b/src/db/codesnippets/posts/python/content.json
@@ -0,0 +1,7 @@
+[
+ {
+ "title": "",
+ "author": { "name": "", "githubLink": "", "about": "" },
+ "doc": ""
+ }
+]
diff --git a/src/db/codesnippets/posts/ruby/content.json b/src/db/codesnippets/posts/ruby/content.json
new file mode 100644
index 00000000..5744e88e
--- /dev/null
+++ b/src/db/codesnippets/posts/ruby/content.json
@@ -0,0 +1,7 @@
+[
+ {
+ "title": "",
+ "author": { "name": "", "githubLink": "", "about": "" },
+ "doc": ""
+ }
+]
diff --git a/src/db/codesnippets/posts/swift/content.json b/src/db/codesnippets/posts/swift/content.json
new file mode 100644
index 00000000..5744e88e
--- /dev/null
+++ b/src/db/codesnippets/posts/swift/content.json
@@ -0,0 +1,7 @@
+[
+ {
+ "title": "",
+ "author": { "name": "", "githubLink": "", "about": "" },
+ "doc": ""
+ }
+]
diff --git a/src/db/codesnippets/posts/typescript/content.json b/src/db/codesnippets/posts/typescript/content.json
new file mode 100644
index 00000000..5744e88e
--- /dev/null
+++ b/src/db/codesnippets/posts/typescript/content.json
@@ -0,0 +1,7 @@
+[
+ {
+ "title": "",
+ "author": { "name": "", "githubLink": "", "about": "" },
+ "doc": ""
+ }
+]
diff --git a/src/db/tools.json b/src/db/tools.json
index 929a772e..1a46de00 100644
--- a/src/db/tools.json
+++ b/src/db/tools.json
@@ -106,12 +106,11 @@
"name": "Image To SVG",
"link": "/convert/img-svg",
"ctg": "other"
- }
- ,
- {
- "id": 19,
- "name": "Coding Snippets",
- "link": "/cs",
- "ctg": "other"
- }
+ },
+ {
+ "id": 19,
+ "name": "Coding Snippets",
+ "link": "/cs",
+ "ctg": "other"
+ }
]
From a682db8ae2d6a146d11d047e86cf75812ad3f278 Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Thu, 8 Aug 2024 12:15:10 +0300
Subject: [PATCH 13/31] chore: fix spelling
---
src/app/api/cs/route.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/app/api/cs/route.js b/src/app/api/cs/route.js
index a8df3f36..75dc4c39 100644
--- a/src/app/api/cs/route.js
+++ b/src/app/api/cs/route.js
@@ -1,8 +1,8 @@
-import categoris from "@/db/codesnippets/categories.json";
+import categories from "@/db/codesnippets/categories.json";
import { NextResponse } from "next/server";
export async function GET(req) {
- const response = NextResponse.json(categoris, { status: 200 });
+ const response = NextResponse.json(categories, { status: 200 });
response.headers.set("Cache-Control", "public, max-age=3600"); // Cache for 1 hour
return response;
}
From 843982b5af433aa0f34f932c7f0e1b49e3eac4b6 Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Thu, 8 Aug 2024 12:27:59 +0300
Subject: [PATCH 14/31] Language router Router
---
src/app/api/cs/[language]/route.js | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
create mode 100644 src/app/api/cs/[language]/route.js
diff --git a/src/app/api/cs/[language]/route.js b/src/app/api/cs/[language]/route.js
new file mode 100644
index 00000000..0e65a1e0
--- /dev/null
+++ b/src/app/api/cs/[language]/route.js
@@ -0,0 +1,26 @@
+import { NextResponse } from "next/server";
+import languages from "@/db/codesnippets/categories.json";
+
+export async function GET(request, { params }) {
+ const { language } = params; // Extract category and language from params
+
+ // Check if the language exists in the languages list
+ const languageExists = languages.languages.some((lang) => {
+ return lang.name.toLowerCase() === language.toLowerCase();
+ });
+
+ // If the language does not exist, return a 404 response
+ if (!languageExists) {
+ const response = NextResponse.json({ error: "Not found" }, { status: 404 });
+ response.headers.set("Cache-Control", "public, max-age=3600"); // Cache for 1 hour
+ return response;
+ } else {
+ // If the language exists, return a success response
+ const response = NextResponse.json(
+ { text: "hey", category: language },
+ { status: 200 }
+ );
+ response.headers.set("Cache-Control", "public, max-age=3600"); // Cache for 1 hour
+ return response;
+ }
+}
\ No newline at end of file
From 29ed72fb528c44c80239011c01f36bae2ab3bc8e Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Thu, 8 Aug 2024 12:41:03 +0300
Subject: [PATCH 15/31] Fetch category
---
src/app/api/cs/[language]/route.js | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/src/app/api/cs/[language]/route.js b/src/app/api/cs/[language]/route.js
index 0e65a1e0..af651070 100644
--- a/src/app/api/cs/[language]/route.js
+++ b/src/app/api/cs/[language]/route.js
@@ -2,11 +2,12 @@ import { NextResponse } from "next/server";
import languages from "@/db/codesnippets/categories.json";
export async function GET(request, { params }) {
- const { language } = params; // Extract category and language from params
+ const { language } = params; // Extract language from params
+ const encodedLanguage = encodeURIComponent(language.toLowerCase());
// Check if the language exists in the languages list
const languageExists = languages.languages.some((lang) => {
- return lang.name.toLowerCase() === language.toLowerCase();
+ return encodeURIComponent(lang.name.toLowerCase()) === encodedLanguage;
});
// If the language does not exist, return a 404 response
@@ -15,12 +16,19 @@ export async function GET(request, { params }) {
response.headers.set("Cache-Control", "public, max-age=3600"); // Cache for 1 hour
return response;
} else {
- // If the language exists, return a success response
- const response = NextResponse.json(
- { text: "hey", category: language },
- { status: 200 }
- );
- response.headers.set("Cache-Control", "public, max-age=3600"); // Cache for 1 hour
- return response;
+ try {
+ const content = require(`@/db/codesnippets/posts/${language}/content.json`);
+ // If the language exists, return a success response
+ const response = NextResponse.json(
+ { category: language, content: content },
+ { status: 200 }
+ );
+ response.headers.set("Cache-Control", "public, max-age=3600"); // Cache for 1 hour
+ return response;
+ } catch (error) {
+ console.error(`Error loading content for language: ${language}`, error);
+ const response = NextResponse.json({ error: "Internal Server Error", message:error }, { status: 500 });
+ return response;
+ }
}
-}
\ No newline at end of file
+}
From 8c5373aff33340aeb7cd75fe918ba3c3b547631c Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Thu, 8 Aug 2024 12:42:41 +0300
Subject: [PATCH 16/31] Format
---
src/app/api/cs/[language]/route.js | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/app/api/cs/[language]/route.js b/src/app/api/cs/[language]/route.js
index af651070..71918c3d 100644
--- a/src/app/api/cs/[language]/route.js
+++ b/src/app/api/cs/[language]/route.js
@@ -17,17 +17,22 @@ export async function GET(request, { params }) {
return response;
} else {
try {
- const content = require(`@/db/codesnippets/posts/${language}/content.json`);
+ const content = require(
+ `@/db/codesnippets/posts/${language}/content.json`,
+ );
// If the language exists, return a success response
const response = NextResponse.json(
{ category: language, content: content },
- { status: 200 }
+ { status: 200 },
);
response.headers.set("Cache-Control", "public, max-age=3600"); // Cache for 1 hour
return response;
} catch (error) {
console.error(`Error loading content for language: ${language}`, error);
- const response = NextResponse.json({ error: "Internal Server Error", message:error }, { status: 500 });
+ const response = NextResponse.json(
+ { error: "Internal Server Error", message: error },
+ { status: 500 },
+ );
return response;
}
}
From 1fe700a78b2d823a23e9d6d51ffb29fba1fd1ab8 Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Thu, 8 Aug 2024 12:57:23 +0300
Subject: [PATCH 17/31] Switch to fs
---
src/app/api/cs/[language]/route.js | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/app/api/cs/[language]/route.js b/src/app/api/cs/[language]/route.js
index 71918c3d..b9460c25 100644
--- a/src/app/api/cs/[language]/route.js
+++ b/src/app/api/cs/[language]/route.js
@@ -1,5 +1,7 @@
import { NextResponse } from "next/server";
import languages from "@/db/codesnippets/categories.json";
+import { promises as fs } from "fs";
+import path from "path";
export async function GET(request, { params }) {
const { language } = params; // Extract language from params
@@ -17,12 +19,13 @@ export async function GET(request, { params }) {
return response;
} else {
try {
- const content = require(
- `@/db/codesnippets/posts/${language}/content.json`,
- );
+ const filePath = path.join(process.cwd(), '/src/db/codesnippets/posts', language, 'content.json');
+ const content = await fs.readFile(filePath, 'utf-8');
+ const parsedContent = JSON.parse(content);
+
// If the language exists, return a success response
const response = NextResponse.json(
- { category: language, content: content },
+ { category: language, content: parsedContent },
{ status: 200 },
);
response.headers.set("Cache-Control", "public, max-age=3600"); // Cache for 1 hour
@@ -30,7 +33,7 @@ export async function GET(request, { params }) {
} catch (error) {
console.error(`Error loading content for language: ${language}`, error);
const response = NextResponse.json(
- { error: "Internal Server Error", message: error },
+ { error: "Internal Server Error", message: error.message },
{ status: 500 },
);
return response;
From 998bca2ef6102c4084d19b6c558a18dc08add40b Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Thu, 8 Aug 2024 12:57:37 +0300
Subject: [PATCH 18/31] Content fetch
---
.../api/cs/[language]/doc/[title]/route.js | 41 +++++++++++++++++++
1 file changed, 41 insertions(+)
create mode 100644 src/app/api/cs/[language]/doc/[title]/route.js
diff --git a/src/app/api/cs/[language]/doc/[title]/route.js b/src/app/api/cs/[language]/doc/[title]/route.js
new file mode 100644
index 00000000..7aa54c03
--- /dev/null
+++ b/src/app/api/cs/[language]/doc/[title]/route.js
@@ -0,0 +1,41 @@
+import { NextResponse } from "next/server";
+import languages from "@/db/codesnippets/categories.json";
+import { promises as fs } from "fs";
+import path from "path";
+
+export async function GET(request, { params }) {
+ const { language, title } = params; // Extract language from params
+ const encodedLanguage = encodeURIComponent(language.toLowerCase());
+
+ // Check if the language exists in the languages list
+ const languageExists = languages.languages.some((lang) => {
+ return encodeURIComponent(lang.name.toLowerCase()) === encodedLanguage;
+ });
+
+ // If the language does not exist, return a 404 response
+ if (!languageExists) {
+ const response = NextResponse.json({ error: "Language not found" }, { status: 404 });
+ response.headers.set("Cache-Control", "public, max-age=3600"); // Cache for 1 hour
+ return response;
+ } else {
+ try {
+ const filePath = path.join(process.cwd(), '/src/db/codesnippets/posts', language, `${title}.md`);
+ const content = await fs.readFile(filePath, 'utf-8');
+
+ // If the language exists, return a success response
+ const response = NextResponse.json(
+ { category: language, content: content },
+ { status: 200 },
+ );
+ response.headers.set("Cache-Control", "public, max-age=3600"); // Cache for 1 hour
+ return response;
+ } catch (error) {
+ console.error(`Error loading content for language: ${language}`, error);
+ const response = NextResponse.json(
+ { error: "Internal Server Error", message: error.message },
+ { status: 500 },
+ );
+ return response;
+ }
+ }
+}
From a3a05c0525d15beb47bf9da6bfd9dfe45de23631 Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Thu, 8 Aug 2024 13:01:08 +0300
Subject: [PATCH 19/31] Format fix
---
src/app/api/cs/[language]/doc/[title]/route.js | 14 +++++++++++---
src/app/api/cs/[language]/route.js | 9 +++++++--
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/app/api/cs/[language]/doc/[title]/route.js b/src/app/api/cs/[language]/doc/[title]/route.js
index 7aa54c03..9e0062d7 100644
--- a/src/app/api/cs/[language]/doc/[title]/route.js
+++ b/src/app/api/cs/[language]/doc/[title]/route.js
@@ -14,13 +14,21 @@ export async function GET(request, { params }) {
// If the language does not exist, return a 404 response
if (!languageExists) {
- const response = NextResponse.json({ error: "Language not found" }, { status: 404 });
+ const response = NextResponse.json(
+ { error: "Language not found" },
+ { status: 404 },
+ );
response.headers.set("Cache-Control", "public, max-age=3600"); // Cache for 1 hour
return response;
} else {
try {
- const filePath = path.join(process.cwd(), '/src/db/codesnippets/posts', language, `${title}.md`);
- const content = await fs.readFile(filePath, 'utf-8');
+ const filePath = path.join(
+ process.cwd(),
+ "/src/db/codesnippets/posts",
+ language,
+ `${title}.md`,
+ );
+ const content = await fs.readFile(filePath, "utf-8");
// If the language exists, return a success response
const response = NextResponse.json(
diff --git a/src/app/api/cs/[language]/route.js b/src/app/api/cs/[language]/route.js
index b9460c25..cc205200 100644
--- a/src/app/api/cs/[language]/route.js
+++ b/src/app/api/cs/[language]/route.js
@@ -19,8 +19,13 @@ export async function GET(request, { params }) {
return response;
} else {
try {
- const filePath = path.join(process.cwd(), '/src/db/codesnippets/posts', language, 'content.json');
- const content = await fs.readFile(filePath, 'utf-8');
+ const filePath = path.join(
+ process.cwd(),
+ "/src/db/codesnippets/posts",
+ language,
+ "content.json",
+ );
+ const content = await fs.readFile(filePath, "utf-8");
const parsedContent = JSON.parse(content);
// If the language exists, return a success response
From e2b1424010bac2825c84b8b98bd87f5371404158 Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Fri, 9 Aug 2024 07:46:03 +0300
Subject: [PATCH 20/31] Card1
---
src/app/cs/[language]/page.jsx | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/src/app/cs/[language]/page.jsx b/src/app/cs/[language]/page.jsx
index ec41893e..d3551a28 100644
--- a/src/app/cs/[language]/page.jsx
+++ b/src/app/cs/[language]/page.jsx
@@ -2,12 +2,12 @@
import { useState, useEffect } from "react";
import { NavBar } from "../../components/navbar";
import languages from "@/db/codesnippets/categories.json";
-import Link from "next/link";
import NotFound from "@/app/not-found";
export default function CodingSnippetsTopic({ params }) {
const [isDarkMode, setIsDarkMode] = useState(false);
const [notfound, setNotfound] = useState(false);
+ const [content, setContent] = useState();
// Toggle theme and save preference in localStorage
const toggleTheme = () => {
@@ -27,7 +27,13 @@ export default function CodingSnippetsTopic({ params }) {
const languageExists = languages.languages.some((language) => {
return language.name.toLowerCase() === params.language.toLowerCase();
});
- if (!languageExists) {
+ if (languageExists) {
+ setContent(
+ require(
+ `@/db/codesnippets/posts/${params.language.toLowerCase()}/content.json`,
+ ),
+ );
+ } else {
setNotfound(true);
}
}, [languages.languages, params.language]);
@@ -57,6 +63,17 @@ export default function CodingSnippetsTopic({ params }) {
A free collection of {title(params.language)} snippets
+
+ {content ? (
+ content.map((article, index) => (
+
+
{article.title}
+
+ ))
+ ) : (
+ No data
+ )}
+
From c2e8475d182714b9b2c7c9b3b5a83b6bd06ac4c9 Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Fri, 9 Aug 2024 10:10:50 +0300
Subject: [PATCH 21/31] Delete posts
---
src/app/cs/[language]/page.jsx | 2 +-
src/db/codesnippets/posts/c#/content.json | 8 +-------
src/db/codesnippets/posts/go/content.json | 8 +-------
src/db/codesnippets/posts/java/content.json | 8 +-------
src/db/codesnippets/posts/javascript/content.json | 8 +-------
src/db/codesnippets/posts/kotlin/content.json | 8 +-------
src/db/codesnippets/posts/php/content.json | 8 +-------
src/db/codesnippets/posts/python/content.json | 8 +-------
src/db/codesnippets/posts/ruby/content.json | 8 +-------
src/db/codesnippets/posts/swift/content.json | 8 +-------
src/db/codesnippets/posts/typescript/content.json | 8 +-------
11 files changed, 11 insertions(+), 71 deletions(-)
diff --git a/src/app/cs/[language]/page.jsx b/src/app/cs/[language]/page.jsx
index d3551a28..cfaab7a7 100644
--- a/src/app/cs/[language]/page.jsx
+++ b/src/app/cs/[language]/page.jsx
@@ -64,7 +64,7 @@ export default function CodingSnippetsTopic({ params }) {
A free collection of {title(params.language)} snippets
- {content ? (
+ {(content && content.length > 0) ?(
content.map((article, index) => (
{article.title}
diff --git a/src/db/codesnippets/posts/c#/content.json b/src/db/codesnippets/posts/c#/content.json
index 5744e88e..0637a088 100644
--- a/src/db/codesnippets/posts/c#/content.json
+++ b/src/db/codesnippets/posts/c#/content.json
@@ -1,7 +1 @@
-[
- {
- "title": "",
- "author": { "name": "", "githubLink": "", "about": "" },
- "doc": ""
- }
-]
+[]
\ No newline at end of file
diff --git a/src/db/codesnippets/posts/go/content.json b/src/db/codesnippets/posts/go/content.json
index 5744e88e..0637a088 100644
--- a/src/db/codesnippets/posts/go/content.json
+++ b/src/db/codesnippets/posts/go/content.json
@@ -1,7 +1 @@
-[
- {
- "title": "",
- "author": { "name": "", "githubLink": "", "about": "" },
- "doc": ""
- }
-]
+[]
\ No newline at end of file
diff --git a/src/db/codesnippets/posts/java/content.json b/src/db/codesnippets/posts/java/content.json
index 5744e88e..0637a088 100644
--- a/src/db/codesnippets/posts/java/content.json
+++ b/src/db/codesnippets/posts/java/content.json
@@ -1,7 +1 @@
-[
- {
- "title": "",
- "author": { "name": "", "githubLink": "", "about": "" },
- "doc": ""
- }
-]
+[]
\ No newline at end of file
diff --git a/src/db/codesnippets/posts/javascript/content.json b/src/db/codesnippets/posts/javascript/content.json
index 5744e88e..0637a088 100644
--- a/src/db/codesnippets/posts/javascript/content.json
+++ b/src/db/codesnippets/posts/javascript/content.json
@@ -1,7 +1 @@
-[
- {
- "title": "",
- "author": { "name": "", "githubLink": "", "about": "" },
- "doc": ""
- }
-]
+[]
\ No newline at end of file
diff --git a/src/db/codesnippets/posts/kotlin/content.json b/src/db/codesnippets/posts/kotlin/content.json
index 5744e88e..0637a088 100644
--- a/src/db/codesnippets/posts/kotlin/content.json
+++ b/src/db/codesnippets/posts/kotlin/content.json
@@ -1,7 +1 @@
-[
- {
- "title": "",
- "author": { "name": "", "githubLink": "", "about": "" },
- "doc": ""
- }
-]
+[]
\ No newline at end of file
diff --git a/src/db/codesnippets/posts/php/content.json b/src/db/codesnippets/posts/php/content.json
index 5744e88e..0637a088 100644
--- a/src/db/codesnippets/posts/php/content.json
+++ b/src/db/codesnippets/posts/php/content.json
@@ -1,7 +1 @@
-[
- {
- "title": "",
- "author": { "name": "", "githubLink": "", "about": "" },
- "doc": ""
- }
-]
+[]
\ No newline at end of file
diff --git a/src/db/codesnippets/posts/python/content.json b/src/db/codesnippets/posts/python/content.json
index 5744e88e..0637a088 100644
--- a/src/db/codesnippets/posts/python/content.json
+++ b/src/db/codesnippets/posts/python/content.json
@@ -1,7 +1 @@
-[
- {
- "title": "",
- "author": { "name": "", "githubLink": "", "about": "" },
- "doc": ""
- }
-]
+[]
\ No newline at end of file
diff --git a/src/db/codesnippets/posts/ruby/content.json b/src/db/codesnippets/posts/ruby/content.json
index 5744e88e..0637a088 100644
--- a/src/db/codesnippets/posts/ruby/content.json
+++ b/src/db/codesnippets/posts/ruby/content.json
@@ -1,7 +1 @@
-[
- {
- "title": "",
- "author": { "name": "", "githubLink": "", "about": "" },
- "doc": ""
- }
-]
+[]
\ No newline at end of file
diff --git a/src/db/codesnippets/posts/swift/content.json b/src/db/codesnippets/posts/swift/content.json
index 5744e88e..0637a088 100644
--- a/src/db/codesnippets/posts/swift/content.json
+++ b/src/db/codesnippets/posts/swift/content.json
@@ -1,7 +1 @@
-[
- {
- "title": "",
- "author": { "name": "", "githubLink": "", "about": "" },
- "doc": ""
- }
-]
+[]
\ No newline at end of file
diff --git a/src/db/codesnippets/posts/typescript/content.json b/src/db/codesnippets/posts/typescript/content.json
index 5744e88e..0637a088 100644
--- a/src/db/codesnippets/posts/typescript/content.json
+++ b/src/db/codesnippets/posts/typescript/content.json
@@ -1,7 +1 @@
-[
- {
- "title": "",
- "author": { "name": "", "githubLink": "", "about": "" },
- "doc": ""
- }
-]
+[]
\ No newline at end of file
From 036d0f9beb0aed86588e9a12abc704aeba673a82 Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Fri, 9 Aug 2024 12:11:05 +0300
Subject: [PATCH 22/31] feat: blog cards
---
src/app/cs/[language]/page.jsx | 47 ++++++++++++++++++++++++++----
src/app/cs/components/blogCard.jsx | 35 ++++++++++++++++++++++
2 files changed, 76 insertions(+), 6 deletions(-)
create mode 100644 src/app/cs/components/blogCard.jsx
diff --git a/src/app/cs/[language]/page.jsx b/src/app/cs/[language]/page.jsx
index cfaab7a7..310b2efd 100644
--- a/src/app/cs/[language]/page.jsx
+++ b/src/app/cs/[language]/page.jsx
@@ -3,6 +3,8 @@ import { useState, useEffect } from "react";
import { NavBar } from "../../components/navbar";
import languages from "@/db/codesnippets/categories.json";
import NotFound from "@/app/not-found";
+import Link from "next/link";
+import { BlogCard } from "../components/blogCard";
export default function CodingSnippetsTopic({ params }) {
const [isDarkMode, setIsDarkMode] = useState(false);
@@ -64,14 +66,47 @@ export default function CodingSnippetsTopic({ params }) {
A free collection of {title(params.language)} snippets
- {(content && content.length > 0) ?(
- content.map((article, index) => (
-
-
{article.title}
+ {content && content.length > 0 ? (
+
+
+ {content.map((article, index) => (
+
+ ))}
- ))
+
) : (
-
No data
+
+
No available posts
+
+
+
+
+
+
+
+ Add code snippets
+
+
+
+
)}
diff --git a/src/app/cs/components/blogCard.jsx b/src/app/cs/components/blogCard.jsx
new file mode 100644
index 00000000..9a76d136
--- /dev/null
+++ b/src/app/cs/components/blogCard.jsx
@@ -0,0 +1,35 @@
+import React from "react";
+import Link from "next/link";
+import { FaGithub } from "react-icons/fa";
+
+export function BlogCard({ data, key, darkmode }) {
+ return (
+
+ {data.title}
+
+
About the author
+
{data?.author?.name}
+
{data?.author?.about}
+ {data?.author?.githubLink && (
+
+
GitHub
+
+ )}
+
+
+ );
+}
From 35b5c077428cce73e1621dc711cd09798e01bf97 Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Fri, 9 Aug 2024 12:14:13 +0300
Subject: [PATCH 23/31] =?UTF-8?q?Format=20=F0=9F=94=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/db/codesnippets/posts/c#/content.json | 2 +-
src/db/codesnippets/posts/go/content.json | 2 +-
src/db/codesnippets/posts/java/content.json | 2 +-
.../posts/javascript/content.json | 2 +-
src/db/codesnippets/posts/kotlin/content.json | 2 +-
src/db/codesnippets/posts/php/content.json | 2 +-
src/db/codesnippets/posts/python/article1.md | 74 +++++++++++++++++++
src/db/codesnippets/posts/python/content.json | 12 ++-
src/db/codesnippets/posts/ruby/content.json | 2 +-
src/db/codesnippets/posts/swift/content.json | 2 +-
.../posts/typescript/content.json | 2 +-
11 files changed, 94 insertions(+), 10 deletions(-)
create mode 100644 src/db/codesnippets/posts/python/article1.md
diff --git a/src/db/codesnippets/posts/c#/content.json b/src/db/codesnippets/posts/c#/content.json
index 0637a088..fe51488c 100644
--- a/src/db/codesnippets/posts/c#/content.json
+++ b/src/db/codesnippets/posts/c#/content.json
@@ -1 +1 @@
-[]
\ No newline at end of file
+[]
diff --git a/src/db/codesnippets/posts/go/content.json b/src/db/codesnippets/posts/go/content.json
index 0637a088..fe51488c 100644
--- a/src/db/codesnippets/posts/go/content.json
+++ b/src/db/codesnippets/posts/go/content.json
@@ -1 +1 @@
-[]
\ No newline at end of file
+[]
diff --git a/src/db/codesnippets/posts/java/content.json b/src/db/codesnippets/posts/java/content.json
index 0637a088..fe51488c 100644
--- a/src/db/codesnippets/posts/java/content.json
+++ b/src/db/codesnippets/posts/java/content.json
@@ -1 +1 @@
-[]
\ No newline at end of file
+[]
diff --git a/src/db/codesnippets/posts/javascript/content.json b/src/db/codesnippets/posts/javascript/content.json
index 0637a088..fe51488c 100644
--- a/src/db/codesnippets/posts/javascript/content.json
+++ b/src/db/codesnippets/posts/javascript/content.json
@@ -1 +1 @@
-[]
\ No newline at end of file
+[]
diff --git a/src/db/codesnippets/posts/kotlin/content.json b/src/db/codesnippets/posts/kotlin/content.json
index 0637a088..fe51488c 100644
--- a/src/db/codesnippets/posts/kotlin/content.json
+++ b/src/db/codesnippets/posts/kotlin/content.json
@@ -1 +1 @@
-[]
\ No newline at end of file
+[]
diff --git a/src/db/codesnippets/posts/php/content.json b/src/db/codesnippets/posts/php/content.json
index 0637a088..fe51488c 100644
--- a/src/db/codesnippets/posts/php/content.json
+++ b/src/db/codesnippets/posts/php/content.json
@@ -1 +1 @@
-[]
\ No newline at end of file
+[]
diff --git a/src/db/codesnippets/posts/python/article1.md b/src/db/codesnippets/posts/python/article1.md
new file mode 100644
index 00000000..7d2a61b9
--- /dev/null
+++ b/src/db/codesnippets/posts/python/article1.md
@@ -0,0 +1,74 @@
+# Generating the Mandelbrot Set with Python
+
+The Mandelbrot set is one of the most famous fractals in mathematics, known for its intricate and beautiful boundary. In this article, we'll explore how to generate and visualize the Mandelbrot set using Python.
+
+## What is the Mandelbrot Set?
+
+The Mandelbrot set is defined as the set of complex numbers \( c \) for which the function \( f(z) = z^2 + c \) does not diverge when iterated from \( z = 0 \). If the magnitude of \( z \) becomes larger than 2, the function is said to diverge.
+
+## Python Code
+
+We'll use Python with the `numpy` and `matplotlib` libraries to generate and plot the Mandelbrot set.
+
+```python
+import numpy as np
+import matplotlib.pyplot as plt
+
+def mandelbrot(c, max_iter):
+ z = c
+ for n in range(max_iter):
+ if abs(z) > 2:
+ return n
+ z = z*z + c
+ return max_iter
+
+def mandelbrot_set(xmin, xmax, ymin, ymax, width, height, max_iter):
+ r1 = np.linspace(xmin, xmax, width)
+ r2 = np.linspace(ymin, ymax, height)
+ n3 = np.empty((width, height))
+ for i in range(width):
+ for j in range(height):
+ n3[i, j] = mandelbrot(r1[i] + 1j*r2[j], max_iter)
+ return (r1, r2, n3)
+
+def plot_mandelbrot(xmin, xmax, ymin, ymax, width, height, max_iter):
+ dpi = 100
+ img_width = dpi * width
+ img_height = dpi * height
+
+ x, y, mandelbrot_image = mandelbrot_set(xmin, xmax, ymin, ymax, img_width, img_height, max_iter)
+
+ plt.figure(figsize=(width, height), dpi=dpi)
+ plt.imshow(mandelbrot_image.T, extent=[xmin, xmax, ymin, ymax], cmap='hot')
+ plt.colorbar()
+ plt.title('Mandelbrot Set')
+ plt.xlabel('Re')
+ plt.ylabel('Im')
+ plt.show()
+
+# Parameters for the plot
+xmin, xmax, ymin, ymax = -2.0, 1.0, -1.5, 1.5
+width, height = 8, 8
+max_iter = 256
+
+plot_mandelbrot(xmin, xmax, ymin, ymax, width, height, max_iter)
+```
+
+### Explanation
+
+1. **mandelbrot(c, max_iter):**
+ This function checks whether a complex number \( c \) is in the Mandelbrot set. It iterates the function \( f(z) = z^2 + c \) up to `max_iter` times or until the magnitude of \( z \) exceeds 2.
+
+2. **mandelbrot_set(xmin, xmax, ymin, ymax, width, height, max_iter):**
+ This function generates the Mandelbrot set over a specified range in the complex plane. It creates a grid of complex numbers and checks each one using the `mandelbrot` function.
+
+3. **plot_mandelbrot(xmin, xmax, ymin, ymax, width, height, max_iter):**
+ This function plots the Mandelbrot set using `matplotlib`. It sets up the plot dimensions and color scheme, and then displays the image.
+
+### Visualization
+
+The `plot_mandelbrot` function will generate a plot of the Mandelbrot set. You can adjust the parameters (e.g., `xmin`, `xmax`, `ymin`, `ymax`, `width`, `height`, `max_iter`) to explore different parts of the fractal and see more details.
+
+### Conclusion
+
+Generating the Mandelbrot set is a fascinating way to explore the beauty of fractals and complex numbers. With Python, it's straightforward to implement and visualize this famous fractal. Experiment with the parameters to see how the fractal changes and uncover the infinite complexity within the Mandelbrot set.
diff --git a/src/db/codesnippets/posts/python/content.json b/src/db/codesnippets/posts/python/content.json
index 0637a088..6c804ef5 100644
--- a/src/db/codesnippets/posts/python/content.json
+++ b/src/db/codesnippets/posts/python/content.json
@@ -1 +1,11 @@
-[]
\ No newline at end of file
+[
+ {
+ "title": "Generating the Mandelbrot Set with Python",
+ "author": {
+ "name": "ChatGPT",
+ "githubLink": "ertj",
+ "about": "I'm a versatile AI language model created by OpenAI, designed to assist with a wide range of tasks, from answering questions and providing explanations to generating creative content and solving technical problems. My capabilities span across various domains including programming, writing, research, and more. I'm here to help users by leveraging my training on diverse datasets to provide accurate, helpful, and engaging responses."
+ },
+ "doc": "article1"
+ }
+]
diff --git a/src/db/codesnippets/posts/ruby/content.json b/src/db/codesnippets/posts/ruby/content.json
index 0637a088..fe51488c 100644
--- a/src/db/codesnippets/posts/ruby/content.json
+++ b/src/db/codesnippets/posts/ruby/content.json
@@ -1 +1 @@
-[]
\ No newline at end of file
+[]
diff --git a/src/db/codesnippets/posts/swift/content.json b/src/db/codesnippets/posts/swift/content.json
index 0637a088..fe51488c 100644
--- a/src/db/codesnippets/posts/swift/content.json
+++ b/src/db/codesnippets/posts/swift/content.json
@@ -1 +1 @@
-[]
\ No newline at end of file
+[]
diff --git a/src/db/codesnippets/posts/typescript/content.json b/src/db/codesnippets/posts/typescript/content.json
index 0637a088..fe51488c 100644
--- a/src/db/codesnippets/posts/typescript/content.json
+++ b/src/db/codesnippets/posts/typescript/content.json
@@ -1 +1 @@
-[]
\ No newline at end of file
+[]
From cf5a06d2f9541452410a33cb8944fdde07161d67 Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Fri, 9 Aug 2024 12:37:39 +0300
Subject: [PATCH 24/31] feat: Link
---
src/app/cs/components/blogCard.jsx | 54 ++++++++++++++++--------------
1 file changed, 29 insertions(+), 25 deletions(-)
diff --git a/src/app/cs/components/blogCard.jsx b/src/app/cs/components/blogCard.jsx
index 9a76d136..224af71d 100644
--- a/src/app/cs/components/blogCard.jsx
+++ b/src/app/cs/components/blogCard.jsx
@@ -2,34 +2,38 @@ import React from "react";
import Link from "next/link";
import { FaGithub } from "react-icons/fa";
-export function BlogCard({ data, key, darkmode }) {
+export function BlogCard({ data, darkmode }) {
return (
-
- {data.title}
-
-
About the author
-
{data?.author?.name}
-
{data?.author?.about}
- {data?.author?.githubLink && (
-
-
GitHub
-
- )}
-
-
+
+ {data.title}
+
+
About the author
+
{data?.author?.name}
+
{data?.author?.about}
+ {data?.author?.githubLink && (
+
+ GitHub
+
+ )}
+
+
+
);
}
From 8414c3986775cc2d69cd8546ad605d72e4d7becd Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Fri, 9 Aug 2024 12:58:58 +0300
Subject: [PATCH 25/31] Blog page
---
src/app/cs/[language]/[article]/page.jsx | 63 ++++++++++++++++++++++++
1 file changed, 63 insertions(+)
create mode 100644 src/app/cs/[language]/[article]/page.jsx
diff --git a/src/app/cs/[language]/[article]/page.jsx b/src/app/cs/[language]/[article]/page.jsx
new file mode 100644
index 00000000..239f7535
--- /dev/null
+++ b/src/app/cs/[language]/[article]/page.jsx
@@ -0,0 +1,63 @@
+"use client";
+import { useState, useEffect } from "react";
+import { NavBar } from "@/app/components/navbar";
+import languages from "@/db/codesnippets/categories.json";
+import NotFound from "@/app/not-found";
+
+export default function CodingSnippets({ params }) {
+ const [isDarkMode, setIsDarkMode] = useState(false);
+ const [articleExists, setArticleExists] = useState(true);
+
+ // Toggle theme and save preference in localStorage
+ const toggleTheme = () => {
+ const newTheme = !isDarkMode;
+ setIsDarkMode(newTheme);
+ localStorage.setItem("theme", JSON.stringify(newTheme));
+ };
+
+ useEffect(() => {
+ const storedTheme = JSON.parse(localStorage.getItem("theme"));
+ if (storedTheme !== null) {
+ setIsDarkMode(storedTheme);
+ }
+ }, []);
+ const title = (text) => {
+ return decodeURIComponent(text)
+ .toLowerCase()
+ .replace(/\b\w/g, (char) => char.toUpperCase());
+ };
+
+ useEffect(() => {
+ const languageExists = languages.languages.some((language) => {
+ return language.name.toLowerCase() === params.language.toLowerCase();
+ });
+ if (languageExists) {
+ const data = require(
+ `@/db/codesnippets/posts/${params.language.toLowerCase()}/content.json`,
+ );
+ const article = data.some((article) => {
+ return title(article.title) === title(params.article);
+ });
+ setArticleExists(article);
+ } else {
+ setArticleExists(false);
+ }
+ }, [languages.languages, params.language, params.article]);
+ return (
+ <>
+ {articleExists ? (
+
+
+
+ ) : (
+
+ )}
+ >
+ );
+}
From c321caa97dfa9c5ed98250d9d9d65fe549cea91b Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Fri, 9 Aug 2024 13:15:12 +0300
Subject: [PATCH 26/31] Remove gh link
---
src/db/codesnippets/posts/python/content.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/db/codesnippets/posts/python/content.json b/src/db/codesnippets/posts/python/content.json
index 6c804ef5..bb981d60 100644
--- a/src/db/codesnippets/posts/python/content.json
+++ b/src/db/codesnippets/posts/python/content.json
@@ -3,7 +3,7 @@
"title": "Generating the Mandelbrot Set with Python",
"author": {
"name": "ChatGPT",
- "githubLink": "ertj",
+ "githubLink": "",
"about": "I'm a versatile AI language model created by OpenAI, designed to assist with a wide range of tasks, from answering questions and providing explanations to generating creative content and solving technical problems. My capabilities span across various domains including programming, writing, research, and more. I'm here to help users by leveraging my training on diverse datasets to provide accurate, helpful, and engaging responses."
},
"doc": "article1"
From da75740ee737fcc102cb882a12b4c1f4d326dbc9 Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Fri, 9 Aug 2024 13:33:43 +0300
Subject: [PATCH 27/31] Sidebar
---
src/app/cs/[language]/[article]/page.jsx | 11 ++++++++-
src/app/cs/components/siodebar.jsx | 29 ++++++++++++++++++++++++
2 files changed, 39 insertions(+), 1 deletion(-)
create mode 100644 src/app/cs/components/siodebar.jsx
diff --git a/src/app/cs/[language]/[article]/page.jsx b/src/app/cs/[language]/[article]/page.jsx
index 239f7535..0e2e6ce1 100644
--- a/src/app/cs/[language]/[article]/page.jsx
+++ b/src/app/cs/[language]/[article]/page.jsx
@@ -3,11 +3,12 @@ import { useState, useEffect } from "react";
import { NavBar } from "@/app/components/navbar";
import languages from "@/db/codesnippets/categories.json";
import NotFound from "@/app/not-found";
+import { Sidebar } from "../../components/siodebar";
export default function CodingSnippets({ params }) {
const [isDarkMode, setIsDarkMode] = useState(false);
const [articleExists, setArticleExists] = useState(true);
-
+ const [data, setData] = useState();
// Toggle theme and save preference in localStorage
const toggleTheme = () => {
const newTheme = !isDarkMode;
@@ -39,6 +40,11 @@ export default function CodingSnippets({ params }) {
return title(article.title) === title(params.article);
});
setArticleExists(article);
+ data.map((art) => {
+ if (title(art.title) === title(params.article)) {
+ setData(art);
+ }
+ });
} else {
setArticleExists(false);
}
@@ -54,6 +60,9 @@ export default function CodingSnippets({ params }) {
isDarkMode={isDarkMode}
toggleTheme={toggleTheme}
/>
+
) : (
diff --git a/src/app/cs/components/siodebar.jsx b/src/app/cs/components/siodebar.jsx
new file mode 100644
index 00000000..3bf7e226
--- /dev/null
+++ b/src/app/cs/components/siodebar.jsx
@@ -0,0 +1,29 @@
+import { FaGithub } from "react-icons/fa";
+
+export function Sidebar({ author, darkmode }) {
+ return (
+
+ );
+}
From 95c52b6922809facab762a6569ddb237ef58dc7c Mon Sep 17 00:00:00 2001
From: Bashamega
Date: Fri, 9 Aug 2024 14:59:15 +0300
Subject: [PATCH 28/31] Blog fixes
---
src/app/cs/[language]/[article]/page.jsx | 9 +++-
src/app/cs/components/blogContent.jsx | 58 ++++++++++++++++++++++++
src/app/cs/components/siodebar.jsx | 2 +-
3 files changed, 67 insertions(+), 2 deletions(-)
create mode 100644 src/app/cs/components/blogContent.jsx
diff --git a/src/app/cs/[language]/[article]/page.jsx b/src/app/cs/[language]/[article]/page.jsx
index 0e2e6ce1..5d85d927 100644
--- a/src/app/cs/[language]/[article]/page.jsx
+++ b/src/app/cs/[language]/[article]/page.jsx
@@ -4,6 +4,7 @@ import { NavBar } from "@/app/components/navbar";
import languages from "@/db/codesnippets/categories.json";
import NotFound from "@/app/not-found";
import { Sidebar } from "../../components/siodebar";
+import { BlogContent } from "../../components/blogContent";
export default function CodingSnippets({ params }) {
const [isDarkMode, setIsDarkMode] = useState(false);
@@ -60,7 +61,13 @@ export default function CodingSnippets({ params }) {
isDarkMode={isDarkMode}
toggleTheme={toggleTheme}
/>
-
+
diff --git a/src/app/cs/components/blogContent.jsx b/src/app/cs/components/blogContent.jsx
new file mode 100644
index 00000000..5b833f66
--- /dev/null
+++ b/src/app/cs/components/blogContent.jsx
@@ -0,0 +1,58 @@
+import { useEffect, useState } from "react";
+import snarkdown from "snarkdown";
+
+export function BlogContent({ doc, title, language, isDarkMode }) {
+ const [content, setContent] = useState("");
+ const [loading, setLoading] = useState(true);
+
+ useEffect(() => {
+ async function fetchContent() {
+ setLoading(true);
+ try {
+ const response = await fetch(`/api/cs/${language}/doc/${doc}`);
+ if (!response.ok) {
+ throw new Error("Network response was not ok");
+ }
+ const data = await response.json();
+ setContent(data.content);
+ } catch (error) {
+ console.error("Failed to fetch content:", error);
+ } finally {
+ setLoading(false);
+ }
+ }
+
+ fetchContent();
+ }, [title, language]);
+
+ return (
+
+ {loading ? (
+ Loading...
+ ) : (
+
+ )}
+
+ );
+}
diff --git a/src/app/cs/components/siodebar.jsx b/src/app/cs/components/siodebar.jsx
index 3bf7e226..49f7e51a 100644
--- a/src/app/cs/components/siodebar.jsx
+++ b/src/app/cs/components/siodebar.jsx
@@ -2,7 +2,7 @@ import { FaGithub } from "react-icons/fa";
export function Sidebar({ author, darkmode }) {
return (
-