mirror of
https://github.com/10h30/astroplate.git
synced 2026-06-05 15:08:00 +09:00
update jsonGenerator
This commit is contained in:
+7
-7
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "astroplate",
|
||||
"version": "3.0.0",
|
||||
"version": "3.0.1",
|
||||
"description": "Astro and Tailwindcss boilerplate",
|
||||
"author": "zeon.studio",
|
||||
"license": "MIT",
|
||||
@@ -19,7 +19,7 @@
|
||||
"@astrojs/rss": "^4.0.1",
|
||||
"@astrojs/sitemap": "^3.0.3",
|
||||
"@astrojs/tailwind": "^5.0.3",
|
||||
"astro": "^4.0.4",
|
||||
"astro": "^4.0.6",
|
||||
"astro-auto-import": "^0.4.2",
|
||||
"date-fns": "^2.30.0",
|
||||
"date-fns-tz": "^2.0.0",
|
||||
@@ -36,24 +36,24 @@
|
||||
"react-lite-youtube-embed": "^2.4.0",
|
||||
"remark-collapse": "^0.1.2",
|
||||
"remark-toc": "^9.0.0",
|
||||
"sharp": "^0.33.0",
|
||||
"sharp": "^0.33.1",
|
||||
"swiper": "^11.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/forms": "^0.5.7",
|
||||
"@tailwindcss/typography": "^0.5.10",
|
||||
"@types/marked": "^5.0.2",
|
||||
"@types/node": "20.10.4",
|
||||
"@types/node": "20.10.5",
|
||||
"@types/react": "18.2.45",
|
||||
"@types/react-dom": "18.2.17",
|
||||
"@types/react-dom": "18.2.18",
|
||||
"autoprefixer": "^10.4.16",
|
||||
"eslint": "^8.55.0",
|
||||
"eslint": "^8.56.0",
|
||||
"postcss": "^8.4.32",
|
||||
"prettier": "^3.1.1",
|
||||
"prettier-plugin-astro": "^0.12.2",
|
||||
"prettier-plugin-tailwindcss": "^0.5.9",
|
||||
"sass": "^1.69.5",
|
||||
"tailwindcss": "^3.3.6",
|
||||
"tailwindcss": "^3.3.7",
|
||||
"tailwind-bootstrap-grid": "^5.1.0",
|
||||
"typescript": "5.3.3"
|
||||
}
|
||||
|
||||
+16
-28
@@ -8,10 +8,10 @@ const BLOG_FOLDER = "src/content/blog";
|
||||
|
||||
// get data from markdown
|
||||
const getData = (folder, groupDepth) => {
|
||||
const getPath = fs.readdirSync(path.join(folder));
|
||||
const removeIndex = getPath.filter((item) => item.match(/^(?!-)/));
|
||||
const getPath = fs.readdirSync(folder);
|
||||
const removeIndex = getPath.filter((item) => !item.startsWith("-"));
|
||||
|
||||
const getPaths = removeIndex.map((filename) => {
|
||||
const getPaths = removeIndex.flatMap((filename) => {
|
||||
const filepath = path.join(folder, filename);
|
||||
const stats = fs.statSync(filepath);
|
||||
const isFolder = stats.isDirectory();
|
||||
@@ -19,18 +19,16 @@ const getData = (folder, groupDepth) => {
|
||||
if (isFolder) {
|
||||
return getData(filepath, groupDepth);
|
||||
} else if (filename.endsWith(".md") || filename.endsWith(".mdx")) {
|
||||
const file = fs.readFileSync(path.join(folder, filename), "utf-8");
|
||||
const { data } = matter(file);
|
||||
const content = matter(file).content;
|
||||
const removeExtension = filepath.replace(/\.[^/.]+$/, "");
|
||||
const slug = data.slug
|
||||
? data.slug
|
||||
: removeExtension
|
||||
.split("/")
|
||||
.slice(CONTENT_DEPTH, removeExtension.split("/").length)
|
||||
.join("/");
|
||||
|
||||
const group = removeExtension.split("/")[Number(groupDepth)];
|
||||
const file = fs.readFileSync(filepath, "utf-8");
|
||||
const { data, content } = matter(file);
|
||||
const pathParts = filepath.split(path.sep);
|
||||
const slug =
|
||||
data.slug ||
|
||||
pathParts
|
||||
.slice(CONTENT_DEPTH)
|
||||
.join("/")
|
||||
.replace(/\.[^/.]+$/, "");
|
||||
const group = pathParts[groupDepth];
|
||||
|
||||
return {
|
||||
group: group,
|
||||
@@ -38,6 +36,8 @@ const getData = (folder, groupDepth) => {
|
||||
frontmatter: data,
|
||||
content: content,
|
||||
};
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
@@ -47,18 +47,6 @@ const getData = (folder, groupDepth) => {
|
||||
return publishedPages;
|
||||
};
|
||||
|
||||
// flatten nested arrays
|
||||
const flatten = (arr) => {
|
||||
return arr.reduce((result, element) => {
|
||||
if (Array.isArray(element)) {
|
||||
result.push(...flatten(element));
|
||||
} else {
|
||||
result.push(element);
|
||||
}
|
||||
return result;
|
||||
}, []);
|
||||
};
|
||||
|
||||
try {
|
||||
// create folder if it doesn't exist
|
||||
if (!fs.existsSync(JSON_FOLDER)) {
|
||||
@@ -68,7 +56,7 @@ try {
|
||||
// create json files
|
||||
fs.writeFileSync(
|
||||
`${JSON_FOLDER}/posts.json`,
|
||||
JSON.stringify(flatten(getData(BLOG_FOLDER, 2))),
|
||||
JSON.stringify(getData(BLOG_FOLDER, 2)),
|
||||
);
|
||||
|
||||
// merger json files for search
|
||||
|
||||
Reference in New Issue
Block a user