public static string getLayoutContents(string layout, string filePath) { Console.WriteLine("getLayoutContents - " + layout + ", " + filePath); var layoutPath = GlobalConfiguration.getConfiguration().source + "/" + GlobalConfiguration.getConfiguration().layouts_dir + "/" + layout + ".html"; var layoutContents = WDHANFile.getFileContents(layoutPath); Console.WriteLine("getLayoutContents WITHOUTINCLUDE:\n" + layoutContents); layoutContents = Include.evalInclude(layoutPath); Console.WriteLine("getLayoutContents WITH:\n" + layoutContents); //layoutContents = WDHANFile.getFileContents(layoutPath); try { var subLayout = Page.parseFrontMatter(layoutPath)["layout"].ToString(); Console.WriteLine(subLayout); var subLayoutPath = GlobalConfiguration.getConfiguration().source + "/" + GlobalConfiguration.getConfiguration().layouts_dir + "/" + subLayout + ".html"; Console.WriteLine(subLayoutPath); layoutContents = getLayoutContents(subLayout, filePath).Replace("{{ content }}", layoutContents); Console.WriteLine(layout + " - HASSUB:\n" + layoutContents); return(layoutContents); //return parseLayout(collectionName, filePath, layoutContents); } catch (Exception ex) { Console.WriteLine("SUBLAYOUTEXCEPTION:\n" + ex.ToString()); Console.WriteLine(layout + ":\n" + layoutContents); return(layoutContents); //return parseLayout(collectionName, filePath, layoutContents); } }
public static string parseRaw(string filePath) { Console.WriteLine("parseRaw - " + filePath); var siteConfig = GlobalConfiguration.getConfiguration(); var fileContents = WDHANFile.getFileContents(filePath); fileContents = Include.evalInclude(filePath); // Expand includes (must happen after layouts are retreived, as layouts can have includes) // When a property of a JObject value is accessed, try to look into its properties TemplateContext.GlobalMemberAccessStrategy.Register <JObject, object>((source, name) => source[name]); // Convert JToken to FluidValue FluidValue.SetTypeMapping <JObject>(o => new ObjectValue(o)); FluidValue.SetTypeMapping <JValue>(o => FluidValue.Create(o.Value)); var siteModel = JObject.Parse(File.ReadAllText("./_config.json")); var dataSet = JObject.Parse(File.ReadAllText(siteConfig.source + "/temp/_data.json")); var pageModel = WDHANFile.parseFrontMatter(filePath); Console.WriteLine("fileContents!!!" + filePath + ":\n" + fileContents); try { if (FluidTemplate.TryParse(fileContents, out var template)) { var context = new TemplateContext(); context.CultureInfo = new CultureInfo(siteConfig.culture); siteModel.Merge(dataSet, new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Union }); context.SetValue("site", siteModel); context.SetValue("page", pageModel); foreach (var collection in siteConfig.collections) { if (File.Exists(siteConfig.source + "/temp/_" + collection + "/_entries.json")) { var collectionModel = JObject.Parse(File.ReadAllText(siteConfig.source + "/_" + collection + "/_config.json")); collectionModel.Merge(JObject.Parse(File.ReadAllText(siteConfig.source + "/temp/_" + collection + "/_entries.json")), new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Union }); context.SetValue(collection, collectionModel); } } Console.WriteLine("DONE!!! - " + filePath + " \n" + template.Render(context)); return(template.Render(context)); } else { Console.WriteLine("ERROR: Could not parse Liquid context for file " + filePath + "."); Console.WriteLine("TryParse error:\n" + fileContents); return(fileContents); } } catch (ArgumentNullException ex) { Console.WriteLine("File " + filePath + " has no Liquid context to parse.\n" + ex.ToString()); return(fileContents); } }