Skip to content

Commit 1841eeb

Browse files
committed
add relativePath
1 parent 53ba005 commit 1841eeb

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/site.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ export interface DocItemContext {
4848
page?: string;
4949
item: DocItemWithContext;
5050
contract?: ContractDefinition;
51-
file: SourceUnit;
51+
file: DocItemContextFile;
5252
build: BuildContext;
5353
}
5454

55+
export interface DocItemContextFile extends SourceUnit {
56+
relativePath: string;
57+
}
58+
5559
export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: Properties = {}): Site {
5660
const assign = typeof siteConfig.pages === 'string' ? pageAssigner[siteConfig.pages] : siteConfig.pages;
5761

@@ -67,9 +71,12 @@ export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: P
6771
const decodeSrc = srcDecoder(input, output);
6872
const build = { input, output, deref, decodeSrc };
6973

70-
for (const { ast: file } of Object.values(output.sources)) {
71-
const isNewFile = !seen.has(file.absolutePath);
72-
seen.add(file.absolutePath);
74+
for (const { ast } of Object.values(output.sources)) {
75+
const isNewFile = !seen.has(ast.absolutePath);
76+
seen.add(ast.absolutePath);
77+
78+
const relativePath = path.relative(siteConfig.sourcesDir, ast.absolutePath);
79+
const file = Object.assign(ast, { relativePath });
7380

7481
for (const topLevelItem of file.nodes) {
7582
if (!isDocItem(topLevelItem)) continue;
@@ -105,7 +112,7 @@ export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: P
105112
};
106113
}
107114

108-
function defineContext(item: DocItem, build: BuildContext, file: SourceUnit, page?: string, contract?: ContractDefinition): DocItemWithContext {
115+
function defineContext(item: DocItem, build: BuildContext, file: DocItemContextFile, page?: string, contract?: ContractDefinition): DocItemWithContext {
109116
return Object.assign(item, {
110117
[DOC_ITEM_CONTEXT]: { build, file, contract, page, item: item as DocItemWithContext },
111118
});
@@ -121,7 +128,7 @@ function defineProperties(item: DocItemWithContext, properties: Properties) {
121128
function assignIfIncludedSource(
122129
assign: PageAssigner,
123130
item: DocItem,
124-
file: SourceUnit,
131+
file: DocItemContextFile,
125132
config: SiteConfig,
126133
) {
127134
return isFileIncluded(file.absolutePath, config)

0 commit comments

Comments
 (0)