mirror of
https://github.com/hazemKrimi/personal-website.git
synced 2026-05-01 18:00:26 +00:00
Fix content utilities
This commit is contained in:
+39
-31
@@ -7,46 +7,54 @@ const blogPostsDirectory = path.join(process.cwd(), '_blog');
|
|||||||
export const getBlogPosts = () => {
|
export const getBlogPosts = () => {
|
||||||
const fileNames = fs.readdirSync(blogPostsDirectory);
|
const fileNames = fs.readdirSync(blogPostsDirectory);
|
||||||
|
|
||||||
const allBlogPostsData = fileNames.map(filename => {
|
if (fileNames) {
|
||||||
const slug = filename.replace('.mdx', '');
|
const allBlogPostsData = fileNames.map(filename => {
|
||||||
|
const slug = filename.replace('.mdx', '');
|
||||||
|
|
||||||
const fullPath = path.join(blogPostsDirectory, filename);
|
const fullPath = path.join(blogPostsDirectory, filename);
|
||||||
const fileContents = fs.readFileSync(fullPath, 'utf8');
|
const fileContents = fs.readFileSync(fullPath, 'utf8');
|
||||||
const { data } = matter(fileContents);
|
const { data } = matter(fileContents);
|
||||||
|
|
||||||
const options = { month: 'long', day: 'numeric', year: 'numeric' };
|
const options = { month: 'long', day: 'numeric', year: 'numeric' };
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const formattedDate = new Date(data.date).toLocaleDateString('en-IN', options);
|
const formattedDate = new Date(data.date).toLocaleDateString('en-IN', options);
|
||||||
|
|
||||||
const frontmatter = {
|
const frontmatter = {
|
||||||
...data,
|
...data,
|
||||||
date: formattedDate
|
date: formattedDate
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
slug,
|
slug,
|
||||||
...frontmatter
|
...frontmatter
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return allBlogPostsData.sort((a, b) => {
|
return allBlogPostsData.sort((a, b) => {
|
||||||
if (new Date(a.date) < new Date(b.date)) {
|
if (new Date(a.date) < new Date(b.date)) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getBlogPostsSlugs = () => {
|
export const getBlogPostsSlugs = () => {
|
||||||
const fileNames = fs.readdirSync(blogPostsDirectory);
|
const fileNames = fs.readdirSync(blogPostsDirectory);
|
||||||
|
|
||||||
return fileNames.map(filename => {
|
if (fileNames) {
|
||||||
return {
|
return fileNames.map(filename => {
|
||||||
params: {
|
return {
|
||||||
slug: filename.replace('.mdx', '')
|
params: {
|
||||||
}
|
slug: filename.replace('.mdx', '')
|
||||||
};
|
}
|
||||||
});
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getBlogPostdata = async (slug: string) => {
|
export const getBlogPostdata = async (slug: string) => {
|
||||||
|
|||||||
+39
-31
@@ -7,46 +7,54 @@ const portfolioProjects = path.join(process.cwd(), '_portfolio');
|
|||||||
export const getPortfolioProjects = () => {
|
export const getPortfolioProjects = () => {
|
||||||
const fileNames = fs.readdirSync(portfolioProjects);
|
const fileNames = fs.readdirSync(portfolioProjects);
|
||||||
|
|
||||||
const allPortfolioProjectsData = fileNames.map(filename => {
|
if (fileNames) {
|
||||||
const slug = filename.replace('.mdx', '');
|
const allPortfolioProjectsData = fileNames.map(filename => {
|
||||||
|
const slug = filename.replace('.mdx', '');
|
||||||
|
|
||||||
const fullPath = path.join(portfolioProjects, filename);
|
const fullPath = path.join(portfolioProjects, filename);
|
||||||
const fileContents = fs.readFileSync(fullPath, 'utf8');
|
const fileContents = fs.readFileSync(fullPath, 'utf8');
|
||||||
const { data } = matter(fileContents);
|
const { data } = matter(fileContents);
|
||||||
|
|
||||||
const options = { month: 'long', day: 'numeric', year: 'numeric' };
|
const options = { month: 'long', day: 'numeric', year: 'numeric' };
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const formattedDate = new Date(data.date).toLocaleDateString('en-IN', options);
|
const formattedDate = new Date(data.date).toLocaleDateString('en-IN', options);
|
||||||
|
|
||||||
const frontmatter = {
|
const frontmatter = {
|
||||||
...data,
|
...data,
|
||||||
date: formattedDate
|
date: formattedDate
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
slug,
|
slug,
|
||||||
...frontmatter
|
...frontmatter
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return allPortfolioProjectsData.sort((a, b) => {
|
return allPortfolioProjectsData.sort((a, b) => {
|
||||||
if (new Date(a.date) < new Date(b.date)) {
|
if (new Date(a.date) < new Date(b.date)) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPortfolioPorjectsSlugs = () => {
|
export const getPortfolioPorjectsSlugs = () => {
|
||||||
const fileNames = fs.readdirSync(portfolioProjects);
|
const fileNames = fs.readdirSync(portfolioProjects);
|
||||||
|
|
||||||
return fileNames.map(filename => {
|
if (fileNames) {
|
||||||
return {
|
return fileNames.map(filename => {
|
||||||
params: {
|
return {
|
||||||
slug: filename.replace('.mdx', '')
|
params: {
|
||||||
}
|
slug: filename.replace('.mdx', '')
|
||||||
};
|
}
|
||||||
});
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPortfolioProjectdata = async (slug: string) => {
|
export const getPortfolioProjectdata = async (slug: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user