mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-07-21 20:55:56 -04:00
some very minor refactoring/fixing
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user