Skip to content

Commit b8d75c5

Browse files
committed
docs: Add Site generation reference documentation
Explain at a high level what `cobalt serve` and `cobalt build` do. Based on this, suggest how to run Cobalt in an existing site's directory. Add the new page to the Reference documentation navigation. Mention the new page on the Start (getting-started) page. Fixes cobalt-org#95
1 parent d4c943d commit b8d75c5

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

_layouts/docs.liquid

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<li><a {% if page.data.route == "install"%}class="active"{%endif%} href="/docs/install">Install</a></li>
1717
<li><a {% if page.data.route == "usage"%}class="active"{%endif%} href="/docs/usage">Usage</a></li>
1818
<li><a {% if page.data.route == "directory"%}class="active"{%endif%} href="/docs/directory">Directory Structure</a></li>
19+
<li><a {% if page.data.route == "site-gen"%}class="active"{%endif%} href="/docs/site-gen">Site generation</a></li>
1920
<li><a {% if page.data.route == "config"%}class="active"{%endif%} href="/docs/config">Configuration</a></li>
2021
</ul>
2122
<hr align="left">

docs/site-gen.md

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
title: "Docs::Site generation"
3+
layout: docs.liquid
4+
data:
5+
route: site-gen
6+
---
7+
## Site generation
8+
9+
[`cobalt serve`](/docs/usage) and `cobalt build` process your entire source directory the same
10+
way. Both write asset files, transformed files, and generated pages to an output
11+
directory; `cobalt serve` writes to a temporary directory while `cobalt build`
12+
writes to a [`destination`](/docs/config) directory (default `./_site`). `cobalt serve` also
13+
runs a web server to serve this static content, and then continues to watch the
14+
source directory for changes.
15+
16+
### Generation process
17+
18+
The generation process is, approximately,
19+
1. Cobalt considers every file in the [`source`](/docs/config)directory.
20+
2. It skips directories and file names beginning with dot `.` or underscore
21+
`_`, and other files and directories. You can specify additional files and
22+
directories to skip using the [`ignore`](/docs/config) configuration
23+
variable.
24+
3. It treats all remaining files that aren't pages and posts (see later) as
25+
[assets](/docs/assets) and copies them to the output directory. It may
26+
preprocess Sass files to turn them into CSS.
27+
4. If a file has an extension in [`template_extensions`](/docs/config) (the
28+
default extensions are `.html` and `.md`), then Cobalt treats it as a
29+
[page](/docs/pages):
30+
- Cobalt looks for a [frontmatter](/docs/front) section (lines between a pair
31+
of `---`) in it, if any, and evaluates metadata settings in it.
32+
- If the site [configuration](/docs/configuration) or the page's
33+
frontmatter specifies a [layout](/docs/layout), Cobalt wraps the file in
34+
that layout's Liquid template.
35+
- Cobalt evaluates any [liquid template](https://shopify.github.io/liquid/)
36+
expressions in the file (to simplify, directives inside curly braces `{...}`).
37+
- Cobalt writes the transformed file to the output directory with, by
38+
default, a `.html` extension. A file with no frontmatter or liquid
39+
template expressions will be unchanged.
40+
5. If a file with a template extension is in the [`posts`](/docs/posts)
41+
directory, Cobalt processes it further, such as draft handling. A page's
42+
frontmatter can direct Cobalt to generate a list of pages, for example a
43+
paginated list of blog posts.
44+
6. Cobalt may generates additional files, such as an `rss.xml` feed.
45+
46+
### Generating from an existing static site
47+
48+
You can run `cobalt serve` or `cobalt build` in your existing static site's
49+
directory.
50+
- They will create a lot of files in the output directory, but will not create
51+
new files or modify existing files in your source directory. _Caution_,
52+
`cobalt build` will overwrite files in an existing destination directory
53+
(which defaults to `./_site`).
54+
- The commands will complain if you don't have a `_config.yml` file or specify
55+
the path to one, nevertheless Cobalt will do default processing.
56+
- Even if your existing files have extensions that Cobalt treats as pages, as
57+
explained in "Generation process" they will not be transformed if they don't
58+
contain liquid templates and a frontmatter section, and you don't specify a
59+
default [`layout`](/docs/config).
60+
- Some assets that you want to appear in the output directory, such as
61+
`.htaccess` files and the `.well-known` directory, may not appear;
62+
conversely, unintended files may appear.
63+
64+
To start adjusting Cobalt's site generation you need to provide a
65+
[configuration](/docs/config) file. Running [`cobalt init`](docs/usage/) will
66+
create a `_config.yml` file and a few sample files and layout. If files
67+
already exist with the same names, `cobalt init` will not overwrite them but
68+
fail, so you could run it in your existing site directory, or you can run it
69+
in an empty directory and copy over files as needed. You can specify the path
70+
to your configuration file with the `--config` _\<FILE>_ command-line option.

getting-started.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ or
1313
$ curl -LSfs https://raw.githubusercontent.com/crate-ci/gh-install/master/v1/install.sh | sh -s -- --git cobalt-org/cobalt.rs --crate cobalt
1414
```
1515

16-
### Usage
16+
### Basic usage
1717

1818
#### Start
1919

@@ -68,3 +68,6 @@ $ cobalt build
6868
```
6969

7070
The site is sitting in `_site` and ready to be uploaded!
71+
72+
If you have an existing site, read [Site generation](/docs/site-gen) to better
73+
understand Cobalt's operation so you can run it in your site directory.

0 commit comments

Comments
 (0)