11using System . Diagnostics ;
22using System . Runtime . CompilerServices ;
3+ using Azure . Storage . Blobs ;
34using Codex . Application . Verbs ;
45using Codex . Lucene . Search ;
56using Codex . Sdk ;
@@ -143,7 +144,7 @@ public async Task<WebProgramBase> CreateWebProgram(IngestOperation indexOperatio
143144
144145 await program . RunAsync ( ) ;
145146
146- return program ; ;
147+ return program ;
147148 }
148149
149150 public CodexPage CreateCodexApp ( IngestOperation indexOperation ,
@@ -217,86 +218,113 @@ public IReadOnlyStableIdStorage ReadStableIdStorage(string storageDirectory, [Ca
217218 public CodexPage CreateCodexApp ( string indexDirectory ,
218219 Func < CodexAppOptions , CodexAppOptions > updateOptions = null )
219220 {
220- var options = new CodexAppOptions ( ) ;
221- options = updateOptions ? . Invoke ( options ) ?? options ;
221+ var page = getPage ( ) ;
222+ page . WebViewModelController ? . TrackSourceReferenceHtml = true;
223+ return page ;
222224
223- if ( PathUtilities . ToUriOrPath ( indexDirectory , out var uri , out var path ) )
225+ CodexPage getPage ( )
224226 {
225- // For uri's we need to use paging logic
226- options . UsePaging = true ;
227- options . ConfigurePaging = options . ConfigurePaging . ApplyBefore ( pc => pc with
227+ var options = new CodexAppOptions ( ) ;
228+ options = updateOptions ? . Invoke ( options ) ?? options ;
229+
230+ if ( options . CreateSite )
228231 {
229- CacheLimit = 100_000 ,
230- } ) ;
231- }
232+ var arguments = new WebProgramArguments ( )
233+ {
234+ RootUrl = new Uri ( "https://codex.test" ) ,
235+ StartUrl = new Uri ( "https://codex.test" ) ,
236+ IndexSource = new Configuration . IndexSourceLocation ( )
237+ {
238+ Url = indexDirectory ,
239+ }
240+ } ;
232241
233- ICodex getCodex ( )
234- {
242+
243+ var program = new WebProgramBase ( arguments ) ;
244+
245+ program . RunAsync ( ) . GetAwaiter ( ) . GetResult ( ) ;
246+
247+ return new CodexPage ( program ) ;
248+ }
249+
250+ if ( PathUtilities . ToUriOrPath ( indexDirectory , out var uri , out var path ) )
235251 {
236- LuceneConfiguration configuration ;
252+ // For uri's we need to use paging logic
253+ options . UsePaging = true ;
254+ options . ConfigurePaging = options . ConfigurePaging . ApplyBefore ( pc => pc with
255+ {
256+ CacheLimit = 100_000 ,
257+ } ) ;
258+ }
237259
238- if ( options . UsePaging
239- || options . TrackingClient != null )
260+ ICodex getCodex ( )
261+ {
240262 {
241- if ( options . ValidatePaging )
263+ LuceneConfiguration configuration ;
264+
265+ if ( options . UsePaging
266+ || options . TrackingClient != null )
242267 {
243- var configurePaging = options . ConfigurePaging ?? ( pc => pc ) ;
244- options . ConfigurePaging = pc =>
268+ if ( options . ValidatePaging )
245269 {
246- pc = pc with { Validating = true , ValidatingDirectory = options . ValidatingIndexDirectory ?? indexDirectory } ;
247- pc = configurePaging . Invoke ( pc ) ;
248- return pc ;
249- } ;
250- }
270+ var configurePaging = options . ConfigurePaging ?? ( pc => pc ) ;
271+ options . ConfigurePaging = pc =>
272+ {
273+ pc = pc with { Validating = true , ValidatingDirectory = options . ValidatingIndexDirectory ?? indexDirectory } ;
274+ pc = configurePaging . Invoke ( pc ) ;
275+ return pc ;
276+ } ;
277+ }
251278
252- if ( options . TrackingClient != null )
253- {
254- var configurePaging = options . ConfigurePaging ?? ( pc => pc ) ;
255- options . ConfigurePaging = pc =>
279+ if ( options . TrackingClient != null )
256280 {
257- pc = pc with
281+ var configurePaging = options . ConfigurePaging ?? ( pc => pc ) ;
282+ options . ConfigurePaging = pc =>
258283 {
259- UpdateClient = client =>
284+ pc = pc with
260285 {
261- var trackingClient = options . TrackingClient ;
262- trackingClient . Inner = client . Value ;
263- client . Value = trackingClient ;
264- }
286+ UpdateClient = client =>
287+ {
288+ var trackingClient = options . TrackingClient ;
289+ trackingClient . Inner = client . Value ;
290+ client . Value = trackingClient ;
291+ }
292+ } ;
293+ pc = configurePaging . Invoke ( pc ) ;
294+
295+ return pc ;
265296 } ;
266- pc = configurePaging . Invoke ( pc ) ;
297+ }
267298
268- return pc ;
269- } ;
299+ configuration = CreatePagingConfigurationAsync (
300+ indexDirectory ,
301+ options . ConfigurePaging ) . GetAwaiter ( ) . GetResult ( ) ;
302+ }
303+ else
304+ {
305+ configuration = new LuceneConfiguration ( indexDirectory ) ;
270306 }
271307
272- configuration = CreatePagingConfigurationAsync (
273- indexDirectory ,
274- options . ConfigurePaging ) . GetAwaiter ( ) . GetResult ( ) ;
275- }
276- else
277- {
278- configuration = new LuceneConfiguration ( indexDirectory ) ;
279- }
280-
281- if ( options . AddSourceRetriever )
282- {
283- configuration . SourceTextRetriever = new HttpClientSourceTextRetriever ( ) ;
284- }
308+ if ( options . AddSourceRetriever )
309+ {
310+ configuration . SourceTextRetriever = new HttpClientSourceTextRetriever ( ) ;
311+ }
285312
286- configuration . DefaultAccessLevel = ObjectModel . RepoAccess . Internal ;
313+ configuration . DefaultAccessLevel = ObjectModel . RepoAccess . Internal ;
287314
288- var codex = new LuceneCodex ( configuration ) ;
289- return codex ;
315+ var codex = new LuceneCodex ( configuration ) ;
316+ return codex ;
317+ }
290318 }
291- }
292319
293- var codex = getCodex ( ) ;
320+ var codex = getCodex ( ) ;
294321
295- var app = new MainController ( ) ;
296- app . Controller = new WebViewModelController ( app ) { TrackSourceReferenceHtml = true } ;
297- app . CodexService = codex ;
322+ var app = new MainController ( ) ;
323+ app . Controller = new WebViewModelController ( app ) ;
324+ app . CodexService = codex ;
298325
299- return new CodexPage ( codex , app , app . Controller . ViewModel ) ;
326+ return new CodexPage ( codex , app , app . Controller . ViewModel ) ;
327+ }
300328 }
301329
302330 public record CodexAppOptions
@@ -305,6 +333,8 @@ public record CodexAppOptions
305333 public string ValidatingIndexDirectory { get ; set ; }
306334 public bool UsePaging { get ; set ; }
307335 public bool ValidatePaging { get ; set ; }
336+ public bool CreateSite { get ; set ; }
337+
308338 public Func < PagingConfiguration , PagingConfiguration > ConfigurePaging = null ;
309339 public TrackingHttpClient TrackingClient { get ; set ; }
310340 }
0 commit comments