UNPKG

2.63 kBMarkdownView Raw
1# Mightymite
2A tiny (yet mighty) markdown-based content store and API.
3
4- [Why?](#why?)
5- [How it works](#how-it-works)
6- [Installation](#installation)
7- [Usage](#usage)
8- [Configuration](#config)
9- [Import syntax](#import-syntax)
10- [Data files](#data-files)
11- [Routes file](#routes-file)
12
13## Why?
14I needed a dead-simple database-less API for accessing content written in markdown with YAML front-matter, that also handles the compilation into JSON and parsing of markdown into HTML. The file-based nature of the API lends itself to hosting anywhere static files may be hosted.
15
16## How it works
17Content is organized as `index.md` files within `/content`, in a hierarchy of directories that will map to the client application routes. Each file is parsed as YAML/markdown, with the body compiled as HTML, and output as JSON to `/api`.
18
19To avoid unnecessary imports on the client side, documents may import certain collections of other files at compilation time using an [import syntax](#import-syntax). For instance, you may want to include a limited set of attributes from the latest _n_ blog posts on the home page.
20
21Beyond that, any front-mattter attributes will be available under `attributes`, and the body HTML will be available at `body`.
22
23## Installation
24```sh
25$ yarn add mightymite # or npm install mightymite
26```
27
28## Usage
29```sh
30# View commands and options
31$ mightymite --help
32
33# Build
34$ mightymite build
35
36# Rebuild on file change
37$ mightymite watch
38
39# Specify source or output directories other than the defaults
40$ mightymite build --src src --out dist
41$ mightymite watch --src src --out dist
42```
43
44## Configuration
45You may use a custom config file by passing along the `config` flag:
46
47```sh
48$ mightymite build --config mightymite.json
49```
50
51And in `mightymite.json`:
52```json
53{
54 "debug": "true",
55 "src": "src",
56 "out": "dist"
57}
58```
59
60## Import syntax
61Content from additional files may be imported using the `import` attribute:
62
63```yaml
64# /content/index.md
65title: Home
66
67_import:
68 posts:
69 match:
70 - 'news/**/index.md'
71 - '!news/index.md'
72 order: date
73 sort: desc
74 limit: 5
75 body: true
76 attributes:
77 - title
78 - date
79```
80
81## Data files
82Any `.yaml` files within the content directory will be converted to JSON and moved to their corresponding location in the output directory. [Imports](#import-syntax) are supported.
83
84```yaml
85# /data.yaml
86
87title: My Site
88
89# Let's import the description from the about page
90_import:
91 about:
92 match: '/about/index.md'
93 attributes:
94 - description
95```
96
97## Routes file
98A register of all routes are published to the output directory in `routes.json`.