docula 1.2.0 → 1.6.0

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 CHANGED
@@ -8,39 +8,46 @@
8
8
  [![npm](https://img.shields.io/npm/dm/docula)](https://npmjs.com/package/docula)
9
9
  [![npm](https://img.shields.io/npm/v/docula)](https://npmjs.com/package/docula)
10
10
 
11
- # Table of Contents
12
- - [Features](#features)
13
- - [Open Source Examples](#open-source-examples)
14
- - [Getting Started](#getting-started)
15
- - [Serve your site locally](#serve-your-site-locally)
16
- - [TypeScript Configuration](#typescript-configuration)
17
- - [Theme Mode](#theme-mode)
18
- - [Using Your own Template](#using-your-own-template)
19
- - [Building Multiple Pages](#building-multiple-pages)
20
- - [Including Assets in Markdown](#including-assets-in-markdown)
21
- - [Public Folder](#public-folder)
22
- - [API Reference](#api-reference)
23
- - [LLM Files](#llm-files)
24
- - [Announcements](#announcements)
25
- - [Changelog](#changelog)
26
- - [Alert, Info, Warn Styling](#alert-info-warn-styling)
27
- - [Using a Github Token](#using-a-github-token)
28
- - [Helpers](#helpers)
29
- - [Working with Markdown using Writr](#working-with-markdown-using-writr)
30
- - [Code of Conduct and Contributing](#code-of-conduct-and-contributing)
31
- - [License - MIT](#license)
32
-
33
11
  # Features
34
12
  * No configuration required. Just setup the folder structure with a logo, favicon, and css file.
35
13
  * Builds a static website that can be hosted anywhere.
36
- * For more complex projects easily add a `docula.config.ts` (TypeScript) or `docula.config.mjs` (JavaScript) file to customize the build process with lifecycle hooks.
37
- * Full TypeScript support with typed configuration and IDE autocompletion.
14
+ * Simple search is provided by default out of the box.
38
15
  * Support for single page with readme or multiple markdown pages in a docs folder.
16
+ * Full TypeScript support with typed configuration and IDE autocompletion.
17
+ * For more complex projects easily add a `docula.config.ts` (TypeScript) or `docula.config.mjs` (JavaScript) file to customize the build process with lifecycle hooks and `DoculaConsole` logging.
39
18
  * Will generate a sitemap.xml, robots.txt, and `feed.xml` for your site.
40
19
  * Automatically generates `llms.txt` and `llms-full.txt` for LLM-friendly indexing of docs, API reference, and changelog content.
41
- * Uses Github release notes to generate a changelog / releases page.
20
+ * OpenAPI / Swagger support for auto-generating an interactive API reference page.
21
+ * Uses Github release notes and file-based changelog entries to generate a changelog with individual pages, pagination, and preview text.
42
22
  * Uses Github to show contributors and link to their profiles.
43
- * Simple search is provided by default out of the box.
23
+ * Light, dark, and system theme modes with a built-in toggle.
24
+ * Easy styling customization via `variables.css` with no template editing required.
25
+ * Watch mode with auto-rebuild for local development.
26
+
27
+ # Table of Contents
28
+ - [Getting Started](https://docula.org/docs/index)
29
+ - [Configuration](https://docula.org/docs/configuration)
30
+ - [CLI](https://docula.org/docs/cli)
31
+ - [Templates](https://docula.org/docs/templates)
32
+ - [Partial Templates](https://docula.org/docs/partial-templates)
33
+ - [Multiple Pages](https://docula.org/docs/multiple-pages)
34
+ - [Assets](https://docula.org/docs/assets)
35
+ - [Styling](https://docula.org/docs/styling)
36
+ - [Custom Scripts](https://docula.org/docs/custom-scripts)
37
+ - [API Reference](https://docula.org/docs/api-reference)
38
+ - [LLM Files](https://docula.org/docs/llm-files)
39
+ - [Announcements](https://docula.org/docs/using-announcements)
40
+ - [Changelog](https://docula.org/docs/changelog)
41
+ - [GitHub Integration](https://docula.org/docs/github-integration)
42
+ - [GitHub Token](https://docula.org/docs/github-token)
43
+ - [Helper Utilities](https://docula.org/docs/helper-utilities)
44
+ - [Header Links](https://docula.org/docs/header-links)
45
+ - [Caching](https://docula.org/docs/caching)
46
+ - [Cookie Auth](https://docula.org/docs/cookie-auth)
47
+ - [Robots & Sitemap](https://docula.org/docs/robots-and-sitemap)
48
+ - [Open Source Examples](#open-source-examples)
49
+ - [Code of Conduct and Contributing](#code-of-conduct-and-contributing)
50
+ - [License - MIT](#license)
44
51
 
45
52
  # Open Source Examples
46
53
 
@@ -50,698 +57,8 @@ See Docula in action with these open source projects that use it for their docum
50
57
  * **[Keyv.org](https://keyv.org)** - Simple key-value storage with support for multiple backends ([Source](https://github.com/jaredwray/keyv))
51
58
  * **[Docula.org](https://docula.org)** - Docula's own documentation site, built with Docula ([Source](https://github.com/jaredwray/docula))
52
59
 
53
- These examples showcase different approaches to using Docula, from simple single-page sites to more complex documentation with multiple pages and custom configurations.
54
-
55
- # Getting Started
56
-
57
- ## Install docula via init
58
- > npx docula init
59
-
60
- This will create a folder called site with the following structure:
61
-
62
- ```
63
- site
64
- ├───site.css
65
- ├───logo.png
66
- ├───favicon.ico
67
- ├───README.md
68
- ├───docula.config.mjs
69
- ```
70
- Note: for typescript do 'docula init --typescript'
71
-
72
- ## Add your content
73
-
74
- Simply replace the logo, favicon, and css file with your own. The readme is your root project readme and you just need to at build time move it over to the site folder. If you have it at the root of the project and this is a folder inside just delete the README.md file in the site folder and docula will copy it over for you automatically.
75
-
76
- ## Build your site
77
-
78
- > npx docula
79
-
80
- This will build your site and place it in the `dist` folder. You can then host it anywhere you like.
81
-
82
- ## Serve your site locally
83
-
84
- > npx docula serve
85
-
86
- This will build and serve your site locally at `http://localhost:3000`. You can specify a custom port with the `-p` or `--port` flag:
87
-
88
- > npx docula serve -p 8080
89
-
90
- ### CLI Options for serve
91
-
92
- | Flag | Description | Default |
93
- |------|-------------|---------|
94
- | `-p, --port` | Set the port number | `3000` |
95
- | `-s, --site` | Set the path where site files are located | `./site` |
96
- | `-o, --output` | Set the output directory | `./site/dist` |
97
- | `-w, --watch` | Watch for changes and rebuild | `false` |
98
- | `-c, --clean` | Clean the output directory before building | `false` |
99
-
100
- ### Watch Mode
101
-
102
- Use the `--watch` flag to automatically rebuild your site when files change:
103
-
104
- > npx docula serve --watch
105
-
106
- When watch mode is enabled:
107
- 1. An initial build runs at startup
108
- 2. The dev server starts and serves your site
109
- 3. File changes in `sitePath` (e.g., `./site`) are detected and trigger an automatic rebuild
110
- 4. Changes in the output directory are ignored to prevent rebuild loops
111
-
112
- This is useful during development when you want to see changes reflected immediately without manually re-running the build.
113
-
114
- # TypeScript Configuration
115
-
116
- Docula supports TypeScript configuration files (`docula.config.ts`) in addition to JavaScript (`docula.config.mjs`). TypeScript configs provide type safety and better IDE support.
117
-
118
- ## Initializing with TypeScript
119
-
120
- To create a new project with a TypeScript config file:
121
-
122
- ```bash
123
- npx docula init --typescript
124
- ```
125
-
126
- This creates a `docula.config.ts` file with full type support:
127
-
128
- ```typescript
129
- import type { DoculaOptions } from 'docula';
130
-
131
- export const options: Partial<DoculaOptions> = {
132
- templatePath: './template',
133
- output: './dist',
134
- sitePath: './site',
135
- githubPath: 'your-username/your-repo',
136
- siteTitle: 'My Project',
137
- siteDescription: 'Project description',
138
- siteUrl: 'https://your-site.com',
139
- };
140
- ```
141
-
142
- ## Using Lifecycle Hooks with TypeScript
143
-
144
- You can add typed lifecycle hooks to your config:
145
-
146
- ```typescript
147
- import type { DoculaOptions } from 'docula';
148
-
149
- export const options: Partial<DoculaOptions> = {
150
- siteTitle: 'My Project',
151
- // ... other options
152
- };
153
-
154
- export const onPrepare = async (config: DoculaOptions): Promise<void> => {
155
- // Runs before the build process
156
- console.log(`Building ${config.siteTitle}...`);
157
- };
158
- ```
159
-
160
- ## Config File Priority
161
-
162
- When both config files exist, Docula loads them in this order (first found wins):
163
- 1. `docula.config.ts` (TypeScript - takes priority)
164
- 2. `docula.config.mjs` (JavaScript)
165
-
166
- ## Available Options
167
-
168
- | Option | Type | Default | Description |
169
- |--------|------|---------|-------------|
170
- | `templatePath` | `string` | `'./template'` | Path to custom template directory |
171
- | `output` | `string` | `'./dist'` | Output directory for built site |
172
- | `sitePath` | `string` | `'./site'` | Directory containing site content |
173
- | `githubPath` | `string` | - | GitHub repository path (e.g., `'user/repo'`) |
174
- | `siteTitle` | `string` | `'docula'` | Website title |
175
- | `siteDescription` | `string` | - | Website description |
176
- | `siteUrl` | `string` | - | Website URL |
177
- | `port` | `number` | `3000` | Port for local development server |
178
- | `homePage` | `boolean` | `true` | When `false`, Docula uses the first docs page as `/index.html` instead of rendering `home.hbs` |
179
- | `sections` | `DoculaSection[]` | - | Documentation sections |
180
- | `openApiUrl` | `string` | - | OpenAPI spec URL for API documentation (auto-detected if `api/swagger.json` exists) |
181
- | `enableReleaseChangelog` | `boolean` | `true` | Convert GitHub releases to changelog entries |
182
- | `enableLlmsTxt` | `boolean` | `true` | Generate `llms.txt` and `llms-full.txt` in the build output |
183
- | `themeMode` | `'light'` \| `'dark'` | - | Override the default theme. By default the site follows the system preference. Set to `'light'` or `'dark'` to use that theme when no user preference is stored. |
184
- | `allowedAssets` | `string[]` | *(see [Including Assets in Markdown](#including-images-and-assets-in-markdown))* | File extensions to copy from `docs/` and `changelog/` to output |
185
-
186
- ## Theme Mode
187
-
188
- By default, the site follows the user's system color scheme preference. The theme toggle cycles through three modes: **system** (follows OS preference), **light**, and **dark**. The user's choice is persisted in `localStorage`.
189
-
190
- To set the initial theme mode, use `themeMode`:
191
-
192
- ```js
193
- export const options = {
194
- themeMode: 'dark',
195
- };
196
- ```
197
-
198
- When `themeMode` is set, new visitors see the specified theme instead of the system preference. Once a user clicks the theme toggle, their choice takes priority and is remembered across visits.
199
-
200
- # Using Your own Template
201
-
202
- If you want to use your own template you can do so by adding a `docula.config.ts` file to the root of your project. This file will be used to configure the build process.
203
-
204
- or at the command line:
205
-
206
- > npx docula --template path/to/template
207
-
208
- # Building Multiple Pages
209
-
210
- If you want to build multiple pages you can easily do that by adding in a `docs` folder to the root of the site folder. Inside of that folder you can add as many pages as you like. Each page will be a markdown file and it will generate a table of contents for you. Here is an example of what it looks like:
211
-
212
- ```
213
- site
214
- ├───site.css
215
- ├───logo.png
216
- ├───favicon.ico
217
- ├───docula.config.mjs
218
- ├───docs
219
- │ ├───getting-started.md
220
- │ ├───contributing.md
221
- │ ├───license.md
222
- │ ├───code-of-conduct.md
223
- ```
224
-
225
- The `readme.md` file will be the root page and the rest will be added to the table of contents. If you want to control the title or order of the pages you can do so by setting the `title` and `order` properties in the front matter of the markdown file. Here is an example:
226
-
227
- ```md
228
- title: Getting Started
229
- order: 2
230
- ```
231
-
232
- If you want your docs to be the root home page (`/`) instead of rendering the template home page, set `homePage: false`:
233
-
234
- ```js
235
- export const options = {
236
- homePage: false,
237
- };
238
- ```
239
-
240
- # Including Assets in Markdown
241
-
242
- Non-markdown files placed inside the `docs/` or `changelog/` directories are automatically copied to the build output, preserving their relative paths. This lets you keep images and other assets alongside the markdown that references them.
243
-
244
- For `docs/`, only assets that are actually referenced in a document's markdown content are copied. If a file exists in the `docs/` directory but is not referenced by any document, it will not be included in the build output. For `changelog/`, all assets are copied regardless of whether they are referenced.
245
-
246
- ```
247
- site
248
- ├───docs
249
- │ ├───getting-started.md
250
- │ ├───images
251
- │ │ ├───architecture.png
252
- │ │ └───screenshot.jpg
253
- │ └───assets
254
- │ └───example.pdf
255
- ├───changelog
256
- │ ├───2025-01-15-initial-release.md
257
- │ └───images
258
- │ └───release-banner.png
259
- ```
260
-
261
- After building, these files appear at the same relative paths under `dist/`:
262
-
263
- ```
264
- dist
265
- ├───docs
266
- │ ├───getting-started
267
- │ │ └───index.html
268
- │ ├───images
269
- │ │ ├───architecture.png
270
- │ │ └───screenshot.jpg
271
- │ └───assets
272
- │ └───example.pdf
273
- ├───changelog
274
- │ ├───initial-release
275
- │ │ └───index.html
276
- │ └───images
277
- │ └───release-banner.png
278
- ```
279
-
280
- Reference assets from your markdown using relative paths:
281
-
282
- ```md
283
- ![Architecture](images/architecture.png)
284
- [Download PDF](assets/example.pdf)
285
- ```
286
-
287
- ## Supported Extensions
288
-
289
- By default the following file extensions are copied:
290
-
291
- **Images:** `.png`, `.jpg`, `.jpeg`, `.gif`, `.svg`, `.webp`, `.avif`, `.ico`
292
- **Documents:** `.pdf`, `.zip`, `.tar`, `.gz`
293
- **Media:** `.mp4`, `.webm`, `.ogg`, `.mp3`, `.wav`
294
- **Data:** `.json`, `.xml`, `.csv`, `.txt`
295
-
296
- Files with extensions not in this list are ignored. To customize the list, set `allowedAssets` in your config:
297
-
298
- ```js
299
- export const options = {
300
- allowedAssets: ['.png', '.jpg', '.gif', '.svg', '.pdf', '.custom'],
301
- };
302
- ```
303
-
304
- # Public Folder
305
-
306
- If you have static assets like images, fonts, or other files that need to be copied directly to your built site, you can use a `public` folder. Any files placed in the `public` folder within your site directory will be automatically copied to the root of your `dist` output folder during the build process.
307
-
308
- ## Usage
309
-
310
- Create a `public` folder inside your site directory:
311
-
312
- ```
313
- site
314
- ├───public
315
- │ ├───images
316
- │ │ ├───screenshot.png
317
- │ │ └───banner.jpg
318
- │ ├───fonts
319
- │ │ └───custom-font.woff2
320
- │ └───downloads
321
- │ └───example.pdf
322
- ├───docs
323
- ├───logo.svg
324
- ├───favicon.ico
325
- └───docula.config.mjs
326
- ```
327
-
328
- When you run the build command, all contents of the `public` folder will be copied to the `dist` folder:
329
-
330
- ```
331
- dist
332
- ├───images
333
- │ ├───screenshot.png
334
- │ └───banner.jpg
335
- ├───fonts
336
- │ └───custom-font.woff2
337
- ├───downloads
338
- │ └───example.pdf
339
- ├───index.html
340
- └───...
341
- ```
342
-
343
- The build output will show each file being copied:
344
-
345
- ```
346
- Public folder found, copying contents to dist...
347
- Copied: images/screenshot.png
348
- Copied: images/banner.jpg
349
- Copied: fonts/custom-font.woff2
350
- Copied: downloads/example.pdf
351
- Build completed in 1234ms
352
- ```
353
-
354
- This is useful for:
355
- - Images referenced in your documentation
356
- - Downloadable files (PDFs, zip archives, etc.)
357
- - Custom fonts
358
- - Any other static assets that need to be served from your site
359
-
360
- # API Reference
361
-
362
- Docula can generate an API Reference page from an OpenAPI (Swagger) specification. The spec is parsed at build time and rendered as a native, interactive API reference (inspired by [Scalar](https://github.com/scalar/scalar)) with grouped endpoints, method badges, schema tables, code examples, and search — all with no external dependencies. The page is available at `/api`.
363
-
364
- ## Auto-Detection
365
-
366
- If your site directory contains an `api/swagger.json` file, Docula will automatically detect it and generate the API Reference page — no configuration needed:
367
-
368
- ```
369
- site
370
- ├───api
371
- │ └───swagger.json
372
- ├───docs
373
- ├───logo.svg
374
- ├───favicon.ico
375
- └───docula.config.mjs
376
- ```
377
-
378
- ## Explicit Configuration
379
-
380
- You can also set the `openApiUrl` option in your config to point to any OpenAPI spec, either a local path or a remote URL:
381
-
382
- ```js
383
- export const options = {
384
- openApiUrl: '/api/swagger.json',
385
- // or a remote URL:
386
- // openApiUrl: 'https://petstore.swagger.io/v2/swagger.json',
387
- };
388
- ```
389
-
390
- When `openApiUrl` is set explicitly, it takes priority over auto-detection.
391
-
392
- ## Spec Requirements
393
-
394
- The file must be a valid OpenAPI 3.x or Swagger 2.0 JSON specification. A minimal example:
395
-
396
- ```json
397
- {
398
- "openapi": "3.0.0",
399
- "info": {
400
- "title": "My API",
401
- "version": "1.0.0"
402
- },
403
- "paths": {}
404
- }
405
- ```
406
-
407
- # LLM Files
408
-
409
- Docula generates two LLM-focused files in the output directory by default:
410
-
411
- - `/llms.txt` - a compact index of your docs, API reference, and changelog URLs.
412
- - `/llms-full.txt` - expanded content including markdown bodies for docs/changelog and local OpenAPI spec text.
413
-
414
- ## What Gets Included
415
-
416
- `/llms.txt` includes:
417
- - Site title and description
418
- - A link to `/llms-full.txt`
419
- - Documentation links (absolute URLs)
420
- - API Reference link when API docs are generated
421
- - Changelog landing page and the latest 20 changelog entries
422
-
423
- `/llms-full.txt` includes:
424
- - Site title and description
425
- - Full markdown body for each docs page
426
- - Full markdown body for each changelog entry
427
- - Full local OpenAPI spec text when available (for example `site/api/swagger.json`)
428
-
429
- If `openApiUrl` points to a remote URL, `/llms-full.txt` includes only the URL reference instead of fetching content over the network.
430
-
431
- ## Configuration
432
-
433
- To disable generation:
434
-
435
- ```js
436
- export const options = {
437
- enableLlmsTxt: false,
438
- };
439
- ```
440
-
441
- ## Custom Overrides
442
-
443
- You can override generated output by providing custom files in your site directory:
444
-
445
- - `site/llms.txt`
446
- - `site/llms-full.txt`
447
-
448
- If present, Docula copies these files to output as-is.
449
-
450
- ## Notes
451
-
452
- - These files are generated in the output root (`dist/llms.txt` and `dist/llms-full.txt`).
453
- - They are not added to `sitemap.xml`.
454
-
455
- # Announcements
456
-
457
- You can display an announcement banner on your home page by creating an `announcement.md` file in your site directory. This is useful for highlighting important updates, new releases, or any time-sensitive information.
458
-
459
- ## Usage
460
-
461
- Create an `announcement.md` file in your site folder:
462
-
463
- ```
464
- site
465
- ├───announcement.md
466
- ├───docs
467
- ├───logo.svg
468
- ├───favicon.ico
469
- └───docula.config.mjs
470
- ```
471
-
472
- Add your announcement content using markdown:
473
-
474
- ```md
475
- **New Release:** Version 2.0 is now available! Check out the [release notes](/releases) for details.
476
- ```
477
-
478
- The announcement will automatically appear on the home page above the "Documentation" button, styled as an alert box with a colored left border.
479
-
480
- ## Styling
481
-
482
- The announcement uses your theme's CSS variables and displays with:
483
- - A subtle background using `--sidebar-background`
484
- - A prominent left border using `--color-secondary`
485
- - Links styled with `--color-primary`
486
-
487
- You can customize the appearance by overriding the `.announcement` class in your `variables.css`:
488
-
489
- ```css
490
- .announcement {
491
- background-color: #fff3cd;
492
- border-left-color: #ffc107;
493
- }
494
- ```
495
-
496
- ## Removing the Announcement
497
-
498
- Simply delete the `announcement.md` file when you no longer need the announcement. The home page will automatically return to its normal layout.
499
-
500
- # Changelog
501
-
502
- Docula can generate a changelog section for your site from markdown files. This is useful for documenting release notes, updates, and changes to your project in a structured, browsable format.
503
-
504
- ## Setup
505
-
506
- Create a `changelog` folder inside your site directory and add markdown (`.md` or `.mdx`) files for each entry:
507
-
508
- ```
509
- site
510
- ├───changelog
511
- │ ├───2025-01-15-initial-release.md
512
- │ ├───2025-02-01-new-features.md
513
- │ └───2025-03-10-bug-fixes.md
514
- ├───logo.svg
515
- ├───favicon.ico
516
- └───docula.config.mjs
517
- ```
518
-
519
- ## Entry Format
520
-
521
- Each changelog entry is a markdown file with front matter:
522
-
523
- ```md
524
- ---
525
- title: "Initial Release"
526
- date: 2025-01-15
527
- tag: "Release"
528
- ---
529
-
530
- We're excited to announce the initial release! Here's what's included:
531
-
532
- - Feature A
533
- - Feature B
534
- - Bug fix C
535
- ```
536
-
537
- ### Front Matter Fields
538
-
539
- | Field | Required | Description |
540
- |-------|----------|-------------|
541
- | `title` | No | Display title for the entry. Defaults to the filename if not provided. |
542
- | `date` | Yes | Date of the entry (`YYYY-MM-DD`). Used for sorting (newest first). |
543
- | `tag` | No | A label displayed as a badge (e.g., `Release`, `Bug Fix`, `Feature`). Gets a CSS class based on its value for styling. |
544
-
545
- ## File Naming
546
-
547
- Files can optionally be prefixed with a date in `YYYY-MM-DD-` format. The date prefix is stripped to create the URL slug:
548
-
549
- - `2025-01-15-initial-release.md` → `/changelog/initial-release/`
550
- - `new-features.md` → `/changelog/new-features/`
551
-
552
- ## Generated Pages
553
-
554
- When changelog entries are found, Docula generates:
555
-
556
- - **Changelog listing page** at `/changelog/` — shows all entries sorted by date (newest first) with titles, dates, tags, and content
557
- - **Individual entry pages** at `/changelog/{slug}/` — a dedicated page for each entry with a back link to the listing
558
-
559
- Changelog URLs are also automatically added to the generated `sitemap.xml`.
560
-
561
- ## RSS Feed
562
-
563
- Docula automatically generates a docs-only RSS 2.0 feed at `/feed.xml` when your site has documentation pages.
564
-
565
- - The feed includes one item per generated doc page.
566
- - Each item uses the document title and canonical page URL.
567
- - Item descriptions prefer front matter descriptions and otherwise fall back to a short excerpt from the markdown body.
568
- - `/feed.xml` is added to `sitemap.xml` for discovery.
569
-
570
- ## Styling
571
-
572
- Tags receive a CSS class based on their value (e.g., a tag of `"Bug Fix"` gets the class `changelog-tag-bug-fix`). You can style tags and other changelog elements by overriding these classes in your `variables.css`:
573
-
574
- ```css
575
- .changelog-entry {
576
- border-bottom: 1px solid var(--border);
577
- padding: 1.5rem 0;
578
- }
579
-
580
- .changelog-tag {
581
- font-size: 0.75rem;
582
- padding: 0.2rem 0.5rem;
583
- border-radius: 4px;
584
- }
585
-
586
- .changelog-tag-release {
587
- background-color: #d4edda;
588
- color: #155724;
589
- }
590
-
591
- .changelog-tag-bug-fix {
592
- background-color: #f8d7da;
593
- color: #721c24;
594
- }
595
- ```
596
-
597
- # Alert, Info, Warn Styling
598
-
599
- Docula uses Writr's GitHub-flavored Markdown plugins, including GitHub-style blockquote alerts. Use the alert syntax directly in Markdown:
600
-
601
- ```md
602
- > [!NOTE]
603
- > Info: Remember to configure your GitHub token for private repos.
604
-
605
- > [!WARNING]
606
- > Warn: This action cannot be undone.
607
-
608
- > [!CAUTION]
609
- > Alert: Rotate your secrets immediately.
610
- ```
611
-
612
- These render with the `remark-github-blockquote-alert` classes (like `.markdown-alert` and `.markdown-alert-note`). If you want GitHub-like styling, copy the plugin's CSS into your `site/variables.css` or template stylesheet (for example, from `remark-github-blockquote-alert/alert.css`), or add your own overrides:
613
-
614
- ```css
615
- .markdown-alert {
616
- border-left: 4px solid var(--border);
617
- border-radius: 8px;
618
- margin: 1rem 0;
619
- padding: 0.75rem 1rem;
620
- background: var(--background);
621
- }
622
-
623
- .markdown-alert-note {
624
- border-left-color: #4c8ef7;
625
- }
626
-
627
- .markdown-alert-warning {
628
- border-left-color: #f2b90c;
629
- }
630
-
631
- .markdown-alert-caution {
632
- border-left-color: #e5534b;
633
- }
634
- ```
635
-
636
- # Using a Github Token
637
-
638
- If you want to use the Github token to access the Github API you can do so by setting the `GITHUB_TOKEN` environment variable. This is useful if you want to access private repositories or if you want to access the Github API without hitting the rate limit. This is optional and you can still use docula without it but could hit rate limits and will not be able to access private repositories.
639
-
640
- # Helpers
641
-
642
- Docula provides powerful helper utilities through its integration with [Writr](https://writr.org). For all markdown operations including reading files, manipulating content, managing frontmatter, and rendering, you should use the `Writr` class that's exported from Docula.
643
-
644
- **Instead of custom helper functions, use Writr for:**
645
- - Loading and saving markdown files
646
- - Getting and setting frontmatter (metadata)
647
- - Rendering markdown to HTML
648
- - Working with markdown content programmatically
649
-
650
- See the [Working with Markdown using Writr](#working-with-markdown-using-writr) section below for comprehensive examples and usage patterns.
651
-
652
- # Working with Markdown using Writr
653
-
654
- Docula exports [Writr](https://writr.org) for powerful markdown operations including loading files, rendering, and managing frontmatter. Writr provides a simple API for working with markdown content.
655
-
656
- ## Creating and Loading Markdown
657
-
658
- ```js
659
- import { Writr } from 'docula';
660
-
661
- // Create a new instance with markdown content
662
- const writr = new Writr('# Hello World\n\nThis is my content');
663
-
664
- // Or load from a file
665
- const writr = new Writr();
666
- await writr.loadFromFile('./README.md');
667
-
668
- // Synchronous version
669
- writr.loadFromFileSync('./README.md');
670
- ```
671
-
672
- ## Getting and Setting Front Matter
673
-
674
- Front matter is metadata at the top of markdown files in YAML format. Writr makes it easy to read and modify:
675
-
676
- ```js
677
- import { Writr } from 'docula';
678
-
679
- const writr = new Writr();
680
- await writr.loadFromFile('./docs/guide.md');
681
-
682
- // Get the entire front matter object
683
- const frontMatter = writr.frontMatter;
684
- console.log(frontMatter.title); // 'My Guide'
685
-
686
- // Get a specific front matter value
687
- const title = writr.getFrontMatterValue('title');
688
- const order = writr.getFrontMatterValue('order');
689
-
690
- // Set front matter
691
- writr.frontMatter = {
692
- title: 'Updated Guide',
693
- order: 1,
694
- author: 'John Doe'
695
- };
696
-
697
- // Save the changes back to the file
698
- await writr.saveToFile('./docs/guide.md');
699
- ```
700
-
701
- ## Accessing Markdown Content
702
-
703
- ```js
704
- // Get the full content (front matter + markdown)
705
- const fullContent = writr.content;
706
-
707
- // Get just the markdown body (without front matter)
708
- const markdown = writr.body;
709
- // or use the alias
710
- const markdown = writr.markdown;
711
-
712
- // Get the raw front matter string (including delimiters)
713
- const rawFrontMatter = writr.frontMatterRaw;
714
-
715
- // Set new content
716
- writr.content = '---\ntitle: New Title\n---\n# New Content';
717
- ```
718
-
719
- ## Rendering Markdown to HTML
720
-
721
- ```js
722
- // Render to HTML
723
- const html = await writr.render();
724
-
725
- // Synchronous rendering
726
- const html = writr.renderSync();
727
-
728
- // Render with options
729
- const html = await writr.render({
730
- emoji: true, // Enable emoji support (default: true)
731
- toc: true, // Generate table of contents (default: true)
732
- highlight: true, // Code syntax highlighting (default: true)
733
- gfm: true, // GitHub Flavored Markdown (default: true)
734
- math: true, // Math support (default: true)
735
- mdx: true // MDX support (default: true)
736
- });
737
-
738
- // Render directly to a file
739
- await writr.renderToFile('./output.html');
740
- ```
741
-
742
60
  # Code of Conduct and Contributing
743
61
  [Code of Conduct](CODE_OF_CONDUCT.md) and [Contributing](CONTRIBUTING.md) guidelines.
744
62
 
745
63
  # License
746
-
747
64
  MIT © [Jared Wray](https://jaredwray.com)