public static void AddCollectionPage(Page page) { var collection = _collections.ContainsKey(page.Collection) ? _collections[page.Collection] as List<Page> : null; if (collection == null) { collection = new List<Page>(); _collections[page.Collection] = collection; } collection.Add(page); }
private static void LoadSiteContent(string path) { string directoryPath = GetPath(path); foreach (var fileInfo in new DirectoryInfo(directoryPath).GetFileSystemInfos()) { string virtualPath = (String.IsNullOrEmpty(path) ? "" : path + "\\") + fileInfo.Name; if (virtualPath.StartsWith(DATA_FOLDER, StringComparison.OrdinalIgnoreCase) || virtualPath.StartsWith(INCLUDES_FOLDER, StringComparison.OrdinalIgnoreCase)) { cacheDependencyDirectories[directoryPath] = directoryPath; continue; } else if (fileInfo is DirectoryInfo) { // recurse directory LoadSiteContent(virtualPath); } else { // process file if (fileInfo.Extension.Equals(".md", StringComparison.OrdinalIgnoreCase) || fileInfo.Extension.Equals(".markdown", StringComparison.OrdinalIgnoreCase) || fileInfo.Extension.Equals(".html", StringComparison.OrdinalIgnoreCase)) { if (virtualPath.StartsWith(Site.LAYOUTS_FOLDER, StringComparison.OrdinalIgnoreCase)) { var layout = new Layout(virtualPath); _layouts[layout.Name] = layout; } else { var page = new Page(virtualPath); _pages[page.Permalink] = page; } // cache this directory cacheDependencyDirectories[directoryPath] = directoryPath; } } } }
public static string RenderPage(Page page, string requestUrl) { EnsureSiteLoaded(); // look for rendered page in cache string cacheKey = "page:" + requestUrl; var content = (string)GetFromCache(cacheKey); if (content != null) { return content; } // get rendered page content content = page.Content; var layoutName = page.Layout; while (layoutName != null) { // render layout if (!_layouts.ContainsKey(layoutName)) { throw new Exception(String.Format("Error rendering page {0}. Layout {1} not found.", page.Url, layoutName)); } var layout = _layouts[layoutName]; content = RenderContent(page, layout.Content, new Dictionary<string, object> { { "content", content } }); layoutName = layout.ParentLayout; } // add to cache if (!page.NoCache) { Site.AddToCache(cacheKey, content, new string[] { page.Path }, new string[] { SITE_CONTENT_VALID_CACHE_KEY }); } return content; }
public static string RenderContent(Page page, string content, Dictionary<string, object> parameters = null) { var context = new Context(); context["site"] = _site; context["page"] = page; context["request"] = new Request(HttpContext.Current); context.AddFilters(typeof(Filters)); if (parameters != null) { foreach (var parameter in parameters) { context[parameter.Key] = parameter.Value; } } Template.RegisterTag<Highlight>("highlight"); Template.FileSystem = new IncludesFolder(GetPath("_includes")); Template template = Template.Parse(content); return template.Render(new RenderParameters { Context = context }); }