Fan website of IMMORTAL: Gates of Pyre.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

78 lines
2.1 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.RegularExpressions;
using Model.Website;
namespace Model.Notes;
public class NoteContentModel
{
public int Id { get; set; }
public int? ParentId { get; set; } = null;
public int? NoteSectionModelId { get; set; } = null;
public string Href { get; set; }
//public DateTime LastUpdated { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime UpdatedDate { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Content { get; set; }
[NotMapped] public virtual string LoadedContent { get; set; }
public string IsHidden { get; set; } = "False";
public string IsPreAlpha { get; set; } = "True";
[NotMapped]
public virtual ICollection<NoteContentModel> NoteContentModels { get; set; } = new List<NoteContentModel>();
[NotMapped] public virtual NoteContentModel Parent { get; set; }
[NotMapped] public virtual int PageOrder { get; set; }
public List<SearchPointModel> GetHeaders()
{
var regex = new Regex(@"^#* (.*)$", RegexOptions.Multiline);
var listOfMatches = regex.Matches(LoadedContent);
var foundHeaders = new List<SearchPointModel>();
foreach (var capture in listOfMatches)
{
var cleanUp = capture.ToString();
cleanUp = cleanUp.ToLower();
cleanUp = cleanUp.Replace("#", "");
cleanUp = cleanUp.Replace("#", "");
cleanUp = cleanUp.Replace("\"", "");
cleanUp = cleanUp.Trim();
cleanUp = cleanUp.Replace(" ", "-");
foundHeaders.Add(new SearchPointModel { Title = capture.ToString().Trim(), Href = cleanUp });
Console.WriteLine($"Capture: {cleanUp}");
}
return foundHeaders;
}
private string GetLink()
{
var link = Href;
if (Parent != null) link = $"{Parent.GetLink()}/" + link;
return link;
}
public string GetNoteLink()
{
return $"notes/{GetLink()}";
}
}