---
title: "getPageMarkdown"
description: "Build the page Markdown of a node's entry page by slug, or of the index page without one."
canonical: "https://www.qino.works/docs/api/tree/get-page-markdown"
---

# getPageMarkdown

> Build the page Markdown of a node's entry page by slug, or of the index page without one.

Builds the page Markdown of a node's entry page, the document served to agents in place of the page. Without a slug, it builds the index page's. The tree must declare [`pages`](https://www.qino.works/docs/api/tree#parameters).

```ts title="src/app/md/docs/[...slug]/route.ts"
const page = await docsTree.getPageMarkdown("guide/cli");
const docs = await docsTree.getPageMarkdown();
```

## Signature

```ts title="@qino/cms"
tree.getPageMarkdown(slug: string): Promise<string | null>;
tree.getPageMarkdown(): Promise<string>;
```

## Parameters

| Name   | Type     | Required | Description                                                                                                                |
| ------ | -------- | -------- | -------------------------------------------------------------------------------------------------------------------------- |
| `slug` | `string` | no       | Slash-joined path minus extension, such as `guide/cli`. Any string, such as a route param. Leave it out for the index page |

Tree views can't filter, so it takes no view and reads the entry without one.

## Returns

For an entry page, `Promise<string | null>`:

- A frontmatter block: `title`, `description` on one line when there is one, and `canonical`, the entry page's URL on `siteUrl`, each a quoted string.
- `# {title}`, from the tree's `titleField` and falling back to the slug, then `> {description}` when the `description` field holds one, then the body without its own frontmatter.
- No heading when the body opens with its own H1. The frontmatter block still holds the title and description.
- Site-relative links and images made absolute on `siteUrl`, and MDX components replaced through [`pages.markdownComponents`](https://www.qino.works/docs/api/types/page-markdown-component).
- `null` when no node has the slug, `""` included.

For the index page, `Promise<string>`: a frontmatter block with `title`, which is `pages.title`, and `canonical`, the index page's URL. Then `# {pages.title}`, and a `##` section per root node, titled by that node and listing the node and then its descendants, in tree order:

```md title="https://www.qino.works/docs.md"
---
title: "Docs"
canonical: "https://www.qino.works/docs"
---

# Docs

## Guide

- [Guide](https://www.qino.works/docs/guide.md): Install qino, lay out a project, and run the CLI.
- [Philosophy](https://www.qino.works/docs/guide/philosophy.md): Why qino is a flat-file CMS and what it deliberately leaves out.
```

## Throws

- `Tree "<directory>" has no pages: declare them to get page Markdown and Markdown URLs.`
- Layout errors from walking the tree. See [getTree](https://www.qino.works/docs/api/tree/get-tree).
- Validation, relation, augment, and component function errors. See [Errors](https://www.qino.works/docs/api/errors).

## See also

- [getMarkdownUrl](https://www.qino.works/docs/api/tree/get-markdown-url)
- [negotiateMarkdown](https://www.qino.works/docs/api/negotiate-markdown)
