public void WriteBooks(AppConf appConfig) { AppName = appConfig.Name; FireEvent(AppInitializing, new WebBookEventArgs(appConfig)); // get all the pages BamApplicationManager manager = new BamApplicationManager(appConfig.BamConf); List <string> pageNames = new List <string>(manager.GetPageNames(appConfig.Name)); // read all the pages pageNames.Each(pageName => { FireEvent(WritingBook, new WebBookEventArgs(appConfig)); CurrentPage = pageName; Fs appFs = appConfig.AppRoot; // create a new book for every page WebBook book = new WebBook { Name = pageName }; string content = appFs.ReadAllText("pages", "{0}.html"._Format(pageName)); // get all the [data-navigate-to] and a elements CQ cq = CQ.Create(content); CQ navElements = cq["a, [data-navigate-to]"]; navElements.Each(nav => { // create a WebBookPage for each target string href = nav.Attributes["href"]; string navTo = nav.Attributes["data-navigate-to"]; string url = string.IsNullOrEmpty(navTo) ? href: navTo; if (!string.IsNullOrEmpty(url)) { url = url.Contains('?') ? url.Split('?')[0] : url; string layout = nav.Attributes["data-layout"]; layout = string.IsNullOrEmpty(layout) ? "basic" : layout; if (pageNames.Contains(url)) { book.Pages.Add(new WebBookPage { Name = url, Layout = layout }); } } }); appFs.WriteFile("~/books/{0}.json"._Format(book.Name), book.ToJson(true), true); FireEvent(WroteBook, new WebBookEventArgs(appConfig)); }); FireEvent(AppInitialized, new WebBookEventArgs(appConfig)); }
protected internal WebBook GetBookByAppAndPage(string appName = "localhost", string pageName = "home") { AppConf appConf = BamConf[appName]; WebBook result = new WebBook(); if (appConf != null) { string booksDir = "books"; string bookFile = "{0}.json"._Format(pageName); Fs appRoot = appConf.AppRoot; if (appRoot.FileExists(booksDir, bookFile)) { result = appRoot.ReadAllText(booksDir, bookFile).FromJson <WebBook>(); } } return(result); }