# Recipe 14: move my site here

For an agent moving an author's existing website (Wix, Squarespace, WordPress, Weebly, GoDaddy,
Carrd, Linktree, a page on BookBub or Amazon, anything) to Beautiful (beautiful.site), rebuilt as
recipe 1's author site, with every old link still working. It's the author-specific layer on top of
Beautiful's migration skill (https://beautiful.site/skill/migrate/SKILL.md), which does the crawl,
the images, the redirects and the check. Read both, and https://beautiful.site/llms.txt, first.

An author's old links matter more than most sites': they're printed in the back of every ebook and
paperback, in Amazon and BookBub profiles, in years of newsletters. A link that breaks in a book's
back matter breaks for good. This recipe keeps every one.

## 1. What the author gets

- Their site on Beautiful, as recipe 1 builds it: a page per book with buy buttons for every store,
  the series in order, about, the newsletter, in a design made for their genre (or their old look,
  if they'd rather).
- Every old address still working: each old page answers at its old address or sends readers (and
  search engines, with a permanent 301) to the new one, including the links printed in their books.
- Their words, covers and photos, moved as they were; their buy links with their affiliate tags.
- Their newsletter list where it belongs: in their newsletter service, never on Beautiful.
- A report: how many old addresses were checked, and that all of them work.
- Their domain moved last, once they've seen the new site and every check passes, without touching
  their email.

## 2. Before you start

- **A shell with Node 18 or later**, for the migration skill's script. Without one (Claude.ai,
  ChatGPT), follow https://beautiful.site/skill/migrate/no-shell.md, then this recipe's book pages.
- **A Beautiful account** for the author, or plan to claim the site in the first hour: a move takes
  longer than a temporary site lasts. Ask in your first message.
