Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/__tests__/metadata.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('createMetadata', () => {
heading,
n_api_version: undefined,
introduced_in: undefined,
llm_description: undefined,
llmDescription: undefined,
removed_in: undefined,
slug: 'test-heading',
source_link: 'test.com',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import { describe, it } from 'node:test';
import { getEntryDescription, buildApiDocLink } from '../buildApiDocLink.mjs';

describe('getEntryDescription', () => {
it('returns llm_description when available', () => {
it('returns llmDescription when available', () => {
const entry = {
llm_description: 'LLM generated description',
llmDescription: 'LLM generated description',
content: { children: [] },
};

const result = getEntryDescription(entry);
assert.equal(result, 'LLM generated description');
});

it('extracts first paragraph when no llm_description', () => {
it('extracts first paragraph when no llmDescription', () => {
const entry = {
content: {
children: [
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('buildApiDocLink', () => {
const entry = {
heading: { data: { name: 'Test API' } },
api_doc_source: 'doc/api/test.md',
llm_description: 'Test description',
llmDescription: 'Test description',
};

const result = buildApiDocLink(entry);
Expand Down
6 changes: 3 additions & 3 deletions src/generators/llms-txt/utils/buildApiDocLink.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { transformNodeToString } from '../../../utils/unist.mjs';

/**
* Retrieves the description of a given API doc entry. It first checks whether
* the entry has a llm_description property. If not, it extracts the first
* the entry has a llmDescription property. If not, it extracts the first
* paragraph from the entry's content.
*
* @param {ApiDocMetadataEntry} entry
* @returns {string}
*/
export const getEntryDescription = entry => {
if (entry.llm_description) {
return entry.llm_description;
if (entry.llmDescription) {
return entry.llmDescription.trim();
}

const descriptionNode = entry.content.children.find(
Expand Down
4 changes: 2 additions & 2 deletions src/linter/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

export const INTRODUCED_IN_REGEX = /<!--\s?introduced_in=.*-->/;

export const LLM_DESCRIPTION_REGEX = /<!--\s?llm_description=.*-->/;
export const LLM_DESCRIPTION_REGEX = /<!--\s?llmDescription:.*-->/;

export const LINT_MESSAGES = {
missingIntroducedIn: "Missing 'introduced_in' field in the API doc entry",
Expand All @@ -11,5 +11,5 @@ export const LINT_MESSAGES = {
invalidChangeVersion: 'Invalid version number: {{version}}',
duplicateStabilityNode: 'Duplicate stability node',
missingLlmDescription:
'Missing llm_description field or paragraph node in the API doc entry',
'Missing llmDescription field or paragraph node in the API doc entry',
};
10 changes: 5 additions & 5 deletions src/linter/rules/__tests__/missing-metadata.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ describe('missingMetadata', () => {
it('should not report when both fields are present', () => {
const context = createContext([
{ type: 'html', value: '<!--introduced_in=12.0.0-->' },
{ type: 'html', value: '<!--llm_description=desc-->' },
{ type: 'html', value: '<!--llmDescription:desc-->' },
]);

missingMetadata(context);
strictEqual(context.report.mock.callCount(), 0);
});

it('should report only llm_description when introduced_in is present', () => {
it('should report only llmDescription when introduced_in is present', () => {
const context = createContext([
{ type: 'html', value: '<!--introduced_in=12.0.0-->' },
]);
Expand All @@ -25,7 +25,7 @@ describe('missingMetadata', () => {
strictEqual(context.report.mock.calls[0].arguments[0].level, 'warn');
});

it('should not report llm_description when paragraph fallback exists', () => {
it('should not report llmDescription when paragraph fallback exists', () => {
const context = createContext([
{ type: 'html', value: '<!--introduced_in=12.0.0-->' },
{ type: 'paragraph', children: [{ type: 'text', value: 'desc' }] },
Expand All @@ -42,9 +42,9 @@ describe('missingMetadata', () => {
strictEqual(context.report.mock.callCount(), 2);
});

it('should report only introduced_in when llm_description is present', () => {
it('should report only introduced_in when llmDescription is present', () => {
const context = createContext([
{ type: 'html', value: '<!--llm_description=desc-->' },
{ type: 'html', value: '<!--llmDescription:desc-->' },
]);

missingMetadata(context);
Expand Down
4 changes: 2 additions & 2 deletions src/metadata.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const createMetadata = slugger => {
updates = [],
changes = [],
tags = [],
llm_description,
llmDescription,
} = internalMetadata.properties;

// Also add the slug to the heading data as it is used to build the heading
Expand All @@ -140,7 +140,7 @@ const createMetadata = slugger => {
content: section,
tags,
introduced_in,
llm_description,
llmDescription,
yaml_position: internalMetadata.yaml_position,
};
},
Expand Down
4 changes: 2 additions & 2 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ declare global {
introduced_in?: string;
napiVersion?: number;
tags?: Array<string>;
llm_description?: string;
llmDescription?: string;
}

export interface ApiDocMetadataEntry {
Expand Down Expand Up @@ -101,7 +101,7 @@ declare global {
// to provide additional metadata about the API doc entry
tags: Array<string>;
// The llms.txt specific description
llm_description: string | undefined;
llmDescription: string | undefined;
// The postion of the YAML of the API doc entry
yaml_position: Position;
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/parser/__tests__/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('normalizeYamlSyntax', () => {
source_link=lib/test.js
type=module
name=test_module
llm_description=This is a test module`;
llmDescription: This is a test module`;

const normalizedYaml = normalizeYamlSyntax(input);

Expand All @@ -40,7 +40,7 @@ llm_description=This is a test module`;
source_link: lib/test.js
type: module
name: test_module
llm_description: This is a test module`
llmDescription: This is a test module`
);
});

Expand Down
1 change: 0 additions & 1 deletion src/utils/parser/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const normalizeYamlSyntax = yamlContent => {
.replace('source_link=', 'source_link: ')
.replace('type=', 'type: ')
.replace('name=', 'name: ')
.replace('llm_description=', 'llm_description: ')
.replace(/^[\r\n]+|[\r\n]+$/g, ''); // Remove initial and final line breaks
};

Expand Down
10 changes: 8 additions & 2 deletions src/utils/unist.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ export const transformNodeToString = node => {
return `**${transformNodesToString(node.children)}**`;
case 'emphasis':
return `_${transformNodesToString(node.children)}_`;
default:
return node.children ? transformNodesToString(node.children) : node.value;
default: {
if (node.children) {
return transformNodesToString(node.children);
}

// Replace line breaks (\n) with spaces to keep text in a single line
return node.value?.replace(/\n/g, ' ') || '';
}
}
};

Expand Down
Loading