Exemplo n.º 1
0
        private void UpdatePages(DateTime lastModified)
        {
            var logFile = File.Create(Path.Combine(_environment.WebRootPath, "sitemap-pages.xml"));

            using (var stream = new StreamWriter(logFile))
            {
                var sitemap = new Sitemap(stream);
                sitemap.WriteStartDocument();

                sitemap.WriteItem(_websiteDomainName, lastModified, "daily", "1");

                sitemap.WriteEndDocument();
                sitemap.Close();
            }
        }
Exemplo n.º 2
0
        private void UpdatePosts(IEnumerable <Post> posts)
        {
            var logFile = File.Create(Path.Combine(_environment.WebRootPath, "sitemap-posts.xml"));

            using (var stream = new StreamWriter(logFile))
            {
                var sitemap = new Sitemap(stream);
                sitemap.WriteStartDocument();

                foreach (var post in posts)
                {
                    sitemap.WriteItem($"{_websiteDomainName}/post/{post.Url}", post.LastModified, "weekly", "0.8");
                }

                sitemap.WriteEndDocument();
                sitemap.Close();
            }
        }
Exemplo n.º 3
0
        private void UpdateCategories(IEnumerable <Category> categories, IEnumerable <Post> posts)
        {
            var logFile = File.Create(Path.Combine(_environment.WebRootPath, "sitemap-categories.xml"));

            using (var stream = new StreamWriter(logFile))
            {
                var sitemap = new Sitemap(stream);
                sitemap.WriteStartDocument();

                foreach (var category in categories)
                {
                    var lastModifiedPostOnCategory = posts.FirstOrDefault(a => a.PostCategories.Any(b => b.CategoryId == category.Id));

                    if (lastModifiedPostOnCategory != null)
                    {
                        sitemap.WriteItem($"{_websiteDomainName}/post/category/{category.Url}",
                                          lastModifiedPostOnCategory.LastModified, "weekly", "0.8");
                    }
                }

                sitemap.WriteEndDocument();
                sitemap.Close();
            }
        }