# Area guide hub

Source: https://help.ruuster.com/idx/recipe-area-guide-hub

> A /neighborhoods hub that links every area page with today's count of homes for sale, plus the sitemap and llms.txt files that list your area pages.

A hub page at `/neighborhoods` with a link to every [area page](https://help.ruuster.com/idx/recipe-neighborhood-page)
and today's count of homes for sale in each. It is the page that ties your area pages together for
visitors and crawlers. The same list of areas, `content/areas.ts`, also builds your `sitemap.xml`
and your `llms.txt`.

## What the visitor sees

A list of your areas, each linking to its page with its count of homes for sale, in your site's own
layout. Each area page then shows its listings:

<figure class="idx-shot"><img src="/idx-docs/screens/ours/listing-grid-1440.png" alt="Listing grid with the disclaimers under it, on a desktop (1440 px wide)" width="1440" height="900" loading="lazy" decoding="async"><figcaption>What each area link leads to.</figcaption></figure>

<figure class="idx-shot"><img src="/idx-docs/screens/ours/listing-grid-375.png" alt="Listing grid with the disclaimers under it, on a phone (375 px wide)" width="375" height="1403" loading="lazy" decoding="async"><figcaption>What each area link leads to.</figcaption></figure>

The markup is `static/html/listing-grid.html` in `@ruuster/idx-recipes`. The [HTML and CSS recipe](https://help.ruuster.com/idx/recipe-html-css) shows how to fill it and which stylesheet and script to load.

## What the page calls

| When | Request | Key | Cached |
|---|---|---|---|
| Once an hour | `GET /v1/listings` with each area's `where` row and `limit=1`, for the count | secret key, on your server | an hour by Next.js |

cURL:

```bash
curl -s -G "https://idx.ruuster.com/v1/listings" \
  --data-urlencode 'where={"label":"Atlanta, GA Midtown","value":"a0000000-0000-4000-8000-000000000001","source":"neighborhood","data":{"state":"GA"}}' \
  --data-urlencode status=active \
  --data-urlencode limit=1 \
  -H "Authorization: Bearer $IDX_SECRET_KEY"
```

TypeScript:

```typescript
import { createClient } from "@ruuster/idx";

const idx = createClient({ secretKey: process.env.IDX_SECRET_KEY });

const r = await idx.search({
  where: {
    label: "Atlanta, GA Midtown",
    value: "a0000000-0000-4000-8000-000000000001",
    source: "neighborhood",
    data: {
      state: "GA",
    },
  },
  status: "active",
  limit: 1,
});
if (!r.ok) throw new Error(`${r.error.code}: ${r.error.message}`);
console.log(r.data);
```

Python:

```python
import os

import requests

res = requests.get(
    "https://idx.ruuster.com/v1/listings",
    params={
        "where": "{\"label\":\"Atlanta, GA Midtown\",\"value\":\"a0000000-0000-4000-8000-000000000001\",\"source\":\"neighborhood\",\"data\":{\"state\":\"GA\"}}",
        "status": "active",
        "limit": "1",
    },
    headers={"Authorization": "Bearer " + os.environ["IDX_SECRET_KEY"]},
    timeout=30,
)
body = res.json()
if not body["ok"]:
    raise RuntimeError(body["error"]["code"] + ": " + body["error"]["message"])
print(body["data"])
```

PHP:

```php
<?php

$query = http_build_query([
    'where' => '{"label":"Atlanta, GA Midtown","value":"a0000000-0000-4000-8000-000000000001","source":"neighborhood","data":{"state":"GA"}}',
    'status' => 'active',
    'limit' => '1',
], '', '&', PHP_QUERY_RFC3986);
$ch = curl_init('https://idx.ruuster.com/v1/listings' . '?' . $query);
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('IDX_SECRET_KEY')],
    CURLOPT_TIMEOUT => 30,
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);
if (!$body['ok']) {
    throw new RuntimeException($body['error']['code'] . ': ' . $body['error']['message']);
}
print_r($body['data']);
```

## Steps

1. Build your [area pages](https://help.ruuster.com/idx/recipe-neighborhood-page) and their
   `content/areas.ts` first.
2. Create `app/neighborhoods/page.tsx`, `app/sitemap.ts` and `app/llms.txt/route.ts` with the code
   below.
3. Link to `/neighborhoods` from your header and footer.
4. Open `http://localhost:3000/neighborhoods`, `/sitemap.xml` and `/llms.txt`.

## The code

<p class="code-title"><code>app/neighborhoods/page.tsx</code></p>

```tsx
// /neighborhoods: the area guide hub. One link per area page, with today's count of homes for sale.
import Link from "next/link";
import { AREAS } from "@/content/areas";
import { idx } from "@/lib/idx";
import { SITE_NAME } from "@/lib/site";

export const revalidate = 3600;

export const metadata = {
  title: `Neighborhood guides · ${SITE_NAME}`,
  description: `Homes for sale, recent prices and local notes for every area ${SITE_NAME} serves.`,
  alternates: { canonical: "/neighborhoods" },
};

export default async function NeighborhoodsHub() {
  // limit=1: the hub needs only each area's total, not its cards.
  const counts = await Promise.all(AREAS.map((a) => idx.search({ where: a.where, status: "active", limit: 1 })));
  return (
    <main>
      <h1>Neighborhood guides</h1>
      <ul>
        {AREAS.map((a, i) => {
          const r = counts[i];
          return (
            <li key={a.slug}>
              <Link href={`/neighborhoods/${a.slug}`}>{a.name}</Link>
              {r.ok ? ` (${r.data.total === 1 ? "1 home" : `${r.data.total.toLocaleString("en-US")} homes`} for sale)` : null}
            </li>
          );
        })}
      </ul>
    </main>
  );
}
```

<p class="code-title"><code>app/sitemap.ts</code></p>

```ts
// /sitemap.xml: your own pages (home, the area hub, every area page and its sold page, the list pages).
// The listing pages are in /homes/sitemap/<n>.xml (app/homes/sitemap.ts).
import type { MetadataRoute } from "next";
import { AREAS } from "@/content/areas";
import { showsSoldData } from "@/lib/area-query";
import { getMeta } from "@/lib/idx";
import { absoluteUrl } from "@/lib/site";

export const revalidate = 3600;

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  const meta = await getMeta();
  const caps = meta.ok ? meta.data.capabilities : null;
  const pages: MetadataRoute.Sitemap = [
    { url: absoluteUrl("/"), changeFrequency: "daily" },
    { url: absoluteUrl("/neighborhoods"), changeFrequency: "weekly" },
    { url: absoluteUrl("/open-houses"), changeFrequency: "daily" },
    { url: absoluteUrl("/price-reduced"), changeFrequency: "daily" },
  ];
  // Your own listings page exists once Ruuster has your agents' and offices' MLS ids.
  if (caps?.ownListings === true) pages.push({ url: absoluteUrl("/our-listings"), changeFrequency: "daily" });
  // Add /new-construction here once that page shows listings on your boards.
  const sold = showsSoldData(caps);
  for (const a of AREAS) {
    pages.push({ url: absoluteUrl(`/neighborhoods/${a.slug}`), changeFrequency: "daily" });
    if (a.soldPage && sold) pages.push({ url: absoluteUrl(`/neighborhoods/${a.slug}/sold`), changeFrequency: "weekly" });
  }
  return pages;
}
```

<p class="code-title"><code>app/llms.txt/route.ts</code></p>

```ts
// /llms.txt: a short Markdown summary of your site for AI assistants, built from content/areas.ts.
// Your sitemaps and the HTML of each page do the real work; this file is a small extra.
import { AREAS } from "@/content/areas";
import { absoluteUrl, SITE_NAME } from "@/lib/site";

export const revalidate = 3600;

export function GET() {
  const lines = [
    `# ${SITE_NAME}`,
    "",
    `> ${SITE_NAME} is a real estate brokerage. This site lists the homes for sale in the areas below, with a page for every listing, recent market numbers for each area and our agents' own notes.`,
    "",
    "## Area pages",
    "",
    ...AREAS.map((a) => `- [Homes for sale in ${a.name}](${absoluteUrl(`/neighborhoods/${a.slug}`)}): listings, market numbers and our notes on ${a.name}.`),
    "",
    "## Listings",
    "",
    `- [Search homes for sale](${absoluteUrl("/search")})`,
    `- [Our listings](${absoluteUrl("/our-listings")})`,
    `- [Open houses this weekend](${absoluteUrl("/open-houses")})`,
    `- [Listing sitemap](${absoluteUrl("/homes/sitemap/0.xml")}): one URL per home for sale.`,
    "",
  ];
  return new Response(lines.join("\n"), { headers: { "Content-Type": "text/markdown; charset=utf-8" } });
}
```

## Forms and your CRM

The hub carries no forms ([Registration, tour and contact forms](https://help.ruuster.com/idx/recipe-forms)
covers where they go).

## Rules this page follows

**MUST**

- Link every area page with a plain `<a href>`, so crawlers find each one.
- List each sold page in the sitemap only while your boards show sold data (the file checks
  `capabilities.sold`).

**NEVER**

- Describe an area by who lives there ([Fair housing](https://help.ruuster.com/idx/fair-housing)).

## Test it

```sh
curl -s http://localhost:3000/sitemap.xml | grep -c "<loc>"
curl -s http://localhost:3000/llms.txt
```

The sitemap lists your pages and every area page. `llms.txt` answers Markdown with a link to each area
page.

## Build it with AI

```text
Read RUUSTER_IDX.md first and follow its MUST and NEVER rules. Ask me if it doesn't cover something.

Build neighborhood pages at /neighborhoods/[area] for this list of places: [your list]. Follow the recipe at <https://help.ruuster.com/idx/recipe-neighborhood-page>. For each place, call GET /v1/suggest once on the server with my secret key, show me the rows it answers so I can confirm the right one, and store that row's where object unchanged in content/areas.ts. Never build or edit a where object by hand. Each page opens with one sentence that answers what the market is like, using GET /v1/market numbers and the date. Then it shows the MarketStats tiles, answers three to five questions as <h2> headings with the answer in the first sentence, leaves a section for my agents' own words, and shows the listings, pagination, the map, the MLS disclaimers and the JSON-LD. Add the area pages to app/sitemap.ts and build an area hub at /neighborhoods.

Use these environment variables: IDX_SECRET_KEY (server only), SITE_ORIGIN and SITE_NAME. Never paste a secret key into a chat, and never put IDX_SECRET_KEY in browser code, a URL or a log. No key goes in any page: my pages call my own /api/idx route, made with createListingsRoute from @ruuster/idx/route, which adds my secret key on the server (on a site with no server, the widgets call the API with no key from my approved website address).

Fair housing: describe homes, places and amenities only. Never describe the people who live in an area or who a home or area suits, and never rank schools as a reason to buy. Do not copy listing remarks into the area copy, and write a marked placeholder for my agents' own section instead of inventing it.

When you are done, list the where rows you stored so I can check them.
```

On a site without React, such as PHP, Python, Ruby on Rails, Go or plain HTML, [Build without React: HTML, CSS and JavaScript](https://help.ruuster.com/idx/recipe-html-css) gives you the same markup, the stylesheet and the script for every widget.
