jekyll/docs/_docs/deployment/multiple-sites.md

45 lines
2.2 KiB
Markdown

---
title: Multiple Sites and Target
permalink: /docs/deployment/multiple-sites/
---
The `target` setting in `_config.yml` and frontmatter in conjunction with config stacking allows multiple sites with varitation to be built from one codebase.
## Use Case
You may have multiple access paths to your site, and want to offer unique content on some of them, for examples you may have a open web version of your site at `https://foo.com` and you may also have an [onion service](https://community.torproject.org/onion-services/setup/) version of your site accesible via `http://foo000...abc.onion`. Alternately you may have a public facing version of the site, and an internal network or VPN accessible version that you want additional content to be included on.
## Method
By default the `target` config option is set to "default" in `_site_config.yml` and when comparing with frontmatter of content, if none is set, it inherit's the site's value. So by default all content will be published. To make content only appear on a specific version of a site, in frontmatter add `target: xVersion` where "xVersion" will be a `target` option set in a second `_site_x.yml`.
You generate the normal site the same
`bundle exec jekyll build`
For the second site, you create a mini site specific config, like
```yml
url: https://altDomain.com
destination: _site_xVersion
target: xVersion
```
and build it with
`bundle exec jekyll build --config "_config.yml,_config_xversion.yml"`
Jekyll configs stack, and overrides from additional configs override earlier ones, so this will get all the default site config options and then just change `url`, `destination` and `target`
Then any content with a frontmatter `target` of "xVersion" will be included in this build which will be output to the new `_site_xVersion`.
If there is any content you want on the default version of the site but not any alternative ones, just add `target: default` to it's frontmatter.
Then configure your webserver with a second site config with the alternative access path and pointing to `_site_xVersion` directory.
### Potential Cons
This does result in multiple builds, which is potentially the one negative of this method if you are very constrained for space or your jekyll site is very large.