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.
Property | Type | Description |
---|---|---|
nameRequired | string | A unique identifier for the page |
textRequired | string | The label shown to the user in Spotlight |
templateRequired | object | The schema defining the page |
shortcut_mac | array<string> | The sequence of hotkeys required to navigate to this page if the user is using MacOS |
shortcut_win | array<string> | The sequence of hotkeys required to navigate to this page if the user is using Windows or Linux |
hotkey_mac | string | The sequence of hotkeys required to navigate to this page if the user is using MacOS (mousetrap.js format) |
hotkey_win | string | The sequence of hotkeys required to navigate to this page if the user is using Windows or Linux (mousetrap.js format) |
heading | string | The string shown above text in Spotlight. You can interpolate metadata or records into this value. |
explanation | string | The subtitle string shown under text in Spotlight |
extra | string | The key of a custom component added with addComponent. If the key is specified, the custom component will render below the page in Spotlight. |
sort_key | number | A key that will determine the page's order in its category (sorted low to high) |
category | number or string | The id (or name) of the category to which this page belongs |
icon | string | Icon to show alongside this page. Can be a URL (absolute or relative) or an emoji character. |
template
object
Property | Type | Description |
---|---|---|
valueRequired | string | The URL to open. |