mirror of
https://github.com/10h30/astroplate.git
synced 2026-06-05 15:08:00 +09:00
refactor jsonGenerator.js to be esmodule
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
const fs = require("fs");
|
import fs from "node:fs";
|
||||||
const path = require("path");
|
import path from "node:path";
|
||||||
const matter = require("gray-matter");
|
import matter from "gray-matter";
|
||||||
|
|
||||||
const CONTENT_DEPTH = 2;
|
const CONTENT_DEPTH = 2;
|
||||||
const JSON_FOLDER = "./.json";
|
const JSON_FOLDER = "./.json";
|
||||||
@@ -41,10 +41,7 @@ const getData = (folder, groupDepth) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const publishedPages = getPaths.filter(
|
return getPaths.filter((page) => !page.frontmatter?.draft && page);
|
||||||
(page) => !page.frontmatter?.draft && page,
|
|
||||||
);
|
|
||||||
return publishedPages;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -60,7 +57,8 @@ try {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// merger json files for search
|
// merger json files for search
|
||||||
const posts = require(`../${JSON_FOLDER}/posts.json`);
|
const postsPath = new URL(`../${JSON_FOLDER}/posts.json`, import.meta.url);
|
||||||
|
const posts = JSON.parse(fs.readFileSync(postsPath, "utf8"));
|
||||||
const search = [...posts];
|
const search = [...posts];
|
||||||
fs.writeFileSync(`${JSON_FOLDER}/search.json`, JSON.stringify(search));
|
fs.writeFileSync(`${JSON_FOLDER}/search.json`, JSON.stringify(search));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user