|
1 | 1 | --- |
2 | | -title: Welcome to Sissi |
| 2 | +title: Configuration |
3 | 3 | layout: base.html |
4 | 4 | --- |
5 | 5 | # {{ title }} |
6 | 6 |
|
7 | | -Right now there's not too much to configure. Specify an input dir, specify an output dir: |
| 7 | +## Config file |
| 8 | + |
| 9 | +Sissi looks for a config file named `.sissi.js` or `.sissi.config.js` in the project root. The file must have a default export that is a function: |
| 10 | + |
| 11 | +```js |
| 12 | +// .sissi.config.js |
| 13 | +export default function(config) { |
| 14 | + // register plugins and filters here |
| 15 | + return { |
| 16 | + dir: { input: 'src', output: 'dist' } |
| 17 | + }; |
| 18 | +} |
| 19 | +``` |
| 20 | + |
| 21 | +The function receives a `SissiConfig` instance and may return an object with a `dir` key to override directories. |
| 22 | + |
| 23 | +## Directory options |
| 24 | + |
| 25 | +All paths are relative to the project root. These are the defaults: |
| 26 | + |
| 27 | +| Key | Default | Description | |
| 28 | +|------------|--------------|--------------------------------------------------| |
| 29 | +| `input` | `.` | Source directory | |
| 30 | +| `output` | `public` | Build output directory | |
| 31 | +| `includes` | `_includes` | Partials for `<html-include src="..."/>` | |
| 32 | +| `layouts` | `_layouts` | Layout templates (referenced via frontmatter) | |
| 33 | +| `data` | `_data` | Global data files (`.js`, `.json`, `.yaml`) | |
8 | 34 |
|
9 | 35 | ```js |
10 | 36 | export default function(config) { |
11 | | - // You can add plugins via config.addPlugin here |
12 | | - // config.addPlugin(html); |
13 | 37 | return { |
14 | 38 | dir: { |
15 | | - input: 'demo', |
16 | | - output: 'dist' |
| 39 | + input: 'src', |
| 40 | + output: 'dist', |
| 41 | + includes: 'src/_includes', |
| 42 | + layouts: 'src/_layouts', |
| 43 | + data: 'src/_data', |
17 | 44 | } |
18 | | - } |
| 45 | + }; |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +## Output naming |
| 50 | + |
| 51 | +By default Sissi preserves the input path and swaps the file extension (`defaultNaming`). You can switch to directory-based URLs with `directoryNaming`, which turns `about.html` into `about/index.html`: |
| 52 | + |
| 53 | +```js |
| 54 | +import { directoryNaming } from 'sissi/naming'; |
| 55 | + |
| 56 | +export default function(config) { |
| 57 | + config.naming = directoryNaming; |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +## config API |
| 62 | + |
| 63 | +### `config.addPlugin(fn)` |
| 64 | + |
| 65 | +Registers a plugin. Plugins follow the same signature as the config function — they receive the `SissiConfig` instance and may return a `dir` override. |
| 66 | + |
| 67 | +```js |
| 68 | +import myPlugin from './my-plugin.js'; |
| 69 | + |
| 70 | +export default function(config) { |
| 71 | + config.addPlugin(myPlugin); |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +### `config.addFilter(name, fn)` |
| 76 | + |
| 77 | +Registers a template filter. Filters are called via the pipe syntax in templates. |
| 78 | + |
| 79 | +```js |
| 80 | +config.addFilter('shout', (str) => str.toUpperCase()); |
| 81 | +config.addFilter('prefix', (str, pre) => `${pre}${str}`); |
| 82 | +``` |
| 83 | + |
| 84 | +```html |
| 85 | +{\{ title | shout }\} |
| 86 | +{\{ title | prefix: 'Hello, ' }\} |
| 87 | +``` |
| 88 | + |
| 89 | +### `config.addExtension(ext, processingFunction)` |
| 90 | + |
| 91 | +Registers a compiler for a file extension. Also implicitly adds the extension to the set of template formats so those files are compiled rather than passthrough-copied. |
| 92 | + |
| 93 | +### `config.addCollection(name, fn)` |
| 94 | + |
| 95 | +Registers a named collection. The callback receives a `CollectionsAPI` and must return an array. See the [Collections](/collections) page for details. |
| 96 | + |
| 97 | +```js |
| 98 | +config.addCollection('recentPosts', (api) => |
| 99 | + api.getFilteredByTag('post').slice(0, 5) |
| 100 | +); |
| 101 | +``` |
| 102 | + |
| 103 | +### `config.addTemplateFormats(formats)` |
| 104 | + |
| 105 | +Marks additional file extensions as template formats. Accepts a comma-separated string or an array. |
| 106 | + |
| 107 | +```js |
| 108 | +config.addTemplateFormats('njk,liquid'); |
| 109 | +config.addTemplateFormats(['njk', 'liquid']); |
| 110 | +``` |
| 111 | + |
| 112 | +### `config.setTemplateFormats(formats)` |
| 113 | + |
| 114 | +Replaces the full set of template formats. Same argument shape as `addTemplateFormats`. |
| 115 | + |
| 116 | +### `config.addPassthroughCopy(paths)` |
| 117 | + |
| 118 | +No-op for Eleventy compatibility. In Sissi, every file whose extension is not in `templateFormats` is passthrough-copied automatically — you never need to opt in explicitly. |
| 119 | + |
| 120 | +## Writing a plugin |
| 121 | + |
| 122 | +A plugin is just a function with the same shape as the config function — it receives the `SissiConfig` instance, calls any config methods it needs, and optionally returns a `dir` override. |
| 123 | + |
| 124 | +### Adding a new template format |
| 125 | + |
| 126 | +The most common use case is registering a compiler for a new file extension via `config.addExtension`. The compiler object must have: |
| 127 | + |
| 128 | +- **`outputFileExtension`** — the extension of the output file (e.g. `'html'`) |
| 129 | +- **`compile(inputContent, inputPath)`** — an async function that receives the raw file content and path, and returns another async function that receives the template data and returns the final string |
| 130 | + |
| 131 | +```js |
| 132 | +// my-plugin.js |
| 133 | +export default function myPlugin(config) { |
| 134 | + config.addExtension('txt', { |
| 135 | + outputFileExtension: 'html', |
| 136 | + compile: async (inputContent, inputPath) => { |
| 137 | + return async (data) => { |
| 138 | + // transform inputContent into HTML here |
| 139 | + return `<pre>${inputContent}</pre>`; |
| 140 | + }; |
| 141 | + }, |
| 142 | + }); |
| 143 | +} |
| 144 | +``` |
| 145 | + |
| 146 | +### Adding filters inside a plugin |
| 147 | + |
| 148 | +Plugins can also bundle filters so related functionality ships together: |
| 149 | + |
| 150 | +```js |
| 151 | +// my-plugin.js |
| 152 | +export default function myPlugin(config) { |
| 153 | + config.addFilter('shout', (str) => str.toUpperCase()); |
| 154 | + |
| 155 | + config.addExtension('txt', { |
| 156 | + outputFileExtension: 'html', |
| 157 | + compile: async (inputContent) => async () => `<pre>${inputContent}</pre>`, |
| 158 | + }); |
19 | 159 | } |
20 | 160 | ``` |
| 161 | + |
| 162 | +### Using the plugin |
| 163 | + |
| 164 | +```js |
| 165 | +// .sissi.config.js |
| 166 | +import myPlugin from './my-plugin.js'; |
| 167 | + |
| 168 | +export default function(config) { |
| 169 | + config.addPlugin(myPlugin); |
| 170 | +} |
| 171 | +``` |
| 172 | + |
| 173 | +## CLI flags |
| 174 | + |
| 175 | +| Command | Description | |
| 176 | +|------------------|-------------------------------------------------------| |
| 177 | +| `sissi build` | One-time build to the output directory | |
| 178 | +| `sissi watch` | Watch mode — rebuilds on file changes | |
| 179 | +| `sissi dev` | Dev server with watch mode and hot reload | |
| 180 | +| `--dry` | Skip writing files (useful for debugging the build) | |
0 commit comments