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);
        }
Exemplo n.º 2
0
        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);
        }
        /// <summary>
        /// スニペット作成ボタン押下イベント
        /// </summary>
        /// <param name="sender">イベント発生元オブジェクト</param>
        /// <param name="e">イベントデータ</param>
        private void createButton_Click(object sender, EventArgs e)
        {
            String saveFilePath = this.GetSavePath();

            // 保存先が指定されていない場合、処理しない。
            if (String.IsNullOrEmpty(saveFilePath))
            {
                return;
            }

            SnippetCreator creator = new SnippetCreator();

            // ヘッダ情報を設定する。
            creator.SetHeader(this.titleTextBox.Text, this.authorTextBox.Text,
                              this.descriptionTextBox.Text, this.shortcutTextBox.Text);
            // コード情報を設定する。
            creator.SetCode(this.codeTextBox.Text, this.languageComboBox.SelectedItem as string);
            // スニペットを保存する。
            creator.Save(saveFilePath);

            MessageBox.Show("Complete save file.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }