2. Settings
The first thing you should do when you start a new Frontity project is to configure your frontity.settings.js file. Let's take a look at each concept you need to understand in order to use it properly.

Site

A site is a set of packages and settings. For example, this is a site:
frontity.settings.js
1
export default [
2
{
3
name: "my-site", // The name of your site.
4
state: {
5
frontity: {
6
url: "https://www.site.com", // Some settings.
7
}
8
},
9
packages: [
10
"@frontity/mars-theme", // And the packages of that site.
11
"@frontity/tiny-router",
12
"@frontity/wp-source"
13
]
14
}
15
]
Copied!

Multiple Sites

One Frontity installation can serve content for multiple sites. This is useful if you have severals blogs and want to manage all of them with the same installation. Both the packages and settings of each site are independent.
To distinguish between different sites, you must use a match setting. Each time a new request is received by Frontity, it tests the URL against the match field to know which site it should load:
1
// frontity.settings.js
2
​
3
export default [
4
{
5
name: "site-1",
6
match: ["https://www.site-1.com"],
7
packages: [...]
8
},
9
{
10
name: "site-2",
11
match: ["https://www.site-2.com"],
12
packages: [...]
13
}
14
]
Copied!
For example, if the URL is https://www.site-1.com/my-post the "site-1" settings are loaded and if the URL is https://www.site-2.com/category/some-cat the "site-2" settings are loaded.
Multisites are encouraged to be defined always with a match property so the internal links defined for the <Link> component can be properly processed from one site to another.
A typical configuration of multisite with:
    The main site linked directly to the main domain
    The blog site linked to a /blog folder below the main domain
can be defined like this...
1
// ./frontity.settings.js
2
​
3
export default [
4
{
5
name: "base", // main site
6
match: "(?!\/blog)", // whatever URL that doesn't match with "/blog"
7
...
8
},
9
{
10
name: "blog", // blog site
11
match: "\/blog", // whatever URL matches with "/blog"
12
...
13
},
14
]
Copied!
In development, you can access a specific site using the ?frontity_name= query, which should match the name specified for your site. For example, using the frontity.settings.js file above, to access site-2, you should use:
1
https://localhost:3000/?frontity_name=site-2
Copied!

Packages

You can specify a different set of packages for each site. They can be either strings or objects:
frontity.settings.js
1
export default [
2
{
3
packages: [
4
"@frontity/mars-theme",
5
"@frontity/tiny-router",
6
{
7
name: "@frontity/wp-source",
8
active: true,
9
state: { // Some settings for this package.
10
source: {
11
url: "https://wp.site.com/"
12
}
13
}
14
}
15
]
16
}
17
]
Copied!
As you can see, they have an active prop. That means you can deactivate a package without having to delete it from your settings file.
In Frontity, all the code is contained in packages. In a sense it is more similar to WordPress, where all the code is contained in your theme and plugins, than to other JavaScript frameworks. This is obviously on purpose, but we will explain the reasons later when we talk about packages and namespaces :)

State

The settings of a Frontity project are written in the state.
If you come from a WordPress background, you can think of Frontity state as the database of your application. And if you come from a React background, well... it's the state that you usually find in Redux or MobX. That state is accessible by your packages at runtime.
The initial settings of a Frontity site can be set in the frontity.settings.js file
frontity.settings.js
1
export default [
2
{
3
name: "my-site",
4
state: {
5
frontity: {
6
url: "https://www.site.com", // Some settings of the site.
7
}
8
},
9
packages: [
10
"@frontity/mars-theme",
11
"@frontity/tiny-router",
12
{
13
name: "@frontity/wp-source",
14
state: { // Some settings for this package.
15
source: {
16
url: "https://wp.site.com/"
17
}
18
}
19
}
20
]
21
}
22
]
Copied!
The state is compartmentalized though namespaces. Each namespace usually corresponds to a Frontity package.
For example, our wp-source package uses the source namespace to store its settings. And our tiny-router package uses the router namespace:
In this way, we keep organized the settings of each package.
frontity.settings.js
1
packages: [
2
{
3
name: "@frontity/tiny-router",
4
state: {
5
router: {
6
autoFetch: true
7
}
8
}
9
}
10
]
Copied!
There's also a special namespace called frontity that is the place to set the general properties of our site. There's a mandatory property we need to set under the frontity namespace: state.frontity.url

state.frontity.url

The important takeaway here is: in the settings file you have the opportunity to change the state of Frontity. Most of the time you will use this to configure the settings of each package.
If you still have any questions about Settings in Frontity, please check out the community forum, which is packed full of answers and solutions to all sorts of Frontity questions. If you don't find what you're looking for, feel free to start a new post.
Last modified 4mo ago