Esempio n. 1
0
        private bool PublishArticlesAndTags(PublishConfiguration pc, out int count)
        {
            count = 0;
            using (var db = new FusekiContext())
            {
                var articleIds = new List <int>();
                try
                {
                    foreach (var article in db.Articles
                             .Include(el => el.Tags)
                             .Where(el => el.Published == true))
                    {
                        var filename = article.MakeFilename(false);
                        Console.WriteLine($"Writing: {filename}");
                        var path = MakePath(pc, filename);
                        //todo add in better title generation code here.

                        var combined = Renderer.GenerateArticleString(Settings, article, false);
                        System.IO.File.WriteAllText(path, combined);
                        articleIds.Add(article.Id);
                        Logger.LogMessage($"Published: {article.Title}");
                        count++;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }


                //todo only publish tags where the article is published.
                var tags = db.Tags.Where(t => articleIds.Contains(t.ArticleId)).ToHashSet();

                var tagDir = pc.TempBase + "/tags";
                if (!System.IO.Directory.Exists(tagDir))
                {
                    System.IO.Directory.CreateDirectory(tagDir);
                }

                foreach (var tag in tags)
                {
                    PublishTag(pc, tag, false);
                }

                RecreateHtaccess(pc);
            }

            return(true);
        }
Esempio n. 2
0
        public IActionResult ViewArticle(string title)
        {
            using (var db = new FusekiContext())
            {
                var article = db.Articles
                              .Include(ee => ee.Tags)
                              .FirstOrDefault(el => el.Title.StartsWith(title));
                //startswith to fix question mark thing.

                if (article == null)
                {
                    return(RedirectToAction("List"));;
                }

                var related = ArticleData.GetRelatedArticles(article);

                var liveUrl       = string.Format(Settings.LiveUrlTemplate, article.MakeFilename(true));
                var editUrl       = string.Format(Settings.EditUrlTemplate, article.Title, false);
                var articleString = Renderer.GenerateArticleString(Settings, article, true);
                var model         = new ArticleModel(article, liveUrl, editUrl, articleString, related);
                ViewData["Title"] = $"{article.Title}";
                return(View("Article", model));
            }
        }