facebook / facebook/docusaurus

Early error if a blog post has slug: '/' that would be shadowed by home page

Ouverte
#7,870 7 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
feature
Langage dominant
TypeScript
Étoiles
66.2k
Forks
10k
Merge moyen
1 j 3 h
PR mergées (30 j)
52

Description

### Have you read the Contributing Guidelines on issues?

- [X] I have read the [Contributing Guidelines on issues](https://github.com/facebook/docusaurus/blob/main/CONTRIBUTING.md#reporting-new-issues).

### Prerequisites

- [X] I'm using the latest version of Docusaurus.
- [ ] I have tried the `npm run clear` or `yarn clear` command.
- [X] I have tried `rm -rf node_modules yarn.lock package-lock.json` and re-installing packages.
- [X] I have tried creating a repro with https://new.docusaurus.io.
- [X] I have read the console error message carefully (if applicable).

### Description

A md file with frontmatter with slug of `/` woule generate path as `/blog/` by default.

But actually, `/blog/` would redirect to be `/blog`, i.e. the home page of blogs.

### Steps to reproduce

place a md file under blog dir, i.e. `/blog/test.md`:

```md
---
slug: /
---

# test
```

### Expected behavior

- possible behavior 1: build the project, then we can visit `/blog/` (or `/blog/xxx`), which is rendered from `/blog/test.md`
- possible behavior 2: just refuse or warn the render requirement of slug `/` in the building part, e.g. added the ruler in `joi` in `packages/docusaurus-plugin-content-blog/src/frontMatter.ts:66`.

### Actual behavior

1. `/blog` or `/blog/` all points to the home page of blog
2. but the blog page (containing 5 articles default) would have the right arcticle rendered from `/blog/test.md`
3. if the arcticle with slug of `/` failed to be parsed at the same time (e.g. `

xxx
` is invalid since the valid jsx grammar is `style={{color: "red"}}`.), then the build engine would not report the error directly from this arcticle, but from the page(containing of 5 arcticles defualt), which is very confusing to the developers (e.g. me).
- I do not know well now that the md would be finally rendered, why the render part of `/blog/` should be just skipped ...

### Your environment

- Public source code:
- Public site URL:
- Docusaurus version used:
- Environment name and version (e.g. Chrome 89, Node.js 16.4):
- Operating system and version (e.g. Ubuntu 20.04.2 LTS):

### Self-service

- [X] I'd be willing to fix this bug myself.

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.