Made content directory configurable.
This commit is contained in:
parent
4476b1b3e1
commit
66aba04156
8
Props/Options/ContentOptions.cs
Normal file
8
Props/Options/ContentOptions.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace Props.Options
|
||||||
|
{
|
||||||
|
public class ContentOptions
|
||||||
|
{
|
||||||
|
public const string Content = "Content";
|
||||||
|
public string Dir { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,26 +1,28 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Props.Options;
|
||||||
|
|
||||||
namespace Props.Services.Content
|
namespace Props.Services.Content
|
||||||
{
|
{
|
||||||
public class CachedContentManager<TPage> : IContentManager<TPage>
|
public class CachedContentManager<TPage> : IContentManager<TPage>
|
||||||
{
|
{
|
||||||
private dynamic data;
|
private dynamic data;
|
||||||
private readonly string directory;
|
private readonly ContentOptions options;
|
||||||
private readonly string fileName;
|
private readonly string fileName;
|
||||||
|
|
||||||
dynamic IContentManager<TPage>.Json
|
dynamic IContentManager<TPage>.Json
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (data == null) data = JValue.Parse(File.ReadAllText(Path.Combine(directory, fileName)));
|
if (data == null) data = JValue.Parse(File.ReadAllText(Path.Combine(options.Dir, fileName)));
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CachedContentManager(string directory = "content")
|
public CachedContentManager(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
this.directory = directory;
|
this.options = configuration.GetSection(ContentOptions.Content).Get<ContentOptions>();
|
||||||
this.fileName = typeof(TPage).Name.Replace("Model", "") + ".json";
|
this.fileName = typeof(TPage).Name.Replace("Model", "") + ".json";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,5 +15,8 @@
|
|||||||
"MaxResults": "100",
|
"MaxResults": "100",
|
||||||
"ShopRegex": "Props\\.Shop\\.."
|
"ShopRegex": "Props\\.Shop\\.."
|
||||||
},
|
},
|
||||||
|
"Content": {
|
||||||
|
"Dir": "./content"
|
||||||
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*"
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user