Template for multi-page SSR website with dynamic content
Links:
npx create-next-app@latest <my-app> --example https://github.com/gravity-ui/page-constructor-website-template
cd my-app
rm -rf .git
Template supports two build modes:
This mode is set by default.
npm ci
npm run dev
npm ci
npm run build
npm run start
SSG mode supports now only one locale, to set it use EXPORT_LOCALE
env variable.
npm ci
npm run dev:export
npm ci
# generate static production build and puts it to `out` folder.
npm run build:export
# run this locally to check everyting works in production mode
npm run start:export
You can define environment variables for dev-mode in .env.local
file within project root.
ALLOW_ROBOTS
- allow search engine robots to index your app;
APP_ENV
- environment prod
, preprod
or dev
;
DISABLE_LOGGING
(optional) - turn logging off;
LOGGING_LEVEL
(optional) - set logging level (default debug
). More about logging level;
PAGES_CACHE_TIME
(optional) - page data cache living time in production;
NAVIGATION_CACHE_TIME
(optional) - navigation data cache living time in production;
EXPORT_MODE
(optional) - boolean, sets export mode on
EXPORT_LOCALE
(optional) - sets locale for export mode
DEV_MODE
- enables dev mode;
SITE_URL
- site url, it will be used for creating sitemap
By default website template keeps it's content inside content
folder in .yaml
files, splitted by locales, e.g content/en
, content/fr
There are two types of content files:
-
pages
- each file in the directory represents website page. Page url is defined by file name and path (pages
folder equals to the site root). Page file data format is compatible with page-constructor content -
data
files keep whole site related data (navigation, meta, analytics configuration, etc). Navigtion file format is compatible with page-constructor navigation
To use custom api for getting page data implement method returning value of type ContentResponseType
in src/server/api/pages-data/implementations/
folder and export it from src/server/api/pages-data/impl.js
.
interface ContentResponseType {
statusCode: 200 | 404 | 500;
error?: string;
data?: ConstructorPageContent;
}
- Set the SITE_URL for sitemap
- You can find sitemap in src/pages/server-sitemap.xml
- Set the SITE_URL for sitemap
- Every build we use next-sitemap to auto-generate sitemap and robots
- For SSG mode (EXPORT_MODE) - fix command
build:export
in package.json and remove src/pages/server-sitemap.xml - For Default mode - remove src/pages/server-sitemap.xml