mirror of
https://github.com/hazemKrimi/personal-website.git
synced 2026-05-02 02:10:27 +00:00
Add prettier configuration
This commit is contained in:
+54
-51
@@ -5,71 +5,74 @@ import matter from 'gray-matter';
|
||||
const blogPostsDirectory = path.join(process.cwd(), '_blog');
|
||||
|
||||
export const getBlogPosts = () => {
|
||||
try {
|
||||
const fileNames = fs.readdirSync(blogPostsDirectory);
|
||||
try {
|
||||
const fileNames = fs.readdirSync(blogPostsDirectory);
|
||||
|
||||
if (!fileNames) return [];
|
||||
if (!fileNames) return [];
|
||||
|
||||
const allBlogPostsData = fileNames.map(filename => {
|
||||
const slug = filename.replace('.mdx', '');
|
||||
const allBlogPostsData = fileNames.map((filename) => {
|
||||
const slug = filename.replace('.mdx', '');
|
||||
|
||||
const fullPath = path.join(blogPostsDirectory, filename);
|
||||
const fileContents = fs.readFileSync(fullPath, 'utf8');
|
||||
const { data } = matter(fileContents);
|
||||
const fullPath = path.join(blogPostsDirectory, filename);
|
||||
const fileContents = fs.readFileSync(fullPath, 'utf8');
|
||||
const { data } = matter(fileContents);
|
||||
|
||||
const options = { month: 'long', day: 'numeric', year: 'numeric' };
|
||||
// @ts-ignore
|
||||
const formattedDate = new Date(data.date).toLocaleDateString('en-IN', options);
|
||||
const options = { month: 'long', day: 'numeric', year: 'numeric' };
|
||||
// @ts-ignore
|
||||
const formattedDate = new Date(data.date).toLocaleDateString(
|
||||
'en-IN',
|
||||
options
|
||||
);
|
||||
|
||||
const frontmatter = {
|
||||
...data,
|
||||
date: formattedDate
|
||||
};
|
||||
return {
|
||||
slug,
|
||||
...frontmatter
|
||||
};
|
||||
});
|
||||
const frontmatter = {
|
||||
...data,
|
||||
date: formattedDate,
|
||||
};
|
||||
return {
|
||||
slug,
|
||||
...frontmatter,
|
||||
};
|
||||
});
|
||||
|
||||
return allBlogPostsData.sort((a, b) => {
|
||||
if (new Date(a.date) < new Date(b.date)) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
return allBlogPostsData.sort((a, b) => {
|
||||
if (new Date(a.date) < new Date(b.date)) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export const getBlogPostsSlugs = () => {
|
||||
try {
|
||||
const fileNames = fs.readdirSync(blogPostsDirectory);
|
||||
try {
|
||||
const fileNames = fs.readdirSync(blogPostsDirectory);
|
||||
|
||||
if (!fileNames) return [];
|
||||
if (!fileNames) return [];
|
||||
|
||||
return fileNames.map(filename => {
|
||||
return {
|
||||
params: {
|
||||
slug: filename.replace('.mdx', '')
|
||||
}
|
||||
};
|
||||
});
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
return fileNames.map((filename) => {
|
||||
return {
|
||||
params: {
|
||||
slug: filename.replace('.mdx', ''),
|
||||
},
|
||||
};
|
||||
});
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export const getBlogPostdata = async (slug: string) => {
|
||||
try {
|
||||
const fullPath = path.join(blogPostsDirectory, `${slug}.mdx`);
|
||||
const postContent = fs.readFileSync(fullPath, 'utf8');
|
||||
try {
|
||||
const fullPath = path.join(blogPostsDirectory, `${slug}.mdx`);
|
||||
const postContent = fs.readFileSync(fullPath, 'utf8');
|
||||
|
||||
if (!postContent) return undefined;
|
||||
if (!postContent) return undefined;
|
||||
|
||||
return postContent;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
return postContent;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
+12
-11
@@ -1,19 +1,20 @@
|
||||
export const GOOGLE_ANALYTICS_KEY = process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_KEY;
|
||||
export const GOOGLE_ANALYTICS_KEY =
|
||||
process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_KEY;
|
||||
|
||||
export const pageview = (url: any) => {
|
||||
// @ts-ignore
|
||||
window.gtag('config', GOOGLE_ANALYTICS_KEY, {
|
||||
page_path: url
|
||||
});
|
||||
// @ts-ignore
|
||||
window.gtag('config', GOOGLE_ANALYTICS_KEY, {
|
||||
page_path: url,
|
||||
});
|
||||
};
|
||||
|
||||
export const event = ({ action, category, label, value }: any) => {
|
||||
// @ts-ignore
|
||||
window.gtag('event', action, {
|
||||
event_category: category,
|
||||
event_label: label,
|
||||
value: value
|
||||
});
|
||||
// @ts-ignore
|
||||
window.gtag('event', action, {
|
||||
event_category: category,
|
||||
event_label: label,
|
||||
value: value,
|
||||
});
|
||||
};
|
||||
|
||||
export const initAnalytics = () => `
|
||||
|
||||
+54
-51
@@ -5,71 +5,74 @@ import matter from 'gray-matter';
|
||||
const projects = path.join(process.cwd(), '_projects');
|
||||
|
||||
export const getProjects = () => {
|
||||
try {
|
||||
const fileNames = fs.readdirSync(projects);
|
||||
try {
|
||||
const fileNames = fs.readdirSync(projects);
|
||||
|
||||
if (!fileNames) return [];
|
||||
if (!fileNames) return [];
|
||||
|
||||
const allProjectsData = fileNames.map(filename => {
|
||||
const slug = filename.replace('.mdx', '');
|
||||
const allProjectsData = fileNames.map((filename) => {
|
||||
const slug = filename.replace('.mdx', '');
|
||||
|
||||
const fullPath = path.join(projects, filename);
|
||||
const fileContents = fs.readFileSync(fullPath, 'utf8');
|
||||
const { data } = matter(fileContents);
|
||||
const fullPath = path.join(projects, filename);
|
||||
const fileContents = fs.readFileSync(fullPath, 'utf8');
|
||||
const { data } = matter(fileContents);
|
||||
|
||||
const options = { month: 'long', day: 'numeric', year: 'numeric' };
|
||||
// @ts-ignore
|
||||
const formattedDate = new Date(data.date).toLocaleDateString('en-IN', options);
|
||||
const options = { month: 'long', day: 'numeric', year: 'numeric' };
|
||||
// @ts-ignore
|
||||
const formattedDate = new Date(data.date).toLocaleDateString(
|
||||
'en-IN',
|
||||
options
|
||||
);
|
||||
|
||||
const frontmatter = {
|
||||
...data,
|
||||
date: formattedDate
|
||||
};
|
||||
return {
|
||||
slug,
|
||||
...frontmatter
|
||||
};
|
||||
});
|
||||
const frontmatter = {
|
||||
...data,
|
||||
date: formattedDate,
|
||||
};
|
||||
return {
|
||||
slug,
|
||||
...frontmatter,
|
||||
};
|
||||
});
|
||||
|
||||
return allProjectsData.sort((a, b) => {
|
||||
if (new Date(a.date) < new Date(b.date)) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
return allProjectsData.sort((a, b) => {
|
||||
if (new Date(a.date) < new Date(b.date)) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export const getPorjectsSlugs = () => {
|
||||
try {
|
||||
const fileNames = fs.readdirSync(projects);
|
||||
try {
|
||||
const fileNames = fs.readdirSync(projects);
|
||||
|
||||
if (!fileNames) return [];
|
||||
if (!fileNames) return [];
|
||||
|
||||
return fileNames.map(filename => {
|
||||
return {
|
||||
params: {
|
||||
slug: filename.replace('.mdx', '')
|
||||
}
|
||||
};
|
||||
});
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
return fileNames.map((filename) => {
|
||||
return {
|
||||
params: {
|
||||
slug: filename.replace('.mdx', ''),
|
||||
},
|
||||
};
|
||||
});
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export const getProjectdata = async (slug: string) => {
|
||||
try {
|
||||
const fullPath = path.join(projects, `${slug}.mdx`);
|
||||
const postContent = fs.readFileSync(fullPath, 'utf8');
|
||||
try {
|
||||
const fullPath = path.join(projects, `${slug}.mdx`);
|
||||
const postContent = fs.readFileSync(fullPath, 'utf8');
|
||||
|
||||
if (!postContent) return undefined;
|
||||
if (!postContent) return undefined;
|
||||
|
||||
return postContent;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
return postContent;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user