Config
Every website should have config.mjs
in it's root folder. This file will help you to configure your website properly.
There is a set of properties that allow you to customize the configuration exactly as you need it. Some of them are mandatory, some are used as needed. In total, there are 6 such properties:
- Routes
- Auth key
- Build folder
- Configuration Object for GudHub Initialization
- Query params cache whitelist
- Index sitemap
- Website name
- Website description
- Chapters
- Redirects
The template config file contains only these three: Auth key, Build folder, Chapters.
Note that all properties from the config file will be passed to the server.
This allows you to securely transfer data to the server and then use it in development. All those properties will be stored in window.constants
on server.
Config properties
This section provides detailed information about all available configuration properties that can be used for a GudHub DXP-based project.
Routes
The first property in this list allows you to configure routes for your website:
export const routes = [
{
route: '/example/',
index: '/example/example.htm'
},
{
route: '/blog/:category/',
index: '/blog/category.html'
},
...
]
This must be an array of objects, each of which contain route and index properties.
More detailed information read in chapter Routing.
Auth Key
This is a property that is mostly used to securely transmit the authentication key to the server:
export const auth_key = 'kjjjHKSKDJSIOUIO-kJSCNKSJIU';
This auth key will be used while accessing applications and their data on server side while rendering.
It also sometimes can be used in the sitemap.
Build Folder
This property is used to set the folder for your build:
export const build_folder = 'dist';
If you have a website with bundler (webpack e.x), you need to pass here your build folder name. That is, the builded files of the site will be stored in this folder.
If you have simple website, just remove this variable or leave it empty.
Configuration Object for GudHub Initialization
This object is used as a configuration for initializing GudHub.
export const gudhub_db_settings_config = {
server_url : 'https://example.com/GudHub',
wss_url : 'wss://example.com/GudHub/ws/app/',
initWebsocket : false
};
If it is not provided, the default configuration will be applied.
Query Params Cache Whitelist
The array stores the keys for query parameters whose corresponding pages will be cached on the server.
export const query_params_cache_whitelist = ['example-type', 'example-status', 'example-color', 'example-price-level'];
This whitelist is a security feature used to control which query parameters are allowed for caching. Only the specified query parameters will be stored in the cache, ensuring efficient retrieval and reducing load times for repeated queries.
If this configuration is not provided, query parameters will not be cached by default. Only parameters listed in this array will be cached, so adding or removing parameters allows you to control what pages is stored on the server for improved performance and data control.
Index Sitemap
The current property allows you to determine whether a sitemap index will be created or not:
export const index_sitemap = true;
If index_sitemap
is set to true, the server will generate an index sitemap and child sitemaps based on the chapter sitemap configuration.
If this property is false, the server will generate a single sitemap with all pages.
Website Name
The current property is designed to set the name of the website:
export const website_name = 'Atlasiko';
This value will be used as title in feeds(rss, atom, json). To learn more about feeds, see chapters configuration.
Website Description
This is the property that allows you to use descriptions:
export const website_description = 'Example of website description.'
Namely, when you set the specific description, then it can be used be used as title in feeds(rss, atom, json). For more information about channels, see in Chapters
Chapters
The current property contains all chapters of the site with their properties.
It is one of the mandatory properties.
Here you can add new chapters or delete existing ones:
export const chapters = {
pages: {
app_id: 00000,
slug_field_id: 000000,
element_id: 000000,
title_field_id: 000000,
description_field_id: 000000,
thumbnail_field_id: 000000,
created_at_field_id: 000000,
author_reference_field_id: 000000,
sitemap: {
frequency: 'weekly',
priority: 0.8,
sitemapName: 'pages',
cases: [
{
case: '/',
priority: 1,
frequency: 'daily'
},
{
case: /example/g,
priorite: 0.2,
frequency: 'weekly',
sitemapName: 'examples'
}
],
filter: (items) => {
return items.filter(item => {
const field = item.fields.find(field => field.field_id == 699138);
if(field) {
return field.field_value == 1;
}
return false;
});
}
},
feed: {
google_news: {
filter: (items) => {
let filteredItems = items.filter(item => {
const field = item.fields.find(field => field.field_id == 697704);
if(field) {
return field.field_value == 1;
}
return false;
});
filteredItems = filteredItems.filter(item => {
const field = item.fields.find(field => field.field_id == 698599);
if(field) {
return field.field_value == 3;
}
return true;
});
return filteredItems;
}
}
}
}
}
A Chapter is an object that stores chapters as properties. Each chapter has its own set of properties, which are stored in the object as well. There are only two mandatory properties:
Property Name | Type | Description |
---|---|---|
app_id |
number |
app id of application for this chapter |
slug_field_id |
number |
field id of field with slug (url) of page |
All other properties are optional:
Property Name | Type | Description |
---|---|---|
element_id |
number |
field id of field with data (json editor data type) |
title_field_id |
number |
field id of field with page title (text). Will be used in feed generation |
description_field_id |
number |
field id of field with page description (text editor). Will be used in feed generation |
thumbnail_field_id |
number |
field id of field with thumbnail path (text). Will be used in feed generation |
created_at_field_id |
number |
field id of field with created at date (date). Will be used in feed generation |
author_reference-field_id |
number |
field id with reference to page author. Author item should be in the same application as pages. Will be used in feed generation |
sitemap |
object |
configuration object for sitemap |
feed |
object |
if you want to generate feed (rss, atom, json), you should add this property to chapter, you want to generate feed for. Currently, we support only one feed for one chapter per website |
If you want some sort of CMS, you need to create GudHub application for your website.
It will be better, to create separate application for every logical part of website (simple pages, blog, products, etc.). Every item in these applications will be page in future. For every application you need to create object in chapters object like above.
Sitemap
The sitemap is a list of information about pages, video, and other file on your site. In the config file, this sitemap is specified as a property of chapters. But it also has its own properties:
export const chapters = {
pages: {
app_id: 00000,
slug_field_id: 000000,
sitemap: {
frequency: 'weekly',
priority: 0.8,
sitemapName: 'pages',
cases: [
{
case: '/',
priority: 1,
frequency: 'daily'
},
{
case: /example/g,
priorite: 0.2,
frequency: 'weekly',
sitemapName: 'examples'
}
],
filter: (items) => {
return items.filter(item => {
const field = item.fields.find(field => field.field_id == 699138);
if(field) {
return field.field_value == 1;
}
return false;
});
}
}
}
}
Property Name | Type | Description |
---|---|---|
frequency |
string |
default frequency for all pages |
priority |
number |
default priority for all pages |
sitemapName |
string |
if you set index_sitemap to true, this property will generate separate sitemap for pages from this chapter and adds link to it in index sitemap |
cases |
array |
array of special cases. If some pages must have different properties in sitemap from other in this chapter, you should create cases for this pages. In example above we change priority and frequency for homepage and example page |
filter |
function |
if you want to filter some pages, to not add them to sitemap, you can create filter. Filter property receive javascript function and run it. In example above, we are filtering all pages, that have status property equal to 'draft' in gudhub |
As mentioned above, an object called cases has its own set of properties:
Property Name | Type | Description |
---|---|---|
case |
string |
for which page this case should work. Cat receive string with slug or regular expression |
priority |
number |
value of priority for this case |
frequency |
string |
value of frequency for this case |
sitemapName |
string |
if you want to create separate sitemap for this case(s), you can pass it's name here. Then, separate sitemap with given name will be generated, and all pages that meet the condition will be added in it. Also, this pages will be removed from parent sitemap, to avoid the duplicates |
Feed
This property allows you to create RSS for the specific chapter.
It can be used for only one chapter within an array.
To create a feed you need the google_news
inside the feed
object, chapter properties:
app_id
slug_field_id
element_id
title_field_id
description_field_id
thumbnail_field_id
And two config properties: Website Name and Website Description. The feed object has its own properties:
export const chapters = {
pages: {
app_id: 00000,
slug_field_id: 000000,
element_id: 000000,
title_field_id: 000000,
description_field_id: 000000,
thumbnail_field_id: 000000,
created_at_field_id: 000000,
feed: {
google_news: {
filter: (items) => {
let filteredItems = items.filter(item => {
const field = item.fields.find(field => field.field_id == 697704);
if(field) {
return field.field_value == 1;
}
return false;
});
filteredItems = filteredItems.filter(item => {
const field = item.fields.find(field => field.field_id == 698599);
if(field) {
return field.field_value == 3;
}
return true;
});
return filteredItems;
}
}
}
}
}
Property Name | Type | Description |
---|---|---|
google_news |
object |
name of service to generate feed for. Currently, only google news is supported, so if you want to generate feed, you should add this property |
filter |
function |
if you want to filter some pages, to not add them to feed, you can create filter. Filter property receive javascript function and run it. In example above, we are filtering all pages, that have status property equal to 'draft' and in next step filtering all pages, that have status not equal no "News" in gudhub app |
Usually, you only need to create a google_news
. The filter
only further filters the pages. When you create a feed, you create three types of feeds at the same time: RSS, Atom, and JSON.
Redirects
The last property allows you to create redirects to any page:
export const redirects = [
{
from: '/example/',
to: '/example-2/'
}
]
Property Name | Type | Description |
---|---|---|
from |
string |
the route from which redirects will be made |
to |
string |
the route to which redirects will be made |
Here you can create redirects for your website. Redirects property is an array of objects. Each object should has from and to properties. All redirects will have 300 status (moved permanently).