private void GenerateSearchPage() { var activePath = new NavigatedPath(); activePath.Push(this.Pages); var searchSimpleElement = new SimpleNavigationElement() { Name = "Search", Value = "Docnet_search.htm", IsIndexElement = false, ParentContainer = this.Pages }; searchSimpleElement.ContentProducerFunc = e => @" <h1 id=""search"">Search Results</h1> <p> <form id=""content_search"" action=""docnet_search.htm""> <span role= ""status"" aria-live=""polite"" class=""ui-helper-hidden-accessible""></span> <input name=""q"" id=""search-query"" type=""text"" class=""search_input search-query ui-autocomplete-input"" placeholder=""Search the Docs"" autocomplete=""off"" autofocus/> </form> </p> <div id=""search-results""> <p>Sorry, page not found.</p> </div>" ; searchSimpleElement.ExtraScriptProducerFunc = e => @" <script>var base_url = '.';</script> <script data-main=""js/search.js"" src=""js/require.js""></script>" ; searchSimpleElement.GenerateOutput(this, activePath); activePath.Pop(); }
public void Load(JObject dataFromFile) { foreach (KeyValuePair <string, JToken> child in dataFromFile) { INavigationElement toAdd; if (child.Value.Type == JTokenType.String) { var nameToUse = child.Key; var isIndexElement = child.Key == "__index"; if (isIndexElement) { nameToUse = this.Name; } toAdd = new SimpleNavigationElement() { Name = nameToUse, Value = child.Value.ToObject <string>(), IsIndexElement = isIndexElement }; } else { var subLevel = new NavigationLevel() { Name = child.Key, IsRoot = false }; subLevel.Load((JObject)child.Value); toAdd = subLevel; } toAdd.ParentContainer = this; this.Value.Add(toAdd); } }
private string GenerateContent(SimpleNavigationElement element, Config config, NavigationContext navigationContext) { var stringBuilder = new StringBuilder(); stringBuilder.AppendLine("# Page not found (404)"); stringBuilder.AppendLine(); stringBuilder.AppendLine("Unfortunately the page you were looking for does not exist. In order to help you out "); stringBuilder.AppendLine("in the best way possible, below is the table of contents:"); stringBuilder.AppendLine(); foreach (var sibling in this.ParentContainer.Value) { if (sibling == this) { continue; } stringBuilder.AppendFormat("* [{0}]({1}{2}){3}", sibling.Name, "/" /* pathRelativeToRoot */, sibling.GetFinalTargetUrl(navigationContext), Environment.NewLine); } var markdownContent = stringBuilder.ToString(); var destinationFile = Utils.MakeAbsolutePath(config.Destination, this.GetTargetURL(navigationContext)); var htmlContent = Utils.ConvertMarkdownToHtml(markdownContent, Path.GetDirectoryName(destinationFile), config.Destination, string.Empty, new List <Heading>(), config.ConvertLocalLinks); return(htmlContent); }
public void Load(JObject dataFromFile) { foreach (KeyValuePair <string, JToken> child in dataFromFile) { INavigationElement toAdd; if (child.Value.Type == JTokenType.String) { var nameToUse = child.Key; var isIndexElement = child.Key == "__index"; if (isIndexElement) { nameToUse = this.Name; } var childValue = child.Value.ToObject <string>(); if (childValue.EndsWith("**")) { var path = childValue.Replace("**", string.Empty) .Replace('\\', Path.DirectorySeparatorChar) .Replace('/', Path.DirectorySeparatorChar); if (!Path.IsPathRooted(path)) { path = Path.Combine(_rootDirectory, path); } toAdd = CreateGeneratedLevel(path); toAdd.Name = nameToUse; } else { toAdd = new SimpleNavigationElement { Name = nameToUse, Value = childValue, IsIndexElement = isIndexElement }; } } else { var subLevel = new NavigationLevel(_rootDirectory) { Name = child.Key, IsRoot = false }; subLevel.Load((JObject)child.Value); toAdd = subLevel; } toAdd.ParentContainer = this; this.Value.Add(toAdd); } }
private NavigationLevel CreateGeneratedLevel(string path) { var root = new NavigationLevel(_rootDirectory) { ParentContainer = this, IsAutoGenerated = true }; foreach (var mdFile in Directory.GetFiles(path, "*.md", SearchOption.TopDirectoryOnly)) { var name = FindTitleInMdFile(mdFile); if (string.IsNullOrWhiteSpace(name)) { continue; } var item = new SimpleNavigationElement { Name = name, Value = Path.Combine(Utils.MakeRelativePath(_rootDirectory, path), Path.GetFileName(mdFile)), ParentContainer = root, IsAutoGenerated = true }; root.Value.Add(item); } foreach (var directory in Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly)) { var subDirectoryNavigationElement = CreateGeneratedLevel(directory); subDirectoryNavigationElement.Name = new DirectoryInfo(directory).Name; subDirectoryNavigationElement.ParentContainer = root; root.Value.Add(subDirectoryNavigationElement); } return(root); }
public SimpleNavigationElement GetIndexElement(NavigationContext navigationContext) { var toReturn = this.Value.FirstOrDefault(e => e.IsIndexElement) as SimpleNavigationElement; if (toReturn == null) { // no index element, add an artificial one. var path = string.Empty; // Don't check parents when using relative paths since we need to walk the tree manually if (navigationContext.PathSpecification == PathSpecification.Full) { if (this.ParentContainer != null) { path = Path.GetDirectoryName(this.ParentContainer.GetTargetURL(navigationContext)); } } var nameToUse = string.Empty; switch (navigationContext.UrlFormatting) { case UrlFormatting.None: // Backwards compatibility mode nameToUse = this.Name.Replace(".", "").Replace('/', '_').Replace("\\", "_").Replace(":", "").Replace(" ", ""); break; default: nameToUse = this.Name.ApplyUrlFormatting(navigationContext.UrlFormatting); break; } if (string.IsNullOrWhiteSpace(nameToUse)) { return(null); } var value = string.Format("{0}{1}.md", path, nameToUse); switch (navigationContext.PathSpecification) { case PathSpecification.Full: // Default is correct break; case PathSpecification.Relative: case PathSpecification.RelativeAsFolder: if (!IsRoot) { string preferredPath = null; // We're making a big assumption here, but we can get the first page and assume it's // in the right folder. // Find first (simple) child and use 1 level up. A SimpleNavigationElement mostly represents a folder // thus is excellent to be used as a folder name var firstSimpleChildPage = (SimpleNavigationElement)this.Value.FirstOrDefault(x => x is SimpleNavigationElement && !ReferenceEquals(this, x)); if (firstSimpleChildPage != null) { preferredPath = Path.GetDirectoryName(firstSimpleChildPage.Value); } else { // This is representing an empty folder. Search for first child navigation that has real childs, // then retrieve the path by going levels up. var firstChildNavigationLevel = (NavigationLevel)this.Value.FirstOrDefault(x => x is NavigationLevel && ((NavigationLevel)x).Value.Any() && !ReferenceEquals(this, x)); if (firstChildNavigationLevel != null) { var targetUrl = firstChildNavigationLevel.Value.First().GetTargetURL(navigationContext); // 3 times since we need 2 parents up preferredPath = Path.GetDirectoryName(targetUrl); preferredPath = Path.GetDirectoryName(preferredPath); preferredPath = Path.GetDirectoryName(preferredPath); } } if (!string.IsNullOrWhiteSpace(preferredPath)) { value = Path.Combine(preferredPath, "index.md"); } } break; default: throw new ArgumentOutOfRangeException(nameof(navigationContext.PathSpecification), navigationContext.PathSpecification, null); } toReturn = new SimpleNavigationElement { ParentContainer = this, Value = value, Name = this.Name, IsIndexElement = true }; this.Value.Add(toReturn); } return(toReturn); }