-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from GalsenDev221/dev
(FEAT) / Fix error deployment and some update ✅
- Loading branch information
Showing
38 changed files
with
7,071 additions
and
7,614 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,4 @@ next-env.d.ts | |
.env*.local | ||
|
||
# lock files | ||
package-lock.json | ||
pnpm-lock.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,78 @@ | ||
// "use client"; | ||
import { promises as fs } from "fs"; | ||
import { serialize } from "next-mdx-remote/serialize"; | ||
import RemoteMdxWrapper from "@/components/Mdx/RemoteMdxWrapper"; | ||
import RenderHTMLFiles from "@/components/galsenUiComponents/RenderHTMLFiles"; | ||
import H1 from "@/components/Mdx/H1"; | ||
// import ErrorMessage from "@/components/Error/ErrorMessage"; | ||
import Link from "next/link"; | ||
import path from "path"; | ||
|
||
type PageProps = { | ||
params: { componentName: string }; | ||
}; | ||
|
||
// TODO: I'll be back to refactor: Because components should not handle logic | ||
export default async function Page({ params }: PageProps) { | ||
// <ErrorMessage message="Veuillez vérifier si cette catégorie de composants existe." /> | ||
|
||
// <ErrorMessage | ||
// title="Erreur de connexion" | ||
// message="Impossible de se connecter au serveur. Veuillez réessayer." | ||
// dismissible | ||
// onDismiss={() => console.log('Message fermé')} | ||
// className="my-8" | ||
// /> | ||
|
||
// TODO: recuperer les titres et description de chaque composant | ||
const componentsData = await fs.readFile( | ||
process.cwd() + | ||
`/src/data/components/galsen-ui-${params.componentName}.mdx`, | ||
"utf8" | ||
const componentMdxPath = path.join( | ||
process.cwd(), | ||
"public", | ||
"data", | ||
"components", | ||
`galsen-ui-${params.componentName}.mdx` | ||
); | ||
const mdxSource = await serialize(componentsData, { parseFrontmatter: true }); | ||
|
||
const componentHTMLFiles = await fs.readdir( | ||
process.cwd() + `/public/components/${params.componentName}`, | ||
"utf8" | ||
); | ||
// TODO: Need refactor: Implemented error handling but it should be optimized | ||
try { | ||
const componentsData = await fs.readFile(componentMdxPath, "utf8"); | ||
const mdxSource = await serialize(componentsData, { | ||
parseFrontmatter: true, | ||
}); | ||
|
||
const mdxScope = { | ||
files: componentHTMLFiles, | ||
componentSlug: params.componentName, | ||
components: mdxSource.frontmatter.components, | ||
}; | ||
const componentHTMLFiles = await fs.readdir( | ||
path.join(process.cwd(), "public", "components", params.componentName), | ||
"utf8" | ||
); | ||
|
||
return ( | ||
<main className=""> | ||
<section className="px-4 py-16 sm:max-w-7xl sm:mx-auto"> | ||
<Link href="/" passHref> | ||
<button className="py-2 px-4 mb-3 bg-blue-500 text-white rounded hover:bg-blue-600"> | ||
Retour | ||
</button> | ||
</Link> | ||
<RemoteMdxWrapper | ||
mdxSource={mdxSource} | ||
mdxScope={mdxScope} | ||
mdxComponents={{ | ||
h1: H1, | ||
RenderHTMLFiles, | ||
}} | ||
/> | ||
</section> | ||
</main> | ||
); | ||
const mdxScope = { | ||
files: componentHTMLFiles, | ||
componentSlug: params.componentName, | ||
components: mdxSource.frontmatter.components, | ||
}; | ||
|
||
return ( | ||
<main className=""> | ||
<section className="px-4 py-16 sm:max-w-7xl sm:mx-auto"> | ||
<Link href="/" passHref> | ||
<button className="py-2 px-4 mb-3 bg-blue-500 text-white rounded hover:bg-blue-600"> | ||
Retour | ||
</button> | ||
</Link> | ||
<RemoteMdxWrapper | ||
mdxSource={mdxSource} | ||
mdxScope={mdxScope} | ||
mdxComponents={{ | ||
h1: H1, | ||
RenderHTMLFiles, | ||
}} | ||
/> | ||
</section> | ||
</main> | ||
); | ||
} catch (error) { | ||
console.error( | ||
`Erreur lors de la lecture du fichier MDX pour ${params.componentName}:`, | ||
error | ||
); | ||
return ( | ||
<main> | ||
<section className="px-4 py-16 text-center"> | ||
<h1 className="text-4xl font-extrabold text-red-600"> | ||
Erreur de chargement | ||
</h1> | ||
<p> | ||
Le composant spécifié est introuvable ou une erreur s'est | ||
produite. | ||
</p> | ||
</section> | ||
</main> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.