Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions packages/node-legacy/src/legacy-json-all/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { writeFile } from 'node:fs/promises';
import { join } from 'node:path';

import getConfig from '@doc-kit/core/utils/configuration/index.mjs';
import { populate } from '@doc-kit/core/utils/configuration/templates.mjs';

import { legacyToJSON } from '../utils/legacyToJSON.mjs';

Expand Down Expand Up @@ -36,8 +37,10 @@ export async function generate(input) {

// Create a map of api name to index position for sorting
const indexOrder = new Map(
config.index?.map(({ api }, position) => [`doc/api/${api}.md`, position]) ??
[]
config.index?.map(({ api }, position) => [
populate(config.sourceURL, { path: `${api}.md` }),
position,
]) ?? []
);

// Sort input by index order (documents not in index go to the end)
Expand Down
1 change: 1 addition & 0 deletions packages/node-legacy/src/legacy-json-all/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default {

defaultConfiguration: {
minify: false,
sourceURL: 'doc/api/{path}',
},

generate,
Expand Down
2 changes: 1 addition & 1 deletion packages/node-legacy/src/legacy-json-all/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export interface Output {
}

export type Generator = GeneratorMetadata<
{},
{ sourceURL: string },
Generate<Array<Section>, Promise<Output>>
>;
4 changes: 3 additions & 1 deletion packages/node-legacy/src/legacy-json/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ const buildSection = createSectionBuilder();
*/
export async function processChunk(slicedInput, itemIndices) {
const results = [];
const config = getConfig('legacy-json');
const sourceURL = config.sourceURL;

for (const idx of itemIndices) {
const { head, nodes } = slicedInput[idx];

results.push(buildSection(head, nodes));
results.push(buildSection(head, nodes, sourceURL));
}

return results;
Expand Down
1 change: 1 addition & 0 deletions packages/node-legacy/src/legacy-json/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default {
defaultConfiguration: {
ref: 'main',
minify: false,
sourceURL: 'doc/api/{path}',
},

hasParallelProcessor: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/node-legacy/src/legacy-json/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export interface MiscSection extends SectionBase {
}

export type Generator = GeneratorMetadata<
{},
{ sourceURL: string },
Generate<Array<MetadataEntry>, AsyncGenerator<Section>>,
ProcessChunk<{ head: MetadataEntry; nodes: Array<MetadataEntry> }, Section>
>;
7 changes: 4 additions & 3 deletions packages/node-legacy/src/legacy-json/utils/buildSection.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { enforceArray } from '@doc-kit/core/utils/array.mjs';
import { populate } from '@doc-kit/core/utils/configuration/templates.mjs';
import { buildHierarchy } from '@doc-kit/core/utils/hierarchy.mjs';
import { getRemarkRehype as remark } from '@doc-kit/core/utils/remark.mjs';
import { parseList } from '@doc-kit/core/utils/signature/parseList.mjs';
Expand Down Expand Up @@ -183,14 +184,14 @@ export const createSectionBuilder = () => {
* Builds the module section from head metadata and entries.
* @param {import('@doc-kit/core/generators/metadata/types').MetadataEntry} head - The head metadata entry.
* @param {Array<import('@doc-kit/core/generators/metadata/types').MetadataEntry>} entries - The list of metadata entries.
* @param {string} sourceURL - The template URL for the generated API source files.
* @returns {import('../types.d.ts').ModuleSection} The constructed module section.
*/
return (head, entries) => {
return (head, entries, sourceURL) => {
const rootModule = {
type: 'module',
api: head.api,
// TODO(@avivkeller): This should be configurable
source: `doc/api/${head.api}.md`,
source: populate(sourceURL, { path: `${head.api}.md` }),
};

buildHierarchy(entries).forEach(node => handleEntry(node, rootModule));
Expand Down
Loading