@@ -48,10 +48,14 @@ export interface DocItemContext {
48
48
page ?: string ;
49
49
item : DocItemWithContext ;
50
50
contract ?: ContractDefinition ;
51
- file : SourceUnit ;
51
+ file : DocItemContextFile ;
52
52
build : BuildContext ;
53
53
}
54
54
55
+ export interface DocItemContextFile extends SourceUnit {
56
+ relativePath : string ;
57
+ }
58
+
55
59
export function buildSite ( builds : Build [ ] , siteConfig : SiteConfig , properties : Properties = { } ) : Site {
56
60
const assign = typeof siteConfig . pages === 'string' ? pageAssigner [ siteConfig . pages ] : siteConfig . pages ;
57
61
@@ -67,9 +71,12 @@ export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: P
67
71
const decodeSrc = srcDecoder ( input , output ) ;
68
72
const build = { input, output, deref, decodeSrc } ;
69
73
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 } ) ;
73
80
74
81
for ( const topLevelItem of file . nodes ) {
75
82
if ( ! isDocItem ( topLevelItem ) ) continue ;
@@ -105,7 +112,7 @@ export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: P
105
112
} ;
106
113
}
107
114
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 {
109
116
return Object . assign ( item , {
110
117
[ DOC_ITEM_CONTEXT ] : { build, file, contract, page, item : item as DocItemWithContext } ,
111
118
} ) ;
@@ -121,7 +128,7 @@ function defineProperties(item: DocItemWithContext, properties: Properties) {
121
128
function assignIfIncludedSource (
122
129
assign : PageAssigner ,
123
130
item : DocItem ,
124
- file : SourceUnit ,
131
+ file : DocItemContextFile ,
125
132
config : SiteConfig ,
126
133
) {
127
134
return isFileIncluded ( file . absolutePath , config )
0 commit comments