Skip to content

Commit

Permalink
Added markdown content output option to be rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
gabros20 committed Jan 17, 2025
1 parent acfeff0 commit c589c0b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 97 deletions.
54 changes: 3 additions & 51 deletions src/components/Accordion/GlossaryAccordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ import Icon from "@/macros/Icons/Icon";
import SearchInput from "@/macros/Forms/SearchInput";
import Link from "next/link";
import PrimaryButton from "@/macros/Buttons/PrimaryButton";
import FacebookSVG from "@/macros/SVGs/FacebookSVG";
import XTwitterSVG from "@/macros/SVGs/XTwitterSVG";
import EmailAltSVG from "@/macros/SVGs/EmailAltSVG";
import CopySVG from "@/macros/SVGs/CopySVG";
import { usePathname } from "next/navigation";
import Markdown from "markdown-to-jsx";

const GlossaryAccordion = ({ glossaryData }) => {
const router = useRouter();
Expand Down Expand Up @@ -169,8 +166,8 @@ const GlossaryAccordion = ({ glossaryData }) => {
<Heading tag={"h3"} size={"sm"} className={"text-left mb-4"}>
{term.title}
</Heading>
<Body size={"md"} className={`text-black-subtle`}>
{term.description}
<Body size={"md"} tag={"div"} className={`text-black-subtle`}>
<Markdown>{term.content || term.description}</Markdown>
</Body>
</div>
</div>
Expand Down Expand Up @@ -199,49 +196,4 @@ const GlossaryAccordion = ({ glossaryData }) => {
);
};

const ShareIcons = ({ slug }) => {
const socialLinks = [
{
url: `https://twitter.com/intent/tweet?url=https://celestia.org/glossary/${slug}`,
Icon: <XTwitterSVG className='w-5' />,
IconHover: <XTwitterSVG dark className='w-6' />,
text: "Share on Twitter/X",
},
{
url: `mailto:?subject=Check out Celestia&body=Check out Celestia: https://celestia.org/glossary/${slug}`,
Icon: <EmailAltSVG className='w-6' />,
IconHover: <EmailAltSVG dark className='w-7 h-7' />,
text: "Share via Email",
},
{
url: `https://www.facebook.com/sharer/sharer.php?u=https://celestia.org/glossary/${slug}`,
Icon: <FacebookSVG className='w-6' />,
IconHover: <FacebookSVG dark className='w-7 h-7' />,
text: "Share on Facebook",
},
{
onClick: () => {
navigator.clipboard.writeText(`https://celestia.org/glossary/${slug}`);
},
Icon: <CopySVG className='w-7 h-7' />,
IconHover: <CopySVG dark className='w-8 h-8' />,
text: "Copy link",
},
];

return (
<div className='flex'>
{socialLinks.map((link, index) => {
const Tag = link.url ? "a" : "button";

return (
<Tag key={index} href={link.url} onClick={link.onClick} target='_blank' rel='noreferrer' className='group'>
<Icon Icon={link.Icon} hover dark={false} border={false} HoverIcon={link.IconHover} size={40} transparentBg={false} />
</Tag>
);
})}
</div>
);
};

export default GlossaryAccordion;
94 changes: 48 additions & 46 deletions src/lib/getPostsMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,55 @@ import fs from "fs";
import matter from "gray-matter";

export const getPostsMetadata = (basePath) => {
const directory = `src/content/${basePath}/`;

// Check if the directory exists
if (!fs.existsSync(directory)) {
console.error(`Directory not found: ${directory}`);
return [];
}

const files = fs.readdirSync(directory);
const markdownPosts = files.filter((file) => file.endsWith(".md"));

const posts = markdownPosts.map((filename) => {
const fullPath = `${directory}${filename}`;
const fileContents = fs.readFileSync(fullPath, "utf8");
const matterResukts = matter(fileContents);

return {
title: matterResukts.data.title,
description: matterResukts.data.description,
slug: filename.replace(/\.md$/, ""),
};
});

return posts;
const directory = `src/content/${basePath}/`;

// Check if the directory exists
if (!fs.existsSync(directory)) {
console.error(`Directory not found: ${directory}`);
return [];
}

const files = fs.readdirSync(directory);
const markdownPosts = files.filter((file) => file.endsWith(".md"));

const posts = markdownPosts.map((filename) => {
const fullPath = `${directory}${filename}`;
const fileContents = fs.readFileSync(fullPath, "utf8");
const matterResults = matter(fileContents);

return {
title: matterResults.data.title,
description: matterResults.data.description,
content: matterResults.content,
slug: filename.replace(/\.md$/, ""),
};
});

return posts;
};

export const getPostMetadata = (basePath, fileName) => {
const filePath = `src/content/${basePath}/${fileName}`;

// Check if the file exists
if (!fs.existsSync(filePath)) {
console.error(`File not found: ${filePath}`);
return null;
}

// Check if the file is a markdown file
if (!fileName.endsWith(".md")) {
console.error(`File is not a markdown file: ${filePath}`);
return null;
}

const fileContents = fs.readFileSync(filePath, "utf8");
const matterResults = matter(fileContents);

return {
title: matterResults.data.title,
description: matterResults.data.description,
slug: fileName.replace(/\.md$/, ""),
};
const filePath = `src/content/${basePath}/${fileName}`;

// Check if the file exists
if (!fs.existsSync(filePath)) {
console.error(`File not found: ${filePath}`);
return null;
}

// Check if the file is a markdown file
if (!fileName.endsWith(".md")) {
console.error(`File is not a markdown file: ${filePath}`);
return null;
}

const fileContents = fs.readFileSync(filePath, "utf8");
const matterResults = matter(fileContents);

return {
title: matterResults.data.title,
description: matterResults.data.description,
content: matterResults.content,
slug: fileName.replace(/\.md$/, ""),
};
};

0 comments on commit c589c0b

Please sign in to comment.