using Business.Services;
using Core.Configuration;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using SimpleMvcSitemap;
using System;
using System.Collections.Generic;
using XperienceAdapter.Localization;
namespace ABC.Controllers
{
[Route("googlesitemap.xml", Name = "GoogleSitemap")]
public class GoogleSitemapController : BaseController
{
private readonly ISitemapServices _sitemapServices;
public GoogleSitemapController(ILogger<BaseController> logger,
IOptionsMonitor<XperienceOptions> optionsMonitor,
IStringLocalizer<SharedResource> stringLocalizer,
ISitemapServices sitemapServices) : base(logger, optionsMonitor, stringLocalizer)
{
_sitemapServices = sitemapServices ?? throw new ArgumentNullException(nameof(sitemapServices));
}
public IActionResult Index()
{
var contentMultiple = _sitemapServices.GetContentAsync(
_optionsMonitor.CurrentValue.CacheInSeconds,
null
);
List<SitemapNode> nodes = new List<SitemapNode>();
foreach (var doc in contentMultiple.Result)
{
nodes.Add(new SitemapNode(doc.NodeAliasPath)
{
LastModificationDate = (doc.DocumentModifiedWhen.Date)
});
}
return new SitemapProvider().CreateSitemap(new SitemapModel(nodes));
}
}
}
No comments:
Post a Comment