Skip to content

not-first/glance-schema

Repository files navigation

Glance Schema

A JSON schema detailing the Glance config file.

Note

Currently represents version: v0.8.4. Now supports validation of split config files using $include!

Usage

The schema is available at: https://raw.githubusercontent.com/not-first/glance-schema/master/schema.json

This schema works with any editor that supports JSON schemas. The examples below use VS Code, but similar configuration can be applied to other editors.

Main Config File (glance.yml)

For your main glance.yml configuration file:

  1. Install the YAML extension for VS Code.
  2. At the top of your glance.yml file, add this line:
    # yaml-language-server: $schema=https://raw.githubusercontent.com/not-first/glance-schema/master/schema.json

Split Config Files

The schema now supports validating split config files using the $include directive. Here are examples for common use cases:

Widget Files

Widget files should always be arrays, even for a single widget (this is the official Glance recommendation):

# yaml-language-server: $schema=https://raw.githubusercontent.com/not-first/glance-schema/master/schema.json#/definitions/widget

- type: weather
  location: New York, United States

Page Files

Page files should also be arrays, even for a single page:

# yaml-language-server: $schema=https://raw.githubusercontent.com/not-first/glance-schema/master/schema.json#/definitions/page

- name: Home
  columns:
    - size: full
      widgets:
        - type: rss
          title: News

Using $include in Your Main Config

Example glance.yml with includes:

# yaml-language-server: $schema=https://raw.githubusercontent.com/not-first/glance-schema/master/schema.json

server:
  port: 8080

pages:
  - $include: pages/home.yml
  - name: Inline Page
    columns:
      - size: full
        widgets:
          - $include: widgets/weather.yml
          - $include: widgets/rss.yml
          - type: clock

Tip

You can also use $include with base config sections (branding, theme, document, server, auth) by using array syntax:

document:
  - $include: config/document.yml

theme:
  - $include: config/theme.yml

Automatic Schema Application for Folders

For projects with dedicated folders for widgets and pages, you can configure VS Code to automatically apply the appropriate schema without adding comments to each file.

Add this to your .vscode/settings.json:

{
  "yaml.schemas": {
    "https://raw.githubusercontent.com/not-first/glance-schema/master/schema.json": ["glance.yml"],
    "https://raw.githubusercontent.com/not-first/glance-schema/master/schema.json#/definitions/widget": ["widgets/*.yml"],
    "https://raw.githubusercontent.com/not-first/glance-schema/master/schema.json#/definitions/page": ["pages/*.yml"]
  }
}

This configuration:

  • Applies the main schema to glance.yml
  • Applies the widget schema (array) to all .yml files in the widgets/ folder
  • Applies the page schema (array) to all .yml files in the pages/ folder

Known Limitations

Some error messages can be autogenerated by the schema validator and are unhelpful in figuring out what is wrong. These can be customised in the schema once they are located, so please create an issue if you experience one.

About

A JSON schema detailing the Glance config file.

Topics

Resources

Contributing

Stars

Watchers

Forks

Languages