# Installation

> Create a JAAB blog, or add JAAB to an existing Astro project, alone or beside JAAD.

`npm create @jaamd` sets up a blog in one command. To add JAAB by hand, see
[Manual installation](#manual-installation); for documentation and a blog on
one site, see [Docs and a blog](#docs-and-a-blog).

## Create a project

**npm**

```bash
npm create @jaamd@latest -- --template blog
```

**pnpm**

```bash
pnpm create @jaamd@latest --template blog
```

**yarn**

```bash
yarn create @jaamd --template blog
```

**bun**

```bash
bunx @jaamd/create@latest --template blog
```

The CLI asks for a destination, title and whether to install dependencies. The
`blog` template puts the posts at `/`; `--template docs-blog` sets up
[docs and a blog](#docs-and-a-blog) together, with the docs at `/` and the blog
at `/blog`. `--here` adds them to a repository you already have, without
overwriting a file: see [JAAD's installation](https://docs.jaamd.org/jaad/getting-started/installation.md)
for every option.

## Run locally

```bash
npm run dev
```

The development server starts at `http://localhost:4321`. Add posts to
`blog/`, following [Posts](https://docs.jaamd.org/jaab/getting-started/posts.md).

## Manual installation

Install JAAB in a project on Astro 7, from 7.3, with Node.js 22.23.4 or later:

**npm**

```bash
npm install @jaamd/jaab astro
```

**pnpm**

```bash
pnpm add @jaamd/jaab astro
```

**yarn**

```bash
yarn add @jaamd/jaab astro
```

**bun**

```bash
bun add @jaamd/jaab astro
```

Tailwind is needed only with [`tailwind: true`](https://docs.jaamd.org/jaad/configuration/tailwind.md):
`tailwindcss` and `@tailwindcss/vite`, from 4.3.

Add the following files:

```ts
// jaab.config.ts
import { defineJaabConfig } from '@jaamd/jaab'

export default defineJaabConfig({
    site: 'https://example.dev',
    title: 'My blog',
})
```

```js
// astro.config.mjs
export { default } from '@jaamd/jaab/site'
```

```ts
// src/content.config.ts
export { collections } from '@jaamd/jaab/content'
```

```json
// tsconfig.json
{
    "extends": "astro/tsconfigs/strict"
}
```

Only `title` is required. Every other option is in
[Options](https://docs.jaamd.org/jaab/configuration/options.md).

Write the first post with `npx jaab new "Hello"`, then run `npx astro dev`. See
[Posts](https://docs.jaamd.org/jaab/getting-started/posts.md).

## Existing Astro project

If `--here` reports custom `astro.config.*` or `src/content.config.*` files,
keep their existing configuration and merge JAAB manually.

Add the integration to the Astro configuration:

```ts
// astro.config.ts
import jaab from '@jaamd/jaab'
import { defineConfig } from 'astro/config'
import jaabConfig from './jaab.config'

export default defineConfig({
    site: jaabConfig.site,
    base: jaabConfig.base,
    integrations: [jaab(jaabConfig)],
})
```

`jaab()` returns integrations only. `site` and `base` are lifted above. Of the
[`astro`](https://docs.jaamd.org/jaad/configuration/astro.md) field, only
`astro.fonts` is read here, to load those fonts on JAAB's pages: write the
other options, and the same fonts, in `defineConfig`.

If the project defines content collections, add JAAB's collections without
replacing them:

```ts
// src/content.config.ts
import { collections as jaabCollections } from '@jaamd/jaab/content'
import { defineCollection } from 'astro:content'

const notes = defineCollection({/* existing loader and schema */})

export const collections = {
    notes,
    ...jaabCollections,
}
```

The collection names `blogPosts` and `blogIndex` are reserved for JAAB.

The blog's index takes its [`routeBase`](https://docs.jaamd.org/jaab/configuration/routebase.md),
`/` by default: a site with a home page of its own sets `routeBase: '/blog'`.
JAAB sets up JAAMD for the Markdown, so remove `jaamd()` from the
integrations if the project has it: see [Layout](https://docs.jaamd.org/jaab/guides/layout.md#jaamd).

Create `blog/`, add a post, then run the project with its existing development
script.

## Docs and a blog

A site with documentation and a blog installs JAAD and JAAB. They share the
header, the footer, the theme, the fonts and the `authors`, so they take the
same site options: `defineSiteConfig` holds them once, and each config spreads
them.

`site.config.ts` holds the shared options:

```ts
import { defineSiteConfig } from '@jaamd/jaab'

export default defineSiteConfig({
    title: 'My project',
    nav: [
        { label: 'Docs', href: '/' },
        { label: 'Blog', href: '/blog/' },
    ],
})
```

`astro.config.mjs` gives them to both, each with its own options after them:

```js
import jaab from '@jaamd/jaab'
import jaad from '@jaamd/jaad'
import { defineConfig } from 'astro/config'
import site from './site.config.ts'

export default defineConfig({
    site: 'https://example.dev',
    integrations: [jaad({ ...site, routeBase: '/' }), jaab({ ...site, routeBase: '/blog' })],
})
```

`src/content.config.ts` declares the docs and the posts:

```ts
import { collections as blog } from '@jaamd/jaab/content'
import { collections as docs } from '@jaamd/jaad/content'

export const collections = { ...docs, ...blog }
```

The build stops when the two set a site option differently, or when a page of
one would be served inside the other. Search stays on the docs; the feed is
linked from every page; `/llms.txt` has a section for each.
