Skip to content

Conversation

matthewp
Copy link
Contributor

Changes

  • Add experimental LLM config flag to enable/disable optimization
  • Integrate optimization into render-context for both dev and prod
  • Add LLM optimization function using Turndown for HTML-to-Markdown conversion

Testing

  • Ads fixture tests for dev and production builds

Docs

tbd

Add new integration that optimizes Astro sites for consumption by Large Language Models.

Features:
- Converts HTML responses to markdown when Accept: text/markdown header is present
- Uses Turndown to strip unnecessary elements (nav, footer, scripts)
- Outputs clean markdown with ATX-style headings and fenced code blocks
- Includes comprehensive tests for markdown conversion functionality
…feature

Move the LLM optimization functionality from @astrojs/llm integration into Astro core as an experimental feature. When `experimental.llm.optimizePageResponse` is enabled, pages automatically convert to Markdown format when clients send an `Accept: text/markdown` header.

This enables better integration with LLM tools and applications that work better with structured Markdown content instead of HTML.

- Add experimental LLM config flag to enable/disable optimization
- Integrate optimization into render-context for both dev and prod
- Add LLM optimization function using Turndown for HTML-to-Markdown conversion
- Add comprehensive fixture tests for dev and production builds
- Remove @astrojs/llm integration package
Copy link

changeset-bot bot commented Oct 17, 2025

🦋 Changeset detected

Latest commit: c170c71

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) docs pr labels Oct 17, 2025
Copy link

codspeed-hq bot commented Oct 17, 2025

CodSpeed Performance Report

Merging #14571 will not alter performance

Comparing llm-integration (c170c71) with main (73c5de9)

Summary

✅ 6 untouched

@ascorbic
Copy link
Contributor

I think this is useful, but I don't think this is the right approach. I think it would be better as an integration. Also, as I understand it, this won't work with prerendered pages, which means all Starlight sites, which I'd imagine is the most common use case for it. I think the approach that Netlify takes is better: they render a .md version of all pages, and then use edge middleware to rewrite requests.

We talked about this feature, but specifically about Starlight. For that it might make sense to have it in core, as well as the "copy as markdown" button which it could work alongside.

As a side issue, I don't think the naming makes sense. It should be about rendering markdown versions, not about LLMs.

@matthewp
Copy link
Contributor Author

matthewp commented Oct 17, 2025

@ascorbic Yeah this is just an early prototype, hence being in draft. I plan on creating an RFC for this. What I actually want to do is deeper than just converting HTML to markdown, but rather a way to directly link pages to the content collection (and entry) it covers so we can directly serve that and not need to do the lossy reverse compilation.

Something like this:

---
export const collection = "blog";
export const entry = "[slug]";

const entry = Astro.collectionEntry; // don't need to call getEntry 
---

And yeah static builds are a must, that probably involves having astro produce .md files as build time and giving adapters a way to configure this all. Will work on the RFC this weekend so we can discuss.

@ematipico
Copy link
Member

I still think such features should be part of an integration.

Astro can enable the integration with new features, but I think the end result should be provided by an integration.

Looking forward to see the RFC

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

Labels

docs pr pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants