Skip to content

Commit 050a74e

Browse files
committed
fix item extraction, change site.items to be top level only
1 parent 50b275c commit 050a74e

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/site.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path';
22
import { ContractDefinition, SourceUnit } from 'solidity-ast';
33
import { SolcOutput, SolcInput } from 'solidity-ast/solc';
4-
import { astDereferencer, ASTDereferencer, findAll } from 'solidity-ast/utils';
4+
import { astDereferencer, ASTDereferencer, findAll, isNodeType } from 'solidity-ast/utils';
55
import { FullConfig } from './config';
66
import { DocItem, docItemTypes, isDocItem } from './doc-item';
77
import { Properties } from './templates';
@@ -55,7 +55,7 @@ export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: P
5555
const assign = typeof siteConfig.pages === 'string' ? pageAssigner[siteConfig.pages] : siteConfig.pages;
5656

5757
const seen = new Set<string>();
58-
const allItems: DocItemWithContext[] = [];
58+
const items: DocItemWithContext[] = [];
5959
const pages: Record<string, DocItemWithContext[]> = {};
6060

6161
for (let { input, output } of builds) {
@@ -66,8 +66,8 @@ export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: P
6666
const build = { input, output, deref };
6767

6868
for (const { ast: file } of Object.values(output.sources)) {
69-
const isNewItem = !seen.has(file.src);
70-
seen.add(file.src);
69+
const isNewFile = !seen.has(file.absolutePath);
70+
seen.add(file.absolutePath);
7171

7272
for (const topLevelItem of file.nodes) {
7373
if (!isDocItem(topLevelItem)) continue;
@@ -78,13 +78,18 @@ export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: P
7878
__item_context: { page, item: topLevelItem as DocItemWithContext, file, build },
7979
});
8080

81-
if (page !== undefined) {
81+
if (isNewFile && page !== undefined) {
8282
(pages[page] ??= []).push(withContext);
83+
items.push(withContext);
8384
}
8485

85-
for (const item of findAll(docItemTypes, topLevelItem)) {
86-
if (isNewItem) allItems.push(item as DocItemWithContext);
87-
if (item === topLevelItem) continue;
86+
if (!isNodeType('ContractDefinition', topLevelItem)) {
87+
continue;
88+
}
89+
90+
for (const item of topLevelItem.nodes) {
91+
if (!isDocItem(item)) continue;
92+
if (isNewFile && page !== undefined) items.push(item as DocItemWithContext);
8893
const contract = topLevelItem.nodeType === 'ContractDefinition' ? topLevelItem : undefined;
8994
const __item_context: DocItemContext = { page, item: item as DocItemWithContext, contract, file, build };
9095
Object.assign(item, { __item_context });
@@ -93,16 +98,16 @@ export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: P
9398
}
9499
}
95100

96-
for (const item of allItems) {
101+
for (const item of items) {
97102
for (const [prop, fn] of Object.entries(properties)) {
98103
const original: unknown = (item as any)[prop];
99104
defineGetterMemoized(item as any, prop, () => fn(item.__item_context, original));
100105
}
101106
}
102107

103108
return {
104-
items: allItems.filter(i => i[DOC_ITEM_CONTEXT].contract === undefined),
105-
pages: Object.entries(pages).map(([id, items]) => ({ id, items })),
109+
items,
110+
pages: Object.entries(pages).map(([id, pageItems]) => ({ id, items: pageItems })),
106111
};
107112
}
108113

0 commit comments

Comments
 (0)