private List <SortedArticleListItem> GetSalItems(string outputFolder, Manifest manifest) { List <SortedArticleListItem> salItems = new List <SortedArticleListItem>(); foreach (ManifestItem manifestItem in manifest.Files) { if (manifestItem.DocumentType != "Conceptual") { continue; } manifestItem.Metadata.TryGetValue(SortedArticleListConstants.IncludeInSalKey, out object includeInSal); if (includeInSal as bool? == false) { continue; } manifestItem.Metadata.TryGetValue(SortedArticleListConstants.SalSnippetLengthKey, out object length); int salSnippetLength = length as int? ?? SortedArticleListConstants.DefaultSalSnippetLength; HtmlNode articleNode = manifestItem.GetHtmlOutputArticleNode(outputFolder); string relPath = manifestItem.GetHtmlOutputRelPath().Replace(".html", ""); HtmlNode snippetNode = SnippetCreator.CreateSnippet(articleNode, relPath, salSnippetLength); DateTime date = default(DateTime); try { date = DateTime.ParseExact(manifestItem.Metadata[SortedArticleListConstants.DateKey] as string, // Info on custom date formats https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.85).aspx new string[] { "MMM d, yyyy", "d" }, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AllowWhiteSpaces); } catch { throw new InvalidDataException($"{nameof(SortedArticleListGenerator)}: Article {manifestItem.SourceRelativePath} has an invalid {SortedArticleListConstants.DateKey}"); } salItems.Add(new SortedArticleListItem { RelPath = relPath, SnippetNode = snippetNode, Date = date }); } return(salItems); }
private Dictionary <string, SearchIndexItem> GetSearchIndexItems(string outputFolder, Manifest manifest) { Dictionary <string, SearchIndexItem> SearchIndexItems = new Dictionary <string, SearchIndexItem>(); foreach (ManifestItem manifestItem in manifest.Files) { if (manifestItem.DocumentType != "Conceptual") { continue; } manifestItem.Metadata.TryGetValue(SearchIndexConstants.IncludeInSearchIndexKey, out object includeInSearchIndex); if (includeInSearchIndex as bool? == false) { continue; } string relPath = manifestItem.GetHtmlOutputRelPath(); HtmlNode articleNode = manifestItem.GetHtmlOutputArticleNode(outputFolder); StringBuilder stringBuilder = new StringBuilder(); ExtractTextFromNode(articleNode, stringBuilder); string text = NormalizeNodeText(stringBuilder.ToString()); manifestItem.Metadata.TryGetValue(SearchIndexConstants.SearchIndexSnippetLengthKey, out object length); int searchIndexSnippetLength = length as int? ?? SearchIndexConstants.DefaultArticleSnippetLength; HtmlNode snippet = SnippetCreator.CreateSnippet(articleNode, relPath, searchIndexSnippetLength); SearchIndexItems.Add(relPath, new SearchIndexItem { RelPath = relPath, SnippetHtml = snippet.OuterHtml, Text = text, Title = snippet.SelectSingleNode(".//h1[contains(@class, 'title')]/a").InnerText }); } return(SearchIndexItems); }