Skip to content

Commit aa63a05

Browse files
committed
Themes list from embedded resources
1 parent dc7e997 commit aa63a05

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

Blogifier.Core/Configuration.cs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,29 +122,43 @@ static void AddFileProviders(IServiceCollection services)
122122
{
123123
services.Configure<RazorViewEngineOptions>(options =>
124124
{
125-
try
126-
{
127-
// load blog themes list from physical file provider
128-
var themes = options.FileProviders[0].GetDirectoryContents("/Views/Blogifier/Themes");
129-
130-
BlogSettings.BlogThemes = new List<SelectListItem>();
131-
BlogSettings.BlogThemes.Add(new SelectListItem { Value = "Standard", Text = "Standard" });
132-
133-
foreach (var theme in themes)
134-
{
135-
BlogSettings.BlogThemes.Add(new SelectListItem {
136-
Text = theme.Name,
137-
Value = theme.Name
138-
});
139-
}
140-
}
141-
catch { }
142-
143125
foreach (var assembly in GetAssemblies())
144126
{
145127
options.FileProviders.Add(new EmbeddedFileProvider(assembly, assembly.GetName().Name));
146128
}
147129
});
130+
131+
LoadThemes();
132+
}
133+
catch { }
134+
}
135+
136+
static void LoadThemes()
137+
{
138+
/*
139+
This code relies on Blogifier.Web.csproj to have this line:
140+
<EmbeddedResource Include="Views\Blogifier\**\Single.cshtml" />
141+
We need it to populate list of installed themes when project
142+
deployed precompiled and file system not accessible
143+
*/
144+
try
145+
{
146+
var assembly = Assembly.LoadFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Blogifier.Web.dll"));
147+
var provider = new EmbeddedFileProvider(assembly, assembly.GetName().Name);
148+
var resources = provider.GetDirectoryContents("/");
149+
150+
BlogSettings.BlogThemes = new List<SelectListItem>();
151+
BlogSettings.BlogThemes.Add(new SelectListItem { Value = "Standard", Text = "Standard" });
152+
153+
foreach (var rsrc in resources)
154+
{
155+
var theme = rsrc.Name.Replace("Views.Blogifier.Themes.", "").Replace(".Single.cshtml", "");
156+
BlogSettings.BlogThemes.Add(new SelectListItem
157+
{
158+
Text = theme,
159+
Value = theme
160+
});
161+
}
148162
}
149163
catch { }
150164
}

Blogifier.Web/Blogifier.Web.csproj

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
</ItemGroup>
2121

2222
<ItemGroup>
23-
<EmbeddedResource Include="Views\Blogifier\Admin\Packages\Themes.cshtml" />
24-
<EmbeddedResource Include="Views\Blogifier\Admin\Packages\Widgets.cshtml" />
25-
<EmbeddedResource Include="wwwroot\admin\js\app\packagesController.js" />
23+
<EmbeddedResource Include="Views\Blogifier\**\Single.cshtml" />
2624
</ItemGroup>
2725

2826
<ItemGroup>
@@ -34,8 +32,4 @@
3432
<Exec Command="xcopy &quot;$(SolutionDir)Packages\Widgets\PostList\bin\Debug\netcoreapp2.0\PostList.dll&quot; &quot;$(TargetDir)&quot; /Y" />
3533
</Target>
3634

37-
<ItemGroup>
38-
<Folder Include="Logs\" />
39-
</ItemGroup>
40-
41-
</Project>
35+
</Project>

0 commit comments

Comments
 (0)