@@ -261,6 +261,34 @@ export async function handleLlmsTxt(
261261 return generateLlmsTxt ( result )
262262}
263263
264+ /**
265+ * Fetch raw README markdown for a package.
266+ * Returns only the README content with no metadata wrapper.
267+ */
268+ export async function handlePackageMd (
269+ packageName : string ,
270+ requestedVersion ?: string ,
271+ ) : Promise < string > {
272+ const packageData = await fetchNpmPackage ( packageName )
273+ const resolvedVersion = requestedVersion ?? packageData [ 'dist-tags' ] ?. latest
274+
275+ if ( ! resolvedVersion ) {
276+ throw createError ( { statusCode : 404 , message : 'Could not resolve package version.' } )
277+ }
278+
279+ const readmeFromPackument = getReadmeFromPackument ( packageData , requestedVersion )
280+ const readme = readmeFromPackument ?? ( await fetchReadmeFromCdn ( packageName , resolvedVersion ) )
281+
282+ if ( ! readme ) {
283+ throw createError ( {
284+ statusCode : 404 ,
285+ message : `No README found for ${ packageName } @${ resolvedVersion } .` ,
286+ } )
287+ }
288+
289+ return readme
290+ }
291+
264292// Validation for org names (matches server/api/registry/org/[org]/packages.get.ts)
265293const NPM_ORG_NAME_RE = / ^ [ a - z 0 - 9 ] (?: [ a - z 0 - 9 - ] * [ a - z 0 - 9 ] ) ? $ / i
266294
@@ -354,12 +382,24 @@ export function generateRootLlmsTxt(baseUrl: string): string {
354382 lines . push ( '' )
355383 lines . push ( `- \`${ baseUrl } /package/@<org>/llms.txt\` — organization package listing` )
356384 lines . push ( '' )
385+ lines . push ( '### Raw README Markdown (.md)' )
386+ lines . push ( '' )
387+ lines . push ( 'Raw README content for a package, with no metadata wrapper.' )
388+ lines . push ( '' )
389+ lines . push ( `- \`${ baseUrl } /package/<name>.md\` — unscoped package (latest version)` )
390+ lines . push ( `- \`${ baseUrl } /package/<name>/v/<version>.md\` — unscoped package (specific version)` )
391+ lines . push ( `- \`${ baseUrl } /package/@<org>/<name>.md\` — scoped package (latest version)` )
392+ lines . push (
393+ `- \`${ baseUrl } /package/@<org>/<name>/v/<version>.md\` — scoped package (specific version)` ,
394+ )
395+ lines . push ( '' )
357396 lines . push ( '## Examples' )
358397 lines . push ( '' )
359398 lines . push ( `- [nuxt llms.txt](${ baseUrl } /package/nuxt/llms.txt)` )
360399 lines . push ( `- [nuxt llms_full.txt](${ baseUrl } /package/nuxt/llms_full.txt)` )
361400 lines . push ( `- [@nuxt/kit llms.txt](${ baseUrl } /package/@nuxt/kit/llms.txt)` )
362401 lines . push ( `- [@nuxt org packages](${ baseUrl } /package/@nuxt/llms.txt)` )
402+ lines . push ( `- [nuxt README](${ baseUrl } /package/nuxt.md)` )
363403 lines . push ( '' )
364404
365405 return lines . join ( '\n' ) . trimEnd ( ) + '\n'
0 commit comments