alloc / alloc/saus

Support file-based routing

Đang mở
#10 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
backlog roadmap
Ngôn ngữ chính
TypeScript
Star
38
Fork
1
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Inside your `src/node/routes.ts` module:
```ts
import { findPages } from 'saus'

// The "/**" suffix is optional.
findPages('./pages/**', ['*.mdx?', '*.njk'])
```

Paths are relative to the project root, so the `findRoutes` call above would work with the following file structure:

```
my-app/
├─ pages/
│ ├─ index.mdx
│ ├─ users/
│ │ ├─ [id].njk
├─ src/
│ ├─ render.ts
│ ├─ node/
│ │ ├─ routes.ts
```

Renderers would receive the file content in string form, passed by the `module.default` argument.

We would also expose a `fileType` property, which allows a renderer to handle multiple file types if so desired.

Renderers could still target specific routes (via route paths) and route parameters could be used to parse out parts of the filename. In the example above, a page named `./pages/foo/index.mdx` would be served for the `/foo` and `/foo/` URLs.

### Dynamic routes

Naturally, square brackets in a page's filename would indicate route parameters. For example, a page named…
```
./pages/users/[id].njk
```
…would be served by the `/users/:id` route. Although, these pages would not be eligible for pre-rendering (until we come up with a suitable API, of course).

### Front matter

Lastly, a helper for parsing [front matter](https://forestry.io/docs/editing/front-matter) from a page would be exported by the `saus` module.

```ts
import { extractFrontMatter } from 'saus'

render((module) => {
const metadata = extractFrontMatter(module)
// return [...]
})
```

Calling it would update the content of `module.default`, removing the parsed front matter.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.