Skip to main content

addCommand(page)

Add a page to CommandBar and returns a promise. This is especially useful for ingesting a sitemap and creating pages for each valid URL in a site.

Example

// Adds a Page
window.CommandBar.addCommand({
text: 'Go to Home',
name: 'go_to_page_home',
template: {
type: 'link',
value: '/home',
operation: 'self' // how should the page open
},
category: "Navigation",
});

// Advanced - Adds a general 'Go to page' Action and provides each page as an argument
window.CommandBar.addCommand({
text: "Go to page",
name: "go_to_any_page",
template: {
type: "link",
value: "/{{pageName}}",
operation: "self",
},
arguments: {
pageName: {
type: "set",
value: ["home", "about", "contact"],
order_key: 1,
},
},
category: "Navigation",
});

// Wait for addCommand to complete
await window.CommandBar.addCommand({...});

Method parameters

page Required

object

The page schema.

PropertyTypeDescription
nameRequired
stringA unique identifier for the page
textRequired
stringThe label shown to the user in Spotlight
templateRequired
objectThe schema defining the page
shortcut_macarray<string>The sequence of hotkeys required to navigate to this page if the user is using MacOS
shortcut_winarray<string>The sequence of hotkeys required to navigate to this page if the user is using Windows or Linux
hotkey_macstringThe sequence of hotkeys required to navigate to this page if the user is using MacOS (mousetrap.js format)
hotkey_winstringThe sequence of hotkeys required to navigate to this page if the user is using Windows or Linux (mousetrap.js format)
headingstringThe string shown above text in Spotlight. You can interpolate metadata or records into this value.
explanationstringThe subtitle string shown under text in Spotlight
extrastringThe key of a custom component added with addComponent. If the key is specified, the custom component will render below the page in Spotlight.
sort_keynumberA key that will determine the page's order in its category (sorted low to high)
categorynumber or stringThe id (or name) of the category to which this page belongs
iconstringIcon to show alongside this page. Can be a URL (absolute or relative) or an emoji character.

template

object

PropertyTypeDescription
valueRequired
stringThe URL to open.