saicaca / fuwari

✨A static blog template built with Astro.
https://fuwari.vercel.app
MIT License
1.41k stars 326 forks source link

If a category contains #, problems occur during the build process #199

Open PIXELHIZE opened 1 month ago

PIXELHIZE commented 1 month ago

While I was making a post using these sources, I accidentally found out that if a category contains #, an error occurs during the birch. I've been looking for a way to fix this error. My conclusion is that in the path node_modules\.pnpm\astro@4.12.2_@types+node@20.14.12_lightningcss@1.25.1_sass@1.77.8_stylus@0.63.0_terser@5.31.3_typescript@5.5.4\node_modules\astro\dist\core\fs\index.js, in the

function removeEmptyDirs(root) {
  const dir = fileURLToPath(root);
  if (!fs.statSync(dir).isDirectory()) return;
  let files = fs.readdirSync(dir);
  if (files.length > 0) {
    files.map((file) => {
      const url = new URL(`./${file}`, appendForwardSlash(root.toString()));
      removeEmptyDirs(url);
    });
    files = fs.readdirSync(dir);
  }
  if (files.length === 0) {
    fs.rmdirSync(dir);
  }
}

is modified as follows.

function removeEmptyDirs(root) {
  const dir = fileURLToPath(root);
  if (!fs.statSync(dir).isDirectory()) return;
  let files = fs.readdirSync(dir);
  if (files.length > 0) {
    files.map((file) => {
      // fix
      const encodedFile = encodeURIComponent(file);
      const url = new URL(`./${encodedFile}`, appendForwardSlash(root.toString()));
      removeEmptyDirs(url);
    });
    files = fs.readdirSync(dir);
  }
  if (files.length === 0) {
    fs.rmdirSync(dir);
  }
}

Yes, that's right. As you can see from the path, to fix that error, you need to upload node_modules along with the site build. This is a waste of resources and a lot of work. I need your help.

saicaca commented 1 month ago

Currently, tags and categories cannot contain URL reserved characters like # / ?. I tried encoding the string but it didn't help since Astro automatically decodes the path during the build process.

The good news is that Astro 5.0 will remove the decoding, so I will try to fix this when 5.0 is out.