fix ordering of stylesheets

This commit is contained in:
sbwalker 2023-06-23 08:07:06 -04:00
parent ee4068d671
commit 2ff365765d
2 changed files with 26 additions and 26 deletions

View File

@ -15,6 +15,7 @@
{
<link id="app-manifest" rel="manifest" />
}
@Html.Raw(Model.StyleSheets)
<link id="app-stylesheet-page" />
<link id="app-stylesheet-module" />
<component type="typeof(Oqtane.Head)" render-mode="@((RenderMode)Enum.Parse(typeof(RenderMode), Model.RenderMode, true))" />

View File

@ -21,7 +21,6 @@ using Oqtane.Security;
using Oqtane.Extensions;
using Oqtane.Themes;
using System.Collections.Generic;
using Oqtane.UI;
namespace Oqtane.Pages
{
@ -69,6 +68,7 @@ namespace Oqtane.Pages
public string RemoteIPAddress = "";
public string HeadResources = "";
public string BodyResources = "";
public string StyleSheets = "";
public string PWAScript = "";
public string ReconnectScript = "";
public string Message = "";
@ -167,26 +167,29 @@ namespace Oqtane.Pages
}
// stylesheets
var resources = new List<Resource>();
if (string.IsNullOrEmpty(page.ThemeType))
if (!HttpContext.Request.Query.ContainsKey("method") || (HttpContext.Request.Query.ContainsKey("method") && HttpContext.Request.Query["method"] == "old"))
{
page.ThemeType = site.DefaultThemeType;
}
var theme = site.Themes.FirstOrDefault(item => item.Themes.Any(item => item.TypeName == page.ThemeType));
if (theme?.Resources != null)
{
resources.AddRange(theme.Resources.Where(item => item.ResourceType == ResourceType.Stylesheet).ToList());
}
var type = Type.GetType(page.ThemeType);
if (type != null)
{
var obj = Activator.CreateInstance(type) as IThemeControl;
if (obj?.Resources != null)
var resources = new List<Resource>();
if (string.IsNullOrEmpty(page.ThemeType))
{
resources.AddRange(obj.Resources.Where(item => item.ResourceType == ResourceType.Stylesheet).ToList());
page.ThemeType = site.DefaultThemeType;
}
var theme = site.Themes.FirstOrDefault(item => item.Themes.Any(item => item.TypeName == page.ThemeType));
if (theme?.Resources != null)
{
resources.AddRange(theme.Resources.Where(item => item.ResourceType == ResourceType.Stylesheet).ToList());
}
var type = Type.GetType(page.ThemeType);
if (type != null)
{
var obj = Activator.CreateInstance(type) as IThemeControl;
if (obj?.Resources != null)
{
resources.AddRange(obj.Resources.Where(item => item.ResourceType == ResourceType.Stylesheet).ToList());
}
}
ManageStyleSheets(resources, alias, theme.ThemeName);
}
ManageResources(resources, alias, theme.ThemeName);
// scripts
if (Runtime == "Server")
@ -494,7 +497,7 @@ namespace Oqtane.Pages
CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture)));
}
private void ManageResources(List<Resource> resources, Alias alias, string name)
private void ManageStyleSheets(List<Resource> resources, Alias alias, string name)
{
if (resources != null)
{
@ -510,15 +513,11 @@ namespace Oqtane.Pages
resource.Url = alias.BaseUrl + resource.Url;
}
if (!HeadResources.Contains(resource.Url, StringComparison.OrdinalIgnoreCase))
if (!StyleSheets.Contains(resource.Url, StringComparison.OrdinalIgnoreCase))
{
string id = "";
if (!HttpContext.Request.Query.ContainsKey("method") || (HttpContext.Request.Query.ContainsKey("method") && HttpContext.Request.Query["method"] == "old"))
{
count++;
id = "id=\"app-stylesheet-" + ResourceLevel.Page.ToString().ToLower() + "-" + DateTime.UtcNow.ToString("yyyyMMddHHmmssfff") + "-" + count.ToString("00") + "\" ";
}
HeadResources += "<link " + id + "rel=\"stylesheet\" href=\"" + resource.Url + "\"" + (!string.IsNullOrEmpty(resource.Integrity) ? " integrity=\"" + resource.Integrity + "\"" : "") + (!string.IsNullOrEmpty(resource.CrossOrigin) ? " crossorigin=\"" + resource.CrossOrigin + "\"" : "") + " type=\"text/css\"/>" + Environment.NewLine;
count++;
string id = "id=\"app-stylesheet-" + ResourceLevel.Page.ToString().ToLower() + "-" + DateTime.UtcNow.ToString("yyyyMMddHHmmssfff") + "-" + count.ToString("00") + "\" ";
StyleSheets += "<link " + id + "rel=\"stylesheet\" href=\"" + resource.Url + "\"" + (!string.IsNullOrEmpty(resource.Integrity) ? " integrity=\"" + resource.Integrity + "\"" : "") + (!string.IsNullOrEmpty(resource.CrossOrigin) ? " crossorigin=\"" + resource.CrossOrigin + "\"" : "") + " type=\"text/css\"/>" + Environment.NewLine;
}
}
}