update content
This commit is contained in:
parent
f13cb160f3
commit
836f960a28
27 changed files with 459 additions and 472 deletions
31
utils/getArtifacts.ts
Normal file
31
utils/getArtifacts.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import fs from "fs";
|
||||
import path from "path";
|
||||
import matter from "gray-matter";
|
||||
|
||||
const root = path.join(process.cwd(), "artifacts");
|
||||
|
||||
export const getArtifacts = (dir: string) => {
|
||||
const fileNames = fs.readdirSync(root + "/" + dir);
|
||||
|
||||
const filtered = fileNames.filter((fileName) => fileName.includes(`.md`));
|
||||
|
||||
return filtered.map((fileName) => {
|
||||
// set id
|
||||
const id = fileName.replace(/\.md$/, "");
|
||||
|
||||
// set full path
|
||||
const fullPath = path.join(root, dir, fileName);
|
||||
|
||||
// read file contents
|
||||
const fileContents = fs.readFileSync(fullPath, "utf8");
|
||||
|
||||
// parse file contents
|
||||
const { data } = matter(fileContents);
|
||||
|
||||
// return id and data
|
||||
return {
|
||||
id,
|
||||
...data,
|
||||
};
|
||||
}) as any[];
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue