File tree Expand file tree Collapse file tree 6 files changed +57
-12
lines changed
Expand file tree Collapse file tree 6 files changed +57
-12
lines changed Original file line number Diff line number Diff line change 33 <PropertyGroup >
44 <TargetFramework >netcoreapp2.1</TargetFramework >
55 <MvcRazorExcludeRefAssembliesFromPublish >false</MvcRazorExcludeRefAssembliesFromPublish >
6- <MvcRazorCompileOnPublish >false </MvcRazorCompileOnPublish >
6+ <MvcRazorCompileOnPublish >true </MvcRazorCompileOnPublish >
77 </PropertyGroup >
88
99 <ItemGroup >
1313 <PackageReference Include =" Serilog.Sinks.RollingFile" Version =" 3.3.0" />
1414 </ItemGroup >
1515
16+ <ItemGroup >
17+ <EmbeddedResource Include =" Views\**\*" />
18+ </ItemGroup >
19+
1620 <ItemGroup >
1721 <ProjectReference Include =" ..\Core\Core.csproj" />
1822 </ItemGroup >
Original file line number Diff line number Diff line change 44using Microsoft . AspNetCore . Mvc ;
55using Microsoft . AspNetCore . Mvc . Rendering ;
66using System . Collections . Generic ;
7+ using System . Linq ;
78using System . Threading . Tasks ;
89
910namespace App . Pages . Admin . Settings
@@ -74,20 +75,28 @@ public IActionResult OnPost()
7475
7576 List < SelectListItem > GetThemes ( )
7677 {
77- var themes = new List < SelectListItem >
78- {
79- new SelectListItem { Text = "Simple" , Value = "Simple" }
80- } ;
78+ var themes = new List < SelectListItem > ( ) ;
79+ var combined = new List < string > ( ) ;
8180
8281 var storageThemes = _storage . GetThemes ( ) ;
8382
84- if ( storageThemes != null && storageThemes . Count > 0 )
83+ if ( storageThemes != null )
84+ combined . AddRange ( storageThemes ) ;
85+
86+ if ( AppConfig . EmbeddedThemes != null )
87+ combined . AddRange ( AppConfig . EmbeddedThemes ) ;
88+
89+ combined = combined . Distinct ( ) . ToList ( ) ;
90+ combined . Sort ( ) ;
91+
92+ if ( combined != null && combined . Count > 0 )
8593 {
86- foreach ( var theme in storageThemes )
94+ foreach ( var theme in combined )
8795 {
8896 themes . Add ( new SelectListItem { Text = theme , Value = theme } ) ;
8997 }
9098 }
99+
91100 return themes ;
92101 }
93102 }
Original file line number Diff line number Diff line change @@ -8,7 +8,9 @@ namespace Core
88{
99 public static class AppConfig
1010 {
11- public static IEnumerable < Assembly > GetAssemblies ( )
11+ public static IList < string > EmbeddedThemes { get ; set ; }
12+
13+ public static IEnumerable < Assembly > GetAssemblies ( bool includeApp = false )
1214 {
1315 var assemblies = new List < Assembly > ( ) ;
1416 try
@@ -18,8 +20,14 @@ public static IEnumerable<Assembly> GetAssemblies()
1820 try
1921 {
2022 var assembly = Assembly . LoadFile ( dll ) ;
21- var product = assembly . GetCustomAttribute < AssemblyProductAttribute > ( ) . Product ;
2223
24+ if ( ( dll . Contains ( "App.dll" ) ) && includeApp )
25+ {
26+ assemblies . Add ( assembly ) ;
27+ continue ;
28+ }
29+
30+ var product = assembly . GetCustomAttribute < AssemblyProductAttribute > ( ) . Product ;
2331 if ( product . StartsWith ( "Blogifier." ) )
2432 {
2533 assemblies . Add ( assembly ) ;
Original file line number Diff line number Diff line change 11using Microsoft . EntityFrameworkCore ;
22using System ;
3+ using System . Collections . Generic ;
34using System . Reflection ;
45
56namespace Core
Original file line number Diff line number Diff line change 22
33 <PropertyGroup >
44 <TargetFramework >netcoreapp2.1</TargetFramework >
5- <Version >2.0.1.9 </Version >
5+ <Version >2.0.2.0 </Version >
66 </PropertyGroup >
77
88 <ItemGroup >
Original file line number Diff line number Diff line change 99using Microsoft . Extensions . DependencyInjection . Extensions ;
1010using Microsoft . Extensions . FileProviders ;
1111using Microsoft . Extensions . Options ;
12+ using System . Collections . Generic ;
1213
1314namespace Core . Extensions
1415{
@@ -49,9 +50,31 @@ static void AddFileProviders(IServiceCollection services)
4950 {
5051 services . Configure < RazorViewEngineOptions > ( options =>
5152 {
52- foreach ( var assembly in AppConfig . GetAssemblies ( ) )
53+ foreach ( var assembly in AppConfig . GetAssemblies ( true ) )
5354 {
54- options . FileProviders . Add ( new EmbeddedFileProvider ( assembly , assembly . GetName ( ) . Name ) ) ;
55+ var fileProvider = new EmbeddedFileProvider ( assembly , assembly . GetName ( ) . Name ) ;
56+
57+ // load themes from embedded provider
58+ var content = fileProvider . GetDirectoryContents ( "" ) ;
59+ if ( content . Exists )
60+ {
61+ foreach ( var item in content )
62+ {
63+ if ( item . Name . StartsWith ( "Views.Themes" ) )
64+ {
65+ if ( AppConfig . EmbeddedThemes == null )
66+ AppConfig . EmbeddedThemes = new List < string > ( ) ;
67+
68+ var ar = item . Name . Split ( '.' ) ;
69+ if ( ar . Length > 2 && ! AppConfig . EmbeddedThemes . Contains ( ar [ 2 ] ) )
70+ {
71+ AppConfig . EmbeddedThemes . Add ( ar [ 2 ] ) ;
72+ }
73+ }
74+ }
75+ }
76+
77+ options . FileProviders . Add ( fileProvider ) ;
5578 }
5679 } ) ;
5780 }
You can’t perform that action at this time.
0 commit comments