1 | # documentative
|
2 |
|
3 | a tool for precompiling docs from markdown
|
4 |
|
5 | [![npm](https://badgen.net/npm/v/documentative?color=blue)](https://npmjs.com/package/documentative)
|
6 | [![install size](https://badgen.net/packagephobia/install/documentative?color=pink)](https://packagephobia.now.sh/result?p=documentative)
|
7 | [![downloads](https://badgen.net/npm/dt/documentative?color=green)](https://npmjs.com/package/documentative)
|
8 | [![discord](https://badgen.net/badge/icon/discord?icon=discord&label&color=purple)](https://discord.gg/g39aNQe)
|
9 | [![license](https://badgen.net/npm/license/documentative?color=b20000)](https://choosealicense.com/licenses/mit/)
|
10 |
|
11 | ## what is this? why use it?
|
12 |
|
13 | there are a lot of tools out there for publishing websites and for generating documentation.
|
14 | some are really powerful - even to the extend of processing code and building docs straight from that.
|
15 | sometimes it's just simpler to write some markdown and publish it as a static site on github pages.
|
16 |
|
17 | i was doing that a lot: and since i was writing markdown and then also manually building a matching
|
18 | website, i was spending nearly as much time on that as i was on coding the project itself. i had a
|
19 | reasonably solid template i was using already, so i did what leads many people to publishing things
|
20 | like this: i thought to myself 'how can i automate this?'
|
21 |
|
22 | documentative cuts out half the work - you write the markdown; it builds you a responsive, modern website.
|
23 |
|
24 | **demo:** [https://dragonwocky.me/documentative/](https://dragonwocky.me/documentative/)
|
25 |
|
26 | _features of a built site include..._
|
27 |
|
28 | - a responsive layout! mobile support is robust, with the sidebar transforming into
|
29 | a hamburger-triggered menu.
|
30 | - light/dark mode that respects the user's system mode (with the capability to display a different
|
31 | icon depending on the mode).
|
32 | - in-page navigation via #IDs (with a sidebar that scrolls to match the reader location), allowing
|
33 | for keeping your place on the page when you reload or linking to a specific section.
|
34 | - social-media embed friendly.
|
35 | - \+ y'know, like, being a configurably built site - you pick a primary colour, you define a footer,
|
36 | you choose which files are served or precompiled... etc.
|
37 |
|
38 | ## usage
|
39 |
|
40 | this package is available from the npm package registry.
|
41 |
|
42 | ```bash
|
43 | npm i -s documentative
|
44 | ```
|
45 |
|
46 | ```js
|
47 | const docs = require('documentative');
|
48 | ```
|
49 |
|
50 | #### to build/precompile to a directory
|
51 |
|
52 | ```js
|
53 | docs.build(inputdir, outputdir, options);
|
54 | // returns a promise: resolves to true
|
55 | ```
|
56 |
|
57 | | argument | type | value |
|
58 | | ----------- | ------ | ------------------------ |
|
59 | | `inputdir` | string | e.g. `'pages'` |
|
60 | | `outputdir` | string | e.g. `'build'` |
|
61 | | `options` | object | see [#options](#options) |
|
62 |
|
63 | if you wish your `inputdir` and `outputdir` to be the same,
|
64 | that works too - just enable the overwrite option (see [#options](#options)).
|
65 |
|
66 | ```js
|
67 | docs.build('.', '.', { overwrite: true });
|
68 | ```
|
69 |
|
70 | #### to serve the directory from a local http server
|
71 |
|
72 | ```js
|
73 | docs.serve(inputdir, port, options);
|
74 | // returns a promise: resolves to the started http server
|
75 | ```
|
76 |
|
77 | | argument | type | value |
|
78 | | ---------- | ------ | ------------------------ |
|
79 | | `inputdir` | string | e.g. `'pages'` |
|
80 | | `port` | number | e.g. `8080` |
|
81 | | `options` | object | see [#options](#options) |
|
82 |
|
83 | > ❗ not recommended unless for testing purposes
|
84 | > \- especially if serving a larger directory,
|
85 | > as it will re-read the entire directory for
|
86 | > every file serve.
|
87 |
|
88 | ## cli
|
89 |
|
90 | if this is your preferred method of use, it is recommended to install via `npm i -g documentative`.
|
91 |
|
92 | ```
|
93 | usage:
|
94 |
|
95 | > documentative-build <inputdir> <outputdir>
|
96 | e.g. documentative-build pages build
|
97 |
|
98 | > documentative-serve <inputdir> [--port, -p PORT]
|
99 | e.g. documentative-serve pages -p 3000
|
100 |
|
101 | options:
|
102 | --help, -h show this message
|
103 | --port, -p set the HTTP server port used by documentative-serve
|
104 | (default: 8080)
|
105 |
|
106 | ** to configure the process, place configuration options into
|
107 | <inputdir>/docs.json
|
108 | ```
|
109 |
|
110 | > ℹ️ the `<inputdir>/docs.json` file will be added
|
111 | > to the exclude list (see [#options](#options)).
|
112 |
|
113 | ## writing a page
|
114 |
|
115 | pages are written in github flavoured markdown.
|
116 |
|
117 | it is recommended to start every page with a `# h1`, as that is what is used
|
118 | for the sidebar table-of-contents documentative generates.
|
119 |
|
120 | in order to maintain viability of pages as both markdown and html, any local markdown page
|
121 | links are changed to match page src -> output. e.g. a link written as `[link](README.md)`
|
122 | may transformed to `<a href='index.html'>link</a>`.
|
123 |
|
124 | check out [the styling guide](styling-guide.md) for ways to further customise what comes out.
|
125 |
|
126 | ## options
|
127 |
|
128 | ```js
|
129 | {
|
130 | title: string, // default: 'documentative'
|
131 | primary: string/colour, // default: '#712c9c
|
132 | git: string/url,
|
133 | footer: string,
|
134 | // default: '© 2020 someone, under the [MIT license](https://choosealicense.com/licenses/mit/).'
|
135 | card: {
|
136 | description: string,
|
137 | url: string/url
|
138 | },
|
139 | icon: {
|
140 | light: string/filepath,
|
141 | dark: string/filepath
|
142 | },
|
143 | overwrite: boolean, // default: false
|
144 | exclude: [strings/filepaths],
|
145 | ignoredotfiles: boolean, // default: true
|
146 | nav: []
|
147 | }
|
148 | ```
|
149 |
|
150 | #### git + footer
|
151 |
|
152 | markdown can be used within the footer.
|
153 |
|
154 | the `git` property defines the url to your inputdir on github or a similar site, excluding the file itself.
|
155 | for github repos, the url must be `https://github.com/user/repo/blob/<branch>/[folder/]`.
|
156 | for gitlab, it must be `https://gitlab.com/user/repo/-/blob/<branch>/[folder/]`.
|
157 |
|
158 | e.g. your `.md` files are in a folder called `docs` @ the `master` branch of the repo `https://github.com/myname/project/`.
|
159 | you would set the `git` property to `https://github.com/myname/project/blob/master/nav`.
|
160 |
|
161 | then, if within the footer you wish to link to the hosted `.md` of the page, simply set it to:
|
162 | `"[Edit on Github](__git__)"`. the `__git__` will be replaced by the config definition + the page source.
|
163 | for the example above, when visiting `page.html`, the footer would link to `https://github.com/myname/project/blob/master/nav/page.md`.
|
164 |
|
165 | if you wish to completely hide the `footer`,
|
166 | simply set the following:
|
167 |
|
168 | ```js
|
169 | footer: '',
|
170 | ```
|
171 |
|
172 | #### card
|
173 |
|
174 | the `card` properties are used for the preview embeds/cards created by social media platforms
|
175 | when linking to your page. the `card.url` should be the canonical base url for your site and must end with a `/`.
|
176 | (e.g. `https://example.com/` or `https://dragonwocky.me/documentative/`, but NOT `https://dragonwocky.me/documentative/page.html`)
|
177 |
|
178 | #### icon
|
179 |
|
180 | the light/dark icons will be shown dependent on whether the viewer has light/dark mode enabled.
|
181 | if only 1 of the icons is set (either light or dark), that icon will be shown for both modes.
|
182 |
|
183 | #### overwrite
|
184 |
|
185 | > ❗ beware of turning on overwrite, as any files copied
|
186 | > across from the inputdir will irreversibly overwrite
|
187 | > files in the outputdir with conflicting names.
|
188 |
|
189 | #### exclude
|
190 |
|
191 | to exclude everything within a folder, end the exclude with `/*` (e.g. `ignorethisdir/*`).
|
192 |
|
193 | > ℹ️ any files within `node_modules`
|
194 | > directories will always be excluded, regardless of
|
195 | > inclusion in the above list.
|
196 |
|
197 | #### ignoredotfiles
|
198 |
|
199 | if true, will not build/serve any files or folders starting with a `.`.
|
200 |
|
201 | ### the nav: default behaviour
|
202 |
|
203 | 1. all markdown files are listed.
|
204 | 2. nav entry names are the first header within the `.md`,
|
205 | or the filename.
|
206 | 3. entries are sorted by alphabetical order,
|
207 | though the `index.md` file is always first.
|
208 | 4. if there is no `index.md` but there is a `README.md`,
|
209 | it becomes the first in the order and is output as `index.html`.
|
210 | 5. entries are categorised by directory (a title is added
|
211 | with the name of the directory).
|
212 |
|
213 | ### the nav: custom behaviour
|
214 |
|
215 | #### defining a title
|
216 |
|
217 | strict definition:
|
218 |
|
219 | ```js
|
220 | {
|
221 | type: 'title',
|
222 | text: string // e.g. 'this is a title'
|
223 | }
|
224 | ```
|
225 |
|
226 | shorthand:
|
227 |
|
228 | ```js
|
229 | string,
|
230 | // e.g. 'this is a title'
|
231 | ```
|
232 |
|
233 | #### defining a page
|
234 |
|
235 | strict definition:
|
236 |
|
237 | ```js
|
238 | {
|
239 | type: 'page',
|
240 | output: string/filepath, // e.g. 'getting-started.html'
|
241 | src: string/filepath, // e.g. 'tutorial.md'
|
242 | }
|
243 | ```
|
244 |
|
245 | shorthand:
|
246 |
|
247 | ```js
|
248 | [output, src, git],
|
249 | // e.g. ['getting-started.html', 'tutorial.md']
|
250 | ```
|
251 |
|
252 | > if the src is not a valid/existing file, it will be assumed to be a link.
|
253 |
|
254 | #### defining a link
|
255 |
|
256 | strict definition:
|
257 |
|
258 | ```js
|
259 | {
|
260 | type: 'link',
|
261 | text: string, // e.g. github
|
262 | url: string/url // e.g. https://github.com/dragonwocky/documentative/
|
263 | }
|
264 | ```
|
265 |
|
266 | shorthand:
|
267 |
|
268 | ```js
|
269 | [text, url],
|
270 | // e.g. ['github', 'https://github.com/dragonwocky/documentative/']
|
271 | ```
|
272 |
|
273 | #### example nav
|
274 |
|
275 | strict definition:
|
276 |
|
277 | ```js
|
278 | [
|
279 | { type: 'page', output: 'getting-started.html', input: 'tutorial.md' },
|
280 | { type: 'title', text: 'resources' },
|
281 | {
|
282 | type: 'link',
|
283 | text: 'github',
|
284 | url: 'https://github.com/dragonwocky/documentative/',
|
285 | },
|
286 | ];
|
287 | ```
|
288 |
|
289 | shorthand:
|
290 |
|
291 | ```js
|
292 | [
|
293 | ['getting-started.html', 'tutorial.md'],
|
294 | 'resources',
|
295 | ['github', 'https://github.com/dragonwocky/documentative/'],
|
296 | ];
|
297 | ```
|
298 |
|
299 | (these methods can be mixed.)
|
300 |
|
301 | ## output
|
302 |
|
303 | #### build
|
304 |
|
305 | 1. the output directory is created if it does not already exist.
|
306 | 2. all assets (non-`.md`) files are copied across as they are.
|
307 | 3. all markdown files included in the nav are output.
|
308 | 4. documentative resource files are copied across: `docs.js`,
|
309 | `docs.css` and (only if no icon has been specified in the
|
310 | build/serve options) `light-docs.png` and `dark-docs.png`.
|
311 |
|
312 | > ❗ note that this means you cannot have any assets with those
|
313 | > names, as they will be overriden.
|
314 |
|
315 | #### serve
|
316 |
|
317 | a http server is created. whenever a request is received:
|
318 |
|
319 | 1. if `docs.js` or `docs.css` are requested, serve them
|
320 | from documentative's resources.
|
321 | 2. if an icon has been specified and is requested, serve it.
|
322 | otherwise, the icon shall be served as `light-docs.png` or `dark-docs.png`.
|
323 | 3. if a nav entry of type page and with an output
|
324 | matching the request exists, serve it.
|
325 | 4. if the file exists in the asset list (all non-`.md` files),
|
326 | serve it.
|
327 | 5. if a file has still not been served, return a 404 error.
|
328 |
|
329 | > ❗ note that this means if you have a `.html` file called (e.g.)
|
330 | > `getting-started.html` and a `.md` file with its output set to
|
331 | > `getting-started.md`, the parsed `.md` will override the `.html` file.
|
332 |
|
333 | ## other details
|
334 |
|
335 | yes, some of the code blocks on this page end with unnecessary commas. my linter enforces it.
|
336 |
|
337 | i also have an unhealthy habit of avoiding capital letters. nothing enforces this, i just do it.
|
338 |
|
339 | the awesome logo is thanks to [@nathfreder](https://github.com/nathfreder/) :D
|
340 |
|
341 | if you have any questions, check my website for contact details.
|