Yext Pages projects include a config.yaml file where settings like build settings, page redirects, and authentication are configured. Each section of the YAML describes a different set of site-wide settings.
Build Configuration
The buildConfiguration section specifies the commands for building the application and installing dependencies, highlighting necessary files like package.json and .npmrc.
Below is how the build settings are configured in the Yext starter repository:
buildConfiguration:
buildCommand: npm run build
installDependenciesStep:
command: npm install
requiredFiles:
- package.json
- package-lock.json
- .npmrc
-
buildCommand: The command to be executed for building the application. This script compiles the application's code into a production-ready format. -
installDependenciesStep: Defines the build process.-
command:npm installinstalls the dependencies listed in yourpackage.jsonfile. -
requiredFiles: Files essential for the dependency installation process:-
package.json: Holds project metadata including the list of dependencies to install. -
package-lock.json: Locks the versions of installed packages, ensuring consistency across installations. -
.npmrc: An optional npm configuration file that can specify registry, scopes, and more.
-
-
Live Preview Configuration
livePreviewConfiguration contains settings related to the live preview of the application:
livePreviewConfiguration: serveCommand: "npm run dev -- --port 8080" # setupCommand: ":"
-
serveCommand: Runs a web server on port 8080 which hosts your preview. -
setupCommand(optional): Executes any commands that need to run before theserveCommandstep.
Site Stream
The siteStream settings create global data used site-wide - things like logos and copyright information you may want in every template. The site stream must contain an ID, the Yext Knowledge Graph ID for the entity used in the stream, the fields pulled from that entity, and localization settings:
# The site stream allows for specification of site entity whose data will be injected to all
# generation contexts under the `_site` property.
siteStream:
id: site-stream
entityId: site
fields:
- name
- logo
- c_optionSelectList
localization:
locales:
- en
transform:
replaceOptionValuesWithDisplayNames:
- c_optionSelectList
Check out the Global Data doc for more information and a breakdown of the different fields within siteStream.
Static & Dynamic Routes
The staticRoutes and dynamicRoutes sections let you define rules for how incoming requests with certain paths should be handled. "Static" refers to a one-to-one mapping between paths, while "dynamic" uses placeholders and wildcards to capture parts of the incoming URL and reinsert them into the destination URL.
# Static routes can establish redirects/rewrites from individual source paths to individual destination paths.
staticRoutes:
- from: /old-path
to: /new-path
status: 301
# static rewrite
- from: /user-friendly-url
to: /internal-content-path/page1.html
status: 200
# Dynamic routes can establish redirect/rewrite groups based on pattern matching.
dynamicRoutes:
- from: /articles/*
to: /blogs/:splat
status: 302
# dynamic rewrite
- from: /help/:articleName
to: /support/content/:articleName
status: 200
The URL Routing doc provides greater detail on how to use these settings.
Sitemaps
The Pages system automatically creates a sitemap for each deployment. You can edit the sitemap section of the config for further customization:
# The sitemap configuration allows for customization or disabling of
# automated sitemap generation.
sitemap:
excludeList:
- exclude1
- exclude2
# disableSitemapGeneration: true
# fileName: custom-name.xml
Check out the Sitemaps reference doc for more information.
Authentication
In the authentication section, you can reference an authentication policy added to the Yext platform to protect certain routes:
authentication:
policyName: auth-policy
includePaths:
- /protected-routes/*
Check out the Authentication doc to learn more.
Response Headers
The responseHeaders section lets you specify custom response headers for your site. Custom headers facilitate advanced security measures, efficient content delivery, and interaction with reverse proxies and caching layers.
responseHeaders:
- pathPattern: .*
headerKey: custom-header
headerValues:
- custom-value
Properties:
-
pathPattern: The URL path pattern the header settings should apply to..*matches all paths; you can specify different patterns to target specific paths or groups. -
headerKey: The name of the HTTP header to set or modify. -
headerValues: The value(s) for the specified header that will be sent in the HTTP response.
Serving
If you are forwarding requests to Yext Pages via reverse proxy, add your reverseProxyPrefix:
serving: reverseProxyPrefix: www.brand.com/subdirectory
This ensures:
- Your sitemap is properly generated with the URL prefix in sitemap paths.
- Assets are handled properly.
- The authentication callback URL is properly set relative to the prefix.