···11+# Sitebase publication exporting
22+33+One of the primary features of sitebase is being able to export your `standard.site` publication to static files that can be deployed through the method of your choice.
44+55+## Export config
66+77+Export configuration can be specified via command line options, or via a config file.
88+99+### Config files
1010+1111+A config file can be specified with the `--config` flag. If a `.sitebase.config.{js|ts}` file is in the current directory, this will be autodetected and used.
1212+1313+**Note**: Options provided via the command line will override those set in a config file.
1414+1515+### Options
1616+1717+#### `filename`
1818+1919+A handlebars template string representing the filename.
2020+2121+Receives both publication (`pub`) and document (`doc`) data.
2222+2323+(TODO: what helpers are available? need some for date string processing at least. what does handlebars come with? [register some default helpers?](https://handlebarsjs.com/guide/expressions.html#helpers))
2424+2525+Default: `
2626+2727+#### `filenameFn` (config file only)
2828+2929+A function receiving the publication and document data, returning a string that will become the exported document filename.
3030+3131+```
3232+({ pub: Publication, doc: Document }) => string | Promise<string>
3333+```
3434+3535+#### `contentTypes`
3636+3737+A list of `doc.content.$type` values that will be included in the export.
3838+3939+Default: `["markdown", "html"]`
4040+4141+#### `includeTags`
4242+4343+A list of tags that, if present, will opt a document in to the export.
4444+4545+If `null | undefined`, assumes all tags are applicable.
4646+4747+#### `excludeTags`
4848+4949+A list of tags that, if present, will PREVENT a document from being included in the export.
5050+5151+#### `filter` (config file only)
5252+5353+Function accepting publication and document data, returning a boolean to determine whether the document should be included in the export.
5454+5555+Processes _after_ the `contentTypes`, `includeTags`, and `excludeTags` properties have been applied.
5656+5757+```
5858+({ pub: Publication, doc: Document }) => boolean | Promise<boolean>
5959+```
6060+6161+#### `contentTemplate`
6262+6363+Path to a handlebars template file used to produce the output doc file content.
6464+6565+#### `contentFn` (config file only)
6666+6767+A function that returns the exported doc file content.
6868+6969+```
7070+({ pub: Publication, doc: Document }) => string | Promise<string>
7171+```
7272+7373+### Default config
7474+7575+```
7676+{
7777+ outputDir: ".",
7878+ contentTypes: ["markdown", "html"],
7979+ filename: (doc) => {
8080+ // TODO: is `publishedAt` always an ISO date string?
8181+ const date = doc.publishedAt.slice(0, 10);
8282+ const docSlug = doc.slug ? basename(doc.slug) : slugify(doc.title);
8383+8484+ let extension = "md";
8585+ if (doc.content.$type === "html") extension = "html";
8686+8787+ return `${date}_${docSlug}.${extension}`;
8888+ },
8989+ contentFn: (doc) => `
9090+---
9191+Bun.YAML.stringify({
9292+ title: doc.title
9393+ tags: doc.tags
9494+ publishedAt: doc.publishedAt
9595+}, null, 2);
9696+---
9797+${doc.content}
9898+ `.trim(),
9999+}
100100+```
101101+102102+