zeon-studio / nextplate

Nextplate is a free starter template built with Next.js and TailwindCSS. It provides you with almost everything you need to jump-start your Next.js project. Try Nextplate and save yourself hours of work.
https://zeon.studio/preview?project=nextplate
MIT License
397 stars 251 forks source link

Error building app on Windows machine #20

Closed accountsware closed 9 months ago

accountsware commented 9 months ago

Windows specific issue


npm run build

image

Solution: to update code to system agnostic path separator.

`const fs = require("fs"); const path = require("path"); const matter = require("gray-matter");

const CONTENT_DEPTH = 2; const JSON_FOLDER = "./.json"; const BLOG_FOLDER = "src/content/blog";

// get data from markdown const getData = (folder, groupDepth) => { const getPath = fs.readdirSync(folder); const removeIndex = getPath.filter((item) => !item.startsWith('_'));

const getPaths = removeIndex.flatMap((filename) => { const filepath = path.join(folder, filename); const stats = fs.statSync(filepath); const isFolder = stats.isDirectory();

if (isFolder) {
  return getData(filepath, groupDepth);
} else if (filename.endsWith(".md") || filename.endsWith(".mdx")) {
  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,
    slug: slug,
    frontmatter: data,
    content: content,
  };
} else {
  return [];
}

});

return getPaths.filter((page) => page && !page.frontmatter?.draft); };

// flatten nested arrays (may not be needed anymore due to flatMap) const flatten = (arr) => arr.reduce((acc, val) => acc.concat(val), []);

try { if (!fs.existsSync(JSON_FOLDER)) { fs.mkdirSync(JSON_FOLDER); }

const data = getData(BLOG_FOLDER, 2); fs.writeFileSync(${JSON_FOLDER}/posts.json, JSON.stringify(flatten(data)));

const posts = require(../${JSON_FOLDER}/posts.json); fs.writeFileSync(${JSON_FOLDER}/search.json, JSON.stringify(posts)); } catch (err) { console.error(err); } `

image

tfsomrat commented 9 months ago

hey @accountsware, I didn't check it on windows. thanks for your code suggestion. I have updated the jsonGenerator. It should work now.