-
Notifications
You must be signed in to change notification settings - Fork 35
/
SiteMapController.cs
54 lines (45 loc) · 1.83 KB
/
SiteMapController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Kontent.Ai.Boilerplate.Models;
using SimpleMvcSitemap;
using Microsoft.Extensions.Logging;
using Kontent.Ai.Delivery.Abstractions;
using Kontent.Ai.Urls.Delivery.QueryParameters;
using Kontent.Ai.Urls.Delivery.QueryParameters.Filters;
namespace Kontent.Ai.Boilerplate.Controllers
{
public class SiteMapController : BaseController<SiteMapController>
{
public SiteMapController(IDeliveryClient deliveryClient, ILogger<SiteMapController> logger) : base(deliveryClient, logger)
{
}
public async Task<ActionResult> Index()
{
// TODO: The different system types which should be included in the sitemap should be specified in the InFilter params
var parameters = new List<IQueryParameter>
{
new DepthParameter(0),
new InFilter("system.type", "article", "cafe"),
};
var response = await DeliveryClient.GetItemsAsync<object>(parameters);
var nodes = response.Items.Cast<ISitemapItem>().Select(item => new SitemapNode(GetPageUrl(item.System))
{
LastModificationDate = item.System.LastModified
}).ToList();
return new SitemapProvider().CreateSitemap(new SitemapModel(nodes));
}
private static string GetPageUrl(IContentItemSystemAttributes system)
{
// TODO: The URL generation logic should be adjusted to match your website
var url = string.Empty;
if (system.SitemapLocation.Any())
{
url = $"/{system.SitemapLocation[0]}";
}
url = $"{url}/{system.Codename.Replace("_", "-").TrimEnd('-')}";
return url;
}
}
}