File Settings
This is an internal package used by @frontity/core.
Usage
This package is used to import the Frontity settings from a local file.
You can install it with npm
:
npm i @frontity/file-settings
Here is a small example of how to use getSettings
:
import { getSettings } from "@frontity/file-settings";
const settings = await getSettings({
name: "example-name",
url: "https://example.site"
});
API Reference
async getSettings(options) => settings
Used to retrieve the settings from the frontity.settings.js
file.
Parameters
options
: { name?: string; url: string; }
Used to match the right set of settings when there is more than one.
-
options.name
: string (optional)
The name of the set of settings you want to retrieve. When provided, getSettings
won't use options.url
.
-
options.url
: string
The url of the site using Frontity. The matches
field of each set of settings will be tested against this url to determine which set of settings should be used.
Return
settings
: Settings
An object with type Settings
containing a set of settings.
async getAllSites() => sites
Used to retrieve all the sites with its name, mode and packages.
Return
Sites: { name: string; mode: string; packages: string[]; }[]
An array of sites containing name, mode and packages.
[
{
name: "my-site-1",
mode: "html",
packages: ["package-1", "package-2"]
},
{
name: "my-site-1-amp",
mode: "amp",
packages: ["package-1", "package-3"]
},
{
name: "my-site-2",
mode: "html",
packages: ["package-1", "package-2"]
}
];
Settings File
The file must be located in the root directory of the project, it must be named frontity.settings.ts
or frontity.settings.js
, and it needs to export a serializable object.
The settings exported can be mono settings (only one):
{
name?: string;
match?: string[];
mode?: string;
state?: object,
packages: [
string,
{
name: string;
active?: boolean;
state?: object;
}
]
}
Or multi settings:
[
{
name: string;
match?: string[];
mode?: string;
state?: { ... },
packages: [ ... ]
},
{
name: string;
match?: string[];
mode?: string;
state?: { ... },
packages: [ ... ]
}
]
Typescript
The Settings
interface is exposed to be used in development. It can be accessed like this:
import { Settings } from "@frontity/file-settings";
const settings: Settings = { ... };
Settings<T = Package>
Types for the imported settings object from the settings file. You'll want to use them on your frontity.settings.ts
file.