@gravito/monolith 1.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -0
- package/dist/index.js +5596 -0
- package/dist/src/index.js +5596 -0
- package/package.json +40 -0
- package/src/ContentManager.ts +116 -0
- package/src/index.ts +42 -0
- package/tests/content.test.ts +41 -0
- package/tests/fixtures/docs/en/install.md +13 -0
- package/tests/fixtures/docs/zh/install.md +13 -0
- package/tsconfig.json +19 -0
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @gravito/monolith
|
|
2
|
+
|
|
3
|
+
> The Eternal Knowledge Block. File-based CMS for Gravito.
|
|
4
|
+
|
|
5
|
+
Turn your markdown files into a powerful API. Perfect for blogs, documentation, and static sites.
|
|
6
|
+
|
|
7
|
+
## 📦 Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @gravito/monolith
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 🚀 Quick Start
|
|
14
|
+
|
|
15
|
+
1. **Register the Orbit**:
|
|
16
|
+
```typescript
|
|
17
|
+
import { PlanetCore } from 'gravito-core';
|
|
18
|
+
import { OrbitContent } from '@gravito/monolith';
|
|
19
|
+
|
|
20
|
+
const core = new PlanetCore();
|
|
21
|
+
|
|
22
|
+
core.boot({
|
|
23
|
+
orbits: [OrbitContent],
|
|
24
|
+
config: {
|
|
25
|
+
content: {
|
|
26
|
+
root: './content', // Root directory for your markdown files
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
2. **Create Content**:
|
|
33
|
+
Create `./content/blog/hello-world.md`:
|
|
34
|
+
```markdown
|
|
35
|
+
---
|
|
36
|
+
title: Hello World
|
|
37
|
+
date: 2024-01-01
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
# Welcome to Gravito
|
|
41
|
+
This is my first post.
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
3. **Fetch Content**:
|
|
45
|
+
```typescript
|
|
46
|
+
app.get('/blog/:slug', async (c) => {
|
|
47
|
+
const content = c.get('content');
|
|
48
|
+
const post = await content.collection('blog').slug(c.req.param('slug')).fetch();
|
|
49
|
+
|
|
50
|
+
return c.json(post);
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## ✨ Features
|
|
55
|
+
|
|
56
|
+
- **Markdown Support**: Full Markdown parsing via `marked`.
|
|
57
|
+
- **Frontmatter**: Parses YAML frontmatter using `gray-matter`.
|
|
58
|
+
- **Collections**: Organize content into collections (folders).
|
|
59
|
+
- **Query API**: Fluent API to fetch by slug, list all, etc. `collection('posts').slug('...').fetch()`.
|
|
60
|
+
|
|
61
|
+
## 📚 API
|
|
62
|
+
|
|
63
|
+
### `content.collection(name: string)`
|
|
64
|
+
|
|
65
|
+
Select a content collection (subdirectory).
|
|
66
|
+
|
|
67
|
+
### `.slug(slug: string)`
|
|
68
|
+
|
|
69
|
+
Target a specific file by name (without extension).
|
|
70
|
+
|
|
71
|
+
### `.fetch()`
|
|
72
|
+
|
|
73
|
+
Retrieves the parsed content object: `{ meta, content, html }`.
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
MIT
|