Description
We need some default settings for a Frontity package for two scenarios:
- When we add the package using
npx frontity create
. - When we add the package using
npx frontity install-package
(in the future).
Right now, the settings of mars-theme
are hardcoded but that obviously doesn’t scale.
User Stories
As a Frontity package developer
I want to expose my desired default settings somewhere
so that when other devs install my package, they start with those settings in their frontity.settings.js file
Possible solution
We could get the settings from the package itself after installing, something like this:
installPackage("@frontity/mars-theme");
const pkg = require("@frontity/mars-theme");
const settings = pkg.state;
but that won’t be ideal because:
- It won’t include arrays, which are not populated in the internal state:
state: {
theme: {
menu: []
}
}
versus
state: {
theme: {
menu: [
["Home", "/"],
["Nature", "/category/nature/"],
["Travel", "/category/travel/"],
["Japan", "/tag/japan/"],
["About Us", "/about-us/"]
]
}
}
- It will include parts that are not meant to be settings. For example, the twentytwenty-theme has things like
isMobileMenuOpen: false
orisSearchModalOpen: false
in the state.
My proposal is that we use the frontity.config.js
file for that:
// frontity.config.js
export const defaultState = {
theme: {
menu: [
["Home", "/"],
["Nature", "/category/nature/"],
["Travel", "/category/travel/"],
["Japan", "/tag/japan/"],
["About Us", "/about-us/"]
],
featured: {
showOnList: true,
showOnPost: true
}
}
}
The frontity.config.js
file is meant to be used for other configurations that live outside of webpack, for example babel or webpack because it won’t be affected by the entryPoints
, so I think it’s a good place to store this.
Obviously, it can be optional.
It will be something like this:
installPackage("@frontity/mars-theme");
const { defaultState } = require("@frontity/mars-theme/frontity.config");
If it exists, we add it along with the name of the package:
// frontity.settings.js generated
packages: [
{
name: "@frontity/mars-theme",
state: {
theme: { /* desired default settings... */ }
}
}
]
If it doesn’t exist, we just add the name:
// frontity.settings.js generated
packages: [
"@frontity/mars-theme"
]