some very minor refactoring/fixing

This commit is contained in:
2021-12-31 08:48:56 -05:00
parent 831f8ffe4c
commit 11d245ad66
19 changed files with 32 additions and 49 deletions
+6 -11
View File
@@ -4,14 +4,12 @@ import matter from "gray-matter";
export const NOTES_PATH = path.join(process.cwd(), "notes");
export function getNoteSlugs() {
return fs.readdirSync(NOTES_PATH);
}
export const getNoteSlugs = () => fs.readdirSync(NOTES_PATH);
// Return all md(x) files in NOTES_PATH
export const notePaths = getNoteSlugs().filter((path) => /\.mdx?$/.test(path));
export const notePaths = getNoteSlugs().filter((notePath) => /\.mdx?$/.test(notePath));
export function getNoteBySlug(slug, fields = []) {
export const getNoteBySlug = (slug, fields = []) => {
const realSlug = slug.replace(/\.mdx$/, "");
const fullPath = path.join(NOTES_PATH, `${realSlug}.mdx`);
const fileContents = fs.readFileSync(fullPath, "utf8");
@@ -34,13 +32,10 @@ export function getNoteBySlug(slug, fields = []) {
});
return items;
}
};
export function getAllNotes(fields = []) {
const slugs = getNoteSlugs();
const notes = slugs
export const getAllNotes = (fields = []) =>
getNoteSlugs()
.map((slug) => getNoteBySlug(slug, fields))
// sort notes by date in descending order
.sort((note1: any, note2: any) => (note1.date > note2.date ? -1 : 1));
return notes;
}