Skip to content

Commit

Permalink
further refactoring of ManageStyleSheets
Browse files Browse the repository at this point in the history
  • Loading branch information
sbwalker committed Feb 19, 2024
1 parent 121a865 commit 4271289
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Oqtane.Server/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@
// initial stylesheets (to prevent FOUC in interactive rendering)
if (_renderMode == RenderModes.Interactive)
{
var themeType = (string.IsNullOrEmpty(page.ThemeType)) ? site.DefaultThemeType : page.ThemeType;
var theme = site.Themes.FirstOrDefault(item => item.Themes.Any(item => item.TypeName == themeType));
ManageStyleSheets(GetStyleSheetResources(site, page, theme), alias, theme.ThemeName);
ManageStyleSheets(alias, site, page);
}

// scripts
Expand Down Expand Up @@ -550,8 +548,12 @@
CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture)));
}

private void ManageStyleSheets(List<Resource> resources, Alias alias, string name)
private void ManageStyleSheets(Alias alias, Site site, Page page)
{
var themeType = (string.IsNullOrEmpty(page.ThemeType)) ? site.DefaultThemeType : page.ThemeType;
var theme = site.Themes.FirstOrDefault(item => item.Themes.Any(item => item.TypeName == themeType));
var resources = GetStyleSheetResources(page, theme);

if (resources != null)
{
string batch = DateTime.UtcNow.ToString("yyyyMMddHHmmssfff");
Expand All @@ -560,7 +562,7 @@
{
if (resource.Url.StartsWith("~"))
{
resource.Url = resource.Url.Replace("~", "/Themes/" + Utilities.GetTypeName(name) + "/").Replace("//", "/");
resource.Url = resource.Url.Replace("~", "/Themes/" + Utilities.GetTypeName(theme.ThemeName) + "/").Replace("//", "/");
}
if (!resource.Url.Contains("://") && alias.BaseUrl != "" && !resource.Url.StartsWith(alias.BaseUrl))
{
Expand All @@ -577,7 +579,7 @@
}
}

private List<Resource> GetStyleSheetResources(Site site, Page page, Theme theme)
private List<Resource> GetStyleSheetResources(Page page, Theme theme)
{
var resources = new List<Resource>();
if (theme?.Resources != null)
Expand Down

0 comments on commit 4271289

Please sign in to comment.