51 lines
1.0 KiB
C#
51 lines
1.0 KiB
C#
using Tagger.Data;
|
|
|
|
namespace Tagger.Service;
|
|
|
|
public class PageProvider
|
|
{
|
|
const string PageDirPath = "Pages";
|
|
|
|
public PageProvider()
|
|
{
|
|
Directory.CreateDirectory(PageDirPath);
|
|
}
|
|
|
|
public MarkdownPage? Get(string name)
|
|
{
|
|
string path = Path.Combine(PageDirPath, name);
|
|
|
|
if (!File.Exists(path))
|
|
return null;
|
|
|
|
return new()
|
|
{
|
|
Title = name,
|
|
Content = File.ReadAllText(path)
|
|
};
|
|
}
|
|
|
|
public void Save(MarkdownPage page)
|
|
{
|
|
string path = Path.Combine(PageDirPath, page.Title);
|
|
|
|
File.Delete(path);
|
|
File.WriteAllText(path, page.Content);
|
|
}
|
|
|
|
public void Delete(string name)
|
|
{
|
|
string path = Path.Combine(PageDirPath, name);
|
|
File.Delete(path);
|
|
}
|
|
|
|
public IEnumerable<string> List()
|
|
{
|
|
foreach(var i in Directory.GetFiles(PageDirPath))
|
|
{
|
|
//FileInfo fi = new(i);
|
|
yield return i.Substring(PageDirPath.Length+1);
|
|
}
|
|
}
|
|
}
|