divan/DivanRazor/Utils/GoogleBreadCrumbList.cs
Anas Rashid 532d005cdb Rename Ganjoor -> Divan throughout the code
Projects (GanjooRazor -> DivanRazor, GanjoorService.sln -> DivanService.sln), files,
folders, classes, namespaces, settings, API routes (/api/divan) and DB tables (Divan*).
External addresses (ganjoor.net, github.com/ganjoor) unchanged. Migrations renamed
consistently (no pending model changes); requires a fresh database.
Upstream RUNNING_LOCALLY/SEMANTIC_SEARCH docs archived unmodified under docs/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 23:49:01 +02:00

83 lines
2.3 KiB
C#

using System.Collections.Generic;
using System.Text;
namespace DivanRazor.Utils
{
/// <summary>
/// Google BreadCrumbList
/// </summary>
public class GoogleBreadCrumbList
{
class ItemListElement
{
public int Position { get; set; }
public string Name { get; set; }
public string Id { get; set; }
public string Image { get; set; }
}
private List<ItemListElement> _items = new List<ItemListElement>();
/// <summary>
/// add item
/// </summary>
/// <param name="name"></param>
/// <param name="slug"></param>
/// <param name="image"></param>
public void AddItem(string name, string slug, string image)
{
_items.Add(new ItemListElement()
{
Position = _items.Count + 1,
Name = name,
Id = slug,
Image = image
});
}
/// <summary>
/// to string
/// </summary>
/// <returns></returns>
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(" \"@context\": \"http://schema.org\",");
sb.AppendLine(" \"@type\": \"BreadcrumbList\",");
sb.AppendLine(" \"itemListElement\": [");
for(int i=0; i<_items.Count; i++)
{
sb.AppendLine(" {");
sb.AppendLine(" \"@type\": \"ListItem\",");
sb.AppendLine($" \"position\": {_items[i].Position},");
sb.AppendLine(" \"item\": {");
sb.AppendLine($" \"@id\": \"https://ganjoor.net{_items[i].Id}/\",");
sb.AppendLine($" \"name\": \"{_items[i].Name}\", ");
sb.AppendLine($" \"image\": \"{_items[i].Image}\"");
sb.AppendLine(" }");
if (i != (_items.Count - 1))
{
sb.AppendLine(" },");
}
else
{
sb.AppendLine(" }");
}
}
sb.AppendLine("]");
return sb.ToString();
}
}
}