Back to Scalar

Site

documentation/guides/docs/configuration/site-config.md

latest8.5 KB
Original Source

Site

The site configuration defines global settings for your documentation site: branding, custom head elements, footer content, and routing rules. These settings apply across your entire documentation site.

All site settings are configured within the siteConfig object in your scalar.config.json file.

Example

json
// scalar.config.json
{
  "$schema": "https://registry.scalar.com/@scalar/schemas/config",
  "scalar": "2.0.0",
  "siteConfig": {
    "logo": "https://example.com/logo.svg",
    "theme": "default"
  }
}

The logo property defines your site's logo displayed in the navigation. You can provide a single URL for all modes, or separate logos for light and dark themes.

json
// scalar.config.json
{
  "$schema": "https://registry.scalar.com/@scalar/schemas/config",
  "scalar": "2.0.0",
  "siteConfig": {
    "logo": "https://example.com/logo.svg"
  }
}

Light and Dark Mode

For better visibility across themes, provide different logos for light and dark modes:

json
// scalar.config.json
{
  "$schema": "https://registry.scalar.com/@scalar/schemas/config",
  "scalar": "2.0.0",
  "siteConfig": {
    "logo": {
      "darkMode": "https://example.com/logo-dark.svg",
      "lightMode": "https://example.com/logo-light.svg"
    }
  }
}

Properties

PropertyTypeRequiredDescription
logostringNoURL to a single logo for all themes
darkModestringNoURL to the logo displayed in dark mode
lightModestringNoURL to the logo displayed in light mode

Theme

The theme property sets a platform-defined theme for your documentation site.

json
// scalar.config.json
{
  "$schema": "https://registry.scalar.com/@scalar/schemas/config",
  "scalar": "2.0.0",
  "siteConfig": {
    "theme": "purple"
  }
}

Properties

PropertyTypeRequiredDescription
themestringNoSlug for a platform-defined theme

Layout

The layout property controls global layout options that apply to all pages unless overridden at the page level.

json
// scalar.config.json
{
  "$schema": "https://registry.scalar.com/@scalar/schemas/config",
  "scalar": "2.0.0",
  "siteConfig": {
    "layout": {
      "toc": true,
      "header": true
    }
  }
}

Properties

PropertyTypeDefaultDescription
tocbooleantrueWhether to show the table of contents globally
headerbooleantrueWhether to show the header globally

The head property allows you to inject custom elements into the HTML <head> of your documentation pages. This is useful for adding custom styles, scripts, meta tags, and favicon links.

Example

json
// scalar.config.json
{
  "$schema": "https://registry.scalar.com/@scalar/schemas/config",
  "scalar": "2.0.0",
  "siteConfig": {
    "head": {
      "title": "My Documentation",
      "meta": [
        {
          "name": "description",
          "content": "Documentation for my API"
        },
        {
          "property": "og:image",
          "content": "https://example.com/og-image.png"
        }
      ],
      "styles": [
        {
          "path": "assets/custom-styles.css"
        }
      ],
      "scripts": [
        {
          "path": "assets/analytics.js"
        }
      ],
      "links": [
        {
          "rel": "icon",
          "href": "/favicon.png"
        }
      ]
    }
  }
}

Properties

PropertyTypeRequiredDescription
titlestringNoThe page title
metaarray | objectNoMeta tags for SEO and social sharing
stylesarrayNoCSS files to include
scriptsarrayNoJavaScript files to include
linksarrayNoLink elements (favicon, preload, etc.)

Meta Tags

Meta tags can be provided as an array of objects or as a key-value object:

Array Format

json
"meta": [
  {
    "name": "description",
    "content": "My API documentation"
  },
  {
    "property": "og:title",
    "content": "My API"
  }
]

Object Format

json
"meta": {
  "description": "My API documentation",
  "og:title": "My API"
}

Styles

Include custom CSS files in your documentation:

json
"styles": [
  {
    "path": "assets/custom-styles.css",
    "tagPosition": "head"
  }
]
PropertyTypeRequiredDescription
pathstringYesRelative path to the CSS file
tagPosition"head" | "bodyEnd"NoWhere to inject the style tag

Scripts

Include custom JavaScript files:

json
"scripts": [
  {
    "path": "assets/analytics.js",
    "tagPosition": "bodyEnd"
  }
]
PropertyTypeRequiredDescription
pathstringYesRelative path to the JavaScript file
tagPosition"head" | "bodyEnd"NoWhere to inject the script tag

Add link elements for favicons, preloading resources, or other purposes:

json
"links": [
  {
    "rel": "icon",
    "type": "image/png",
    "href": "/favicon.png"
  },
  {
    "rel": "preconnect",
    "href": "https://fonts.googleapis.com"
  }
]
PropertyTypeRequiredDescription
relstringYesThe relationship type (icon, preload)
hrefstringYesThe URL or path to the resource
typestringNoThe MIME type of the resource

The footer property allows you to add a custom footer to your documentation site.

json
// scalar.config.json
{
  "$schema": "https://registry.scalar.com/@scalar/schemas/config",
  "scalar": "2.0.0",
  "siteConfig": {
    "footer": {
      "filepath": "docs/footer.html",
      "belowSidebar": true
    }
  }
}

Properties

PropertyTypeDefaultDescription
filepathstringRelative path to a custom HTML footer file
belowSidebarbooleanfalsePosition the footer below the sidebar navigation

Routing

The routing property configures URL redirects and path patterns for your documentation.

Redirects

Set up redirects to handle URL changes or aliases:

json
// scalar.config.json
{
  "$schema": "https://registry.scalar.com/@scalar/schemas/config",
  "scalar": "2.0.0",
  "siteConfig": {
    "routing": {
      "redirects": [
        {
          "from": "/old-path",
          "to": "/new-path"
        },
        {
          "from": "/docs/v1",
          "to": "/docs/latest"
        }
      ]
    }
  }
}

Properties

PropertyTypeRequiredDescription
redirectsarrayNoArray of redirect rules
guidePathPatternstringNoURL pattern for guide pages
referencePathPatternstringNoURL pattern for API reference pages

Redirect Object

PropertyTypeRequiredDescription
fromstringYesThe source path to match
tostringYesThe destination path

Path Patterns

Customize the URL structure for guides and API references:

json
"routing": {
  "guidePathPattern": "/docs/:slug",
  "referencePathPattern": "/api/:slug"
}