Skip to content

LiveSearch + RecentPosts widget hardcode /posts/{slug} URL — no way to customize for catch-all routing #1332

Description

@rodsom

Description

Both LiveSearch (the live search dropdown, exported from emdash/ui/search) and the RecentPosts widget construct result links by hardcoding the collection name into the path /${collection}/${slug} and /posts/${post.id} respectively.

Sites using a catch-all route like src/pages/[...slug].astro (so URLs are /{slug} without the /posts/ segment the common SEO pattern for content sites and news publishers) have no way to override this.

The <slot name="result"> in LiveSearch doesn't help because the JS overwrites link.href on every cloned template after the slot renders.

Proposed fix: add an optional urlBuilder?: (entry) => string prop to both components, defaulting to the current /${collection}/${slug} behaviour so existing sites are unaffected. For LiveSearch (client-side), the builder could be serialised via the existing data-config JSON, or accept a template string like "/${slug}" if a function attribute is too costly.

Steps to reproduce

  1. Scaffold a site with pnpm create emdash@latest my-site --template cloudflare:blog
    1. Replace src/pages/posts/[slug].astro and src/pages/pages/[slug].astro with a single catch-all src/pages/[...slug].astro that resolves the slug across both posts and pages collections
  2. Update internal href references throughout src/ from /posts/${id} to /${id} (e.g. in index.astro, posts/index.astro, category/[slug].astro, tag/[slug].astro, search.astro, rss.xml.ts)
  3. Deploy. Direct navigation to /{slug} works correctly content renders via the catch-all
  4. On any page rendering <LiveSearch />, type a query, click any dropdown result -> browser navigates to /posts/{slug} and hits /404 because that path no longer exists
  5. Same outcome if a widget area renders RecentPosts its links also point to /posts/{slug}

Environment

emdash version: 0.16.1
@emdash-cms/cloudflare version: 0.16.1
Astro version: 6.4.3
Node.js version: 22.x (via pnpm 11)
Runtime: Cloudflare Workers
OS: Windows 11

Logs / error output

Expected: dropdown result link href = `/${slug}`
Actual:   dropdown result link href = `/${collection}/${slug}` → 404 on catch-all sites

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions