Edit documentation Edit document
SSR/SSG

Config

Every website should have config.mjs in it's root folder. This file will help you to configure your website properly. Bellow, you will see all possible settings with example values and explanation.

Config properties

Routes

export const routes = [
    {
        route: '/example/',
        index: '/example/example.htm'
    },
    {
        route: '/blog/:category/',
        index: '/blog/category.html'
    },
    ...
]

Here you can configure routes for your website. This must be array of objects. In each object must be route and index properties. <br><br> Route property - is the url of page you want to create. <br><br> Index property - is a path to html file, which should be opened on this route. <br><br> Dynamic routes. You probably noticed this route - /blog/:category/. This is dynaimic route. It can be used for dynamic pages (articles, categories, authors for blog e.x.). This route will work in cases like this: /blog/web-development/ and will return /blog/category.html html file. <br> You can have multiple dynamic parts in one route, like this - /blog/:category/:article/. <br> Also, you can mix dynamic routes with simple ones. <br>

export const routes = [
    {
        route: '/blog/example/',
        index: '/blog/example.html'
    },
    {
        route: '/blog/:category/',
        index: '/blog/category.html'
    },
    {
        route: '/blog/authors/:author/',
        index: '/blog/author.html'
    },
    {
        route: '/blog/:category/:article/',
        index: '/blog/article.html'
    }
]

BE AWARE. In case like above, order of routes is important! Because, route, for example, /blog/example/ match both /blog/example/ and /blog/:category/. That's why, simple routes must be above dynamic.

Auth key

export const auth_key = '*****';

This auth_key will be used while accessing applications and their data on server side while rendering.

Build folder

export const build_folder = 'dist';

If you have a website with bundler (webpack e.x), you need to pass here your build folder name. If you have simple website, just remove this variable or leave it empty.

Index sitemap

export const index_sitemap = true;

If index_sitemap set to true, server will generate index sitemap and child sitemaps, based on chapters sitemap configuration (see chapters configuration). If this property is equals to false, then server will generate one sitemap with all pages.

Chapters

export const chapters = {
    pages: {
        app_id: 00000,
        slug_field_id: 000000,
        element_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;
                });
            }
        }
    }
}

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. <br> Every chapter object should have these properties:

  • app_id - app id of application for this chapter.
  • slug_field_id - field id of field with slug (url) of page. <br> Next properties may be optional:
  • element_id - field id of field with data (json editor data type).
  • sitemap - configuration object for sitemap.
    • frequency - default frequency for all pages.
    • priority - default priority for all pages.
    • sitemapName - 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 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 chage priority and frequency for homepage and example page.
      • case - for which page this case should work. Cat receive string with slug or regular expression.
      • priority - value of priority for this case.
      • frequency - value of frequency for this case.
      • sitemapName - 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.
    • filter - 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.
export const redirects = [
    {
        from: '/example/',
        to: '/example-2/'
    }
]

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).