mirror of
https://github.com/hazemKrimi/personal-website.git
synced 2026-05-02 02:10:27 +00:00
Handle file reading errors
This commit is contained in:
+20
-12
@@ -5,9 +5,11 @@ import matter from 'gray-matter';
|
||||
const portfolioProjects = path.join(process.cwd(), '_portfolio');
|
||||
|
||||
export const getPortfolioProjects = () => {
|
||||
const fileNames = fs.readdirSync(portfolioProjects);
|
||||
try {
|
||||
const fileNames = fs.readdirSync(portfolioProjects);
|
||||
|
||||
if (!fileNames) return [];
|
||||
|
||||
if (fileNames) {
|
||||
const allPortfolioProjectsData = fileNames.map(filename => {
|
||||
const slug = filename.replace('.mdx', '');
|
||||
|
||||
@@ -36,15 +38,17 @@ export const getPortfolioProjects = () => {
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [];
|
||||
};
|
||||
|
||||
export const getPortfolioPorjectsSlugs = () => {
|
||||
const fileNames = fs.readdirSync(portfolioProjects);
|
||||
try {
|
||||
const fileNames = fs.readdirSync(portfolioProjects);
|
||||
|
||||
if (!fileNames) return [];
|
||||
|
||||
if (fileNames) {
|
||||
return fileNames.map(filename => {
|
||||
return {
|
||||
params: {
|
||||
@@ -52,16 +56,20 @@ export const getPortfolioPorjectsSlugs = () => {
|
||||
}
|
||||
};
|
||||
});
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [];
|
||||
};
|
||||
|
||||
export const getPortfolioProjectdata = async (slug: string) => {
|
||||
const fullPath = path.join(portfolioProjects, `${slug}.mdx`);
|
||||
const postContent = fs.readFileSync(fullPath, 'utf8');
|
||||
try {
|
||||
const fullPath = path.join(portfolioProjects, `${slug}.mdx`);
|
||||
const postContent = fs.readFileSync(fullPath, 'utf8');
|
||||
|
||||
if (!postContent) return undefined;
|
||||
if (!postContent) return undefined;
|
||||
|
||||
return postContent;
|
||||
return postContent;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user