# Advanced menu

> Advertising code editor, duplicate, version history, export, and reveal actions from a custom ClayJS host.

Source: https://clayjs.com/docs/advanced/menu/

For servers implementing host-provided menu actions through `GET /_/meta`; for configuring and extending the menu on a page, see [menu](https://clayjs.com/docs/plugins/menu/).

## For host authors

The code editor, new document, duplicate, version history, export and show-in-folder items come from the host. Add an `actions` object to the `document` block of `GET /_/meta`, naming only the pages this caller may open:

```json
{
  "document": {
    "actions": {
      "codeEditor": { "href": "/_/edit/notes/today.html" },
      "versions": { "href": "/_/versions/notes/today.html" },
      "duplicate": { "href": "/_/copy/notes/today.html" },
      "newDocument": { "post": "/_/new-document" }
    }
  }
}
```

Each `href` resolves against the page and must be `http:` or `https:`; anything else is ignored. A host without the block shows none of them.

An action can ask the host to do something instead of opening a page. Name a same-origin URL with `post`:

```json
{
  "document": {
    "actions": {
      "newDocument": { "post": "/_/new-document" },
      "reveal": { "post": "/_/reveal" },
      "export": { "post": "/_/export" },
      "versions": { "post": "/_/versions-folder" }
    }
  }
}
```

The menu sends a `POST` with the page's cookies and a `Document-URL` header naming the page, and reads a JSON answer. `{ "ok": true }` is done. `{ "ok": true, "href": "..." }` also opens that address in a new tab, which is how `newDocument` and `duplicate` show their new file. `{ "ok": false, "message": "..." }` shows the message beside the menu button. A `post` on another origin is ignored.

The six names are `codeEditor`, `newDocument`, `duplicate`, `versions`, `export` and `reveal`. The reveal item reads **Show in Finder** on a Mac, **Show in Explorer** on Windows, and **Show in folder** elsewhere. HTML Clay offers `reveal`, `versions` and `export`; Hyperclay Local offers all six. Answer it per caller, the same way the rest of the `document` block is answered, so the menu never offers a page that then refuses.