- **Their old site stays up** until the very end. Nothing here deletes, cancels or changes it.
- **Public pages only** (the skill's rules): never sign in to their old builder, never copy a
  members area, stop at a bot check and ask for the builder's export.
- **Time**: one long message to the author at the start; one to review. For a 20-page author site,
  about two hours of yours.

## 3. Talk to the author

Ask in one message:

> Let's move your site here, keeping every old link working. A few questions:
>
> 1. Your site's address, and that it's yours to move (the words and photos on it are yours).
>    Your builder's terms may say something about copying your site; that's between you and
>    them.
> 2. Do you have a Beautiful account? If not, sign up at sites.beautiful.tech: a site without one
>    lasts an hour, and this takes longer.
> 3. Keep the look you have, or a fresh design made for your genre? (Recipe 1's directions, if
>    fresh. I'll send three.)
> 4. Which links are printed in your books' back matter, or in your Amazon and BookBub profiles?
>    ("yoursite.com/newsletter", "yoursite.com/free".) Those must never break.
> 5. Where does your newsletter list live: MailerLite, Kit, Mailchimp, or inside your current
>    builder (Wix or Squarespace contacts, WordPress plugin)?
> 6. Do you sell anything on the old site (a store, Payhip, BookFunnel)?
> 7. Anything you don't want moved (old pages, an old pen name)?
> 8. Where is your domain registered (GoDaddy, Namecheap, Squarespace, Wix…)? Do you get email at
>    it? (We'll leave your email exactly as it is.)

| Question | Why | Default |
| --- | --- | --- |
| Address, theirs | The crawl | Ask: never move a site the author doesn't say is theirs |
| Account | The site lasts past an hour | Publish the homepage first and give the claim link at once (the skill's step 3) |
| Look | Recipe 1's design step | A fresh direction; show three |
| Back-matter links | Checked one by one at the end | Every old page's address is kept anyway; these get a manual check too |
| Newsletter | Section 4 | The form goes to their service (recipe 4), or its embed |
| Store | Recipe 6 or 7 | Keep their store links as they are |
| Not moved | `"-"` in the URL map | Move everything public |
| Registrar, email | The domain move | Ask before the move; never touch MX records |

## 4. Pick the services

What moves from where:

| From | Pages and images | Newsletter list | Watch for |
| --- | --- | --- | --- |
| Wix | The crawl (the skill knows Wix) | Wix contacts: the author exports a CSV (Contacts, More actions, Export) and imports it into their newsletter service | Book pages often built as one long page; a "Books" page with many books is a list, not a book |
| Squarespace | The crawl, or Settings, Export (WordPress format) | Email Campaigns: the author exports the mailing list CSV | Squarespace Commerce products: recreate in Payhip (recipe 6) |
| WordPress | The crawl, plus its own API (the skill reads it) | A plugin (MailPoet, Newsletter): export CSV | Posts at `/2023/05/slug/` keep that address |
| Carrd, Linktree, a single page | The crawl (one page) | Usually already in their service | Few pages: build recipe 1 fresh from the links |
| Only Amazon or BookBub | Nothing to crawl | Their service | Not a move: do recipe 1, and keep their links |

**The list never comes to Beautiful.** Beautiful doesn't send newsletters. The author imports the
CSV into MailerLite, Kit or Mailchimp themselves (each has an Import button), and you connect the
form (recipe 4). Never upload, store or handle a subscriber list yourself.

**Universal book links** (geni.us, mybook.to, Booklinker) on the old buttons: they send readers
to their own country's Amazon and count clicks. Recipe 3 does the first with the ASIN and the
author's Associates tags, but the click counts stop. Tell the author so. If the counts matter to
them, keep using the universal link in their newsletters and back matter (it still works), and
let the site's Amazon button use the ASIN. Find the ASIN by opening the link (`curl -sI`: the
`location` has `/dp/<ASIN>`).

## 5. How it works

```
move/                            the work folder, on your machine
  bty-migrate.mjs                the migration skill's script
  migration/                     its output: inventory, pages, images, url-map.json, report.md
  books.mjs                      this recipe's helper: a draft book file per old book page
  drafts/books/<id>.md           the drafts, for you to read and finish
  drafts/url-map.json            each old book page's address, to its new /books/<id>/
  drafts/notes.md                what it couldn't place: links without an ASIN, other stores, tags
  site/                          the new site: recipe 1's files, then the books, about, posts
```

The skill crawls, captures each page (title, text, Markdown, images, buy links) and later checks
every old address on the new site. This recipe adds the author part: the old book pages become
recipe 1 books (entries at `src/content/books/<id>.md`), their old addresses go into the URL map so the
skill writes a 301 for each, the old buy links become `stores` (with the Amazon ASIN and the
author's affiliate tags), and the rest of the site (about, newsletter, events, media) is rebuilt
with the recipe that matches.

## 6. Build it

1. **Crawl and capture** with the skill: its steps 1, 2 and 4 (`inventory`, `capture`, `images`)
   in `move/`. Tell the author how many pages and posts you found.
2. **Start the new site**: recipe 1's files into `move/site/` (its extraction one-liner, with
   `site` as the folder). Fill `src/data/site.json` from the old site: the author's name, menu,
   contact, social links (the capture's `social`), and the bios from the old about page, word for
   word. Then publish the homepage at once (the skill's step 3) and give the author the link.
3. **Draft the books**: save `books.mjs` (below) in `move/` and run `node books.mjs`. Read
   `drafts/notes.md` first, then each draft against its old page:
   - the title and blurb as on the old page (the blurb is the page's Markdown less its headings,
     images and buy links: trim anything that isn't the blurb);
   - `release`: the script can't know it. Ask the author, or read it from the old page;
   - `series` and `number`, `status`, `formats`, `praise` (only quotes the old page shows, with who
     said them);
   - the cover: the first content image; check it's the cover, not a photo.
   A draft of a page that isn't one book's (a home page, a list of books, a series): delete it,
   and its line in `drafts/url-map.json`, which would otherwise redirect that page away.
   Then move the drafts into `site/src/content/books/` and the series into
   `site/src/data/series.json`. The books are entries of the site's CMS, not files: once the site
   (with recipe 1's `src/content.config.ts`) is published, write them with
   `BTY_TOKEN=<the API key> node bty-migrate.mjs entries --site site --to <slug>` (the skill's
   step 5), which saves each and puts them live together.
4. **Buy links and tags.** The drafts' `stores` come from the old buttons. If `notes.md` lists
   Amazon tags (`tag=…-20`), do recipe 3 and put them in `src/data/stores.json`'s `amazonTags`:
   the author's affiliate income depends on it. A link the script couldn't place: open it, and put
   it under its store, or ask. A `bookshopUK` link, and Libby, Spotify or Chirp links, need recipe
   3's stores: do recipe 3, or recipe 1's schema drops them without a word.
5. **The other pages**, with their recipes: the newsletter page or form (recipe 4, or the embed
   they had), a free book page (recipe 5), events (11), a media kit or press page (10), a shop
   (6, 7). Blog posts: the skill's `posts` command. A page that fits no recipe: rebuild it as a
   plain page at the same address, in the site's layout.
6. **The URL map.** Merge `drafts/url-map.json` into `migration/url-map.json`, and add the rest:
   the old books page to `/books/`, the old about to `/about/` (if it was `/about-me`), old
   series pages to `/series/<id>/`, and `"-"` for pages the author doesn't want moved. Every
   back-matter link from question 4 must be in the inventory or the map. Then run the skill's
   `redirects --site site`.
7. **Publish and check**: the skill's step 7 (`verify`), and fix until no old address is broken
   and no page lost content. Then each back-matter link by hand: `curl -sI <new site>/<path>` is
   200, or a 301 to the right page.
8. **The design**: recipe 1's "Design it" (or match the old look, the skill's
   `references/design.md`). Publish, and send the author the site and the report.
9. **The domain**, last, once the site is paid for and the author is happy: the skill's
   `references/seo-and-cutover.md`. Never change MX records. After the move, ask the author to
   keep the old plan for a week, then update the website link in their Amazon Author Central,
   BookBub, Goodreads and social profiles if it changed.

### books.mjs

Run in `move/` after `capture` and `images`. It reads the captured pages, never the old site.

```js
// Draft a recipe 1 book file for each old page that sells one book (recipe 14). Writes
// drafts/books/<id>.md, drafts/url-map.json and drafts/notes.md. Read every draft before using it.
import fs from "node:fs";

const dir = "migration/pages";
const pages = fs.readdirSync(dir).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs.readFileSync(`${dir}/${f}`, "utf8")));
const images = fs.existsSync("migration/images.json") ? JSON.parse(fs.readFileSync("migration/images.json", "utf8")) : [];
const sitePath = (original) => images.find((i) => i.original === original || i.copies?.includes(original))?.path.replace(/^public/, "");

// The capture's retailer names to recipe 1 and 3's store keys.
const KEY = { "apple-books": "apple", kobo: "kobo", "barnes-noble": "bn", "google-play": "google", audible: "audible", bookshop: "bookshop", books2read: "books2read", waterstones: "waterstones", "libro-fm": "libro", chirp: "chirp" };
const asinOf = (href) => /\/(?:dp|gp\/product|d|e)\/([A-Z0-9]{10})(?:[/?#]|$)/i.exec(href)?.[1]?.toUpperCase();
const slug = (s) => s.toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g, "").replace(/&/g, " and ").replace(/['’]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
const q = (s) => JSON.stringify(s); // a YAML string that's safe whatever is in it

fs.mkdirSync("drafts/books", { recursive: true });
const map = {};
const notes = [];
const tags = {};
let drafted = 0;

for (const p of pages) {
  const buy = p.retail ?? [];
  if (!buy.length || p.kind === "post" || p.status !== 200) continue;
  if (p.path === "/" || /^\/(?:books|series|shop|store)\/?$/.test(p.path)) {
    notes.push(`- ${p.path}: sells books, but it's the home page or a books page, not one book's page. Not drafted.`);
    continue;
  }
  const asins = [...new Set(buy.filter((r) => r.retailer === "amazon").map((r) => asinOf(r.href)).filter(Boolean))];
  if (asins.length > 1) {
    notes.push(`- ${p.path}: links to ${asins.length} different Amazon books, so it's a list page (books, series or home). Not drafted.`);
    continue;
  }
  const title = (p.h1?.[0] ?? p.title ?? "").trim();
  if (!title) {
    notes.push(`- ${p.path}: sells a book but has no heading or title. Not drafted.`);
    continue;
  }
  const id = slug(title);
  const stores = {};
  for (const r of buy) {
    if (r.retailer === "amazon") {
      const asin = asinOf(r.href);
      const url = new URL(r.href);
      const tag = url.searchParams.get("tag");
      if (tag) (tags[url.hostname.replace(/^www\./, "")] ??= new Set()).add(tag);
      if (asin) stores.amazon ??= asin;
      else notes.push(`- ${p.path}: an Amazon link without an ASIN (a short link?): ${r.href}. Open it (curl -sI) and take the 10 characters after /dp/.`);
    } else if (r.retailer === "universal-book-link") {
      notes.push(`- ${p.path}: a universal book link, ${r.href}. Open it (curl -sI) for the ASIN, and see "Universal book links" in the recipe.`);
    } else if (KEY[r.retailer] && new URL(r.href).pathname.replace(/\/+$/, "") === "") {
      // A button to the store's home page, not the book's: no use to a reader.
      notes.push(`- ${p.path}: the ${r.retailer} button goes to the store's home page (${r.href}), not this book's. Ask the author for the book's own link.`);
    } else if (KEY[r.retailer]) {
      // uk.bookshop.org is its own store (recipe 3's bookshopUK), not bookshop.org's US one.
      const uk = r.retailer === "bookshop" && new URL(r.href).hostname === "uk.bookshop.org";
      stores[uk ? "bookshopUK" : KEY[r.retailer]] ??= r.href;
    } else {
      notes.push(`- ${p.path}: a ${r.retailer} link the book file has no place for: ${r.href}`);
    }
  }
  const cover = sitePath(p.images?.find((i) => i.where === "content")?.original ?? p.og_image ?? "") ?? "";
  if (!cover) notes.push(`- ${p.path}: no cover found among its images. Ask the author for it.`);
  const hrefs = buy.map((r) => r.href);
  const blurb = (p.markdown ?? "")
    .split("\n")
    .filter((l) => !/^#{1,6} /.test(l) && !/^!\[/.test(l) && !hrefs.some((h) => l.includes(h)))
    .join("\n")
    .replace(/\n{3,}/g, "\n\n")
    .trim();
  const front = [
    "---",
    `title: ${q(title)}`,
    `cover: ${q(cover)}`,
    "# release: the date it came out, YYYY-MM-DD (ask the author, or read it from the old page)",
    "# series: a series id, and number: its place in the reading order, if it's in one",
    "stores:",
    ...Object.entries(stores).map(([k, v]) => `  ${k}: ${q(v)}`),
    `# Drafted from ${p.path} on the old site. Read it against the old page.`,
    "---",
  ];
  fs.writeFileSync(`drafts/books/${id}.md`, `${front.join("\n")}\n${blurb}\n`);
  drafted++;
  if (p.path !== `/books/${id}/`) map[p.path] = `/books/${id}/`;
}

if (Object.keys(tags).length) {
  notes.unshift(`- Amazon tags on the old buttons (put them in src/data/stores.json, recipe 3): ${Object.entries(tags).map(([host, t]) => `${host}: ${[...t].join(", ")}`).join("; ")}`);
}
fs.writeFileSync("drafts/url-map.json", `${JSON.stringify(map, null, 2)}\n`);
fs.writeFileSync("drafts/notes.md", `# Notes from books.mjs\n\n${notes.join("\n") || "Nothing to note."}\n`);
console.log(`Drafted ${drafted} book files in drafts/books/, ${notes.length} notes in drafts/notes.md.`);
```

Every draft fails to build until you add its `release` (it's required), so none goes live
unread.

## 7. Test it

1. The skill's `verify`: `migration/report.md` says every old address works (a page, or a 301 to
   the right one) and no page lost content. Its "buy links" line will list the Amazon buttons
   (they're now `/dp/<ASIN>` links the page points at the reader's store): check the tag is in
   `amazonTags` for each country the old links had.
2. Each back-matter link from question 4, by hand: `curl -sI https://<site>/<path>`.
3. Each book page against its old page: the title, the blurb word for word, the cover, a button
   for every store the old page had.
4. The newsletter form sends a test signup to the author's list (recipe 4's test), or the embed
   shows.
5. `screenshot` the home page, a book page and about, at desktop and phone width.
6. After the domain move: `verify` again against the domain, and the author's email still
   arrives (ask them to send themselves one).

## 8. Hand it over

> Your new site is at [url] ([claimed/needs claiming: link]). I checked all [n] addresses from
> your old site: every one opens the right page on the new one, including the links in your books'
> back matter ([list]).
>
> What I changed: [the design / kept your look], [fonts or stock photos replaced], [anything
> merged or dropped as you asked]. Your buy buttons keep your Amazon tags.
>
> Still to do, when you're ready: [import your list CSV into [service]], subscribe the site at
> [upgrade_url], then I'll move your domain. Your email stays exactly as it is. Keep your old plan
> until the domain serves the new site and I've checked it again.

## 9. Keep it running

- **A month after the domain move**: the skill's verify against the domain once more, and the
  author's search console (if they had one) for 404s.
- **An old link someone finds broken.** Add it to `public/_redirects` (above the skill's marker
  lines) to the right page, publish, and check it.
- **The old plan.** Tell the author when it's safe to cancel: the domain serves the new site,
  verify passed on it, and their email works.
- From here on, the author's site is recipe 1's: every other recipe applies.

## 10. When it goes wrong

| What you see | Why | Fix |
| --- | --- | --- |
| The crawl stops: "bot check" (exit code 2) | The builder blocks crawlers | Ask for the builder's export (the skill's `references/platforms.md`) |
| A book page wasn't drafted | It links to more than one Amazon book, has no heading, or is at `/`, `/books/`, `/series/`, `/shop/` or `/store/` | Draft it by hand from its capture (`migration/pages/<key>.json`) |
| A list page was drafted as a book | Its buttons don't name two Amazon books (no Amazon, or one book's buttons on a series page) | Delete the draft and its line in `drafts/url-map.json` |
| A draft's blurb includes "Also by…" or the newsletter pitch | The old page had them in its content | Trim the draft to the blurb |
| `template_error` on `release` | A draft without its date | Add `release: YYYY-MM-DD` |
| The publish fails: `Fetching <image URL> failed with HTTP 404` | The old site pointed at an image that's gone (often a placeholder `og:image`) | Remove that entry from `migration/images.json` and the image-files list, and publish again |
| The new site has no fonts | Recipe 1's `fonts.json` isn't in the skill's publish | Send `fonts.json`'s files in a changeset of their own, then deploy |
| verify: a back-matter link is broken | Not in the inventory or the map | Add it to `migration/url-map.json`, run `redirects` again, publish |
| verify: "lost buy links" for Amazon | The new buttons use `/dp/<ASIN>`, not the old long links | Expected; check the tags are in `amazonTags` |
| The author's email stopped after the domain move | MX records changed | Put back the MX records from before (the cutover guide says to note them first) |
