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" /> <link id="app-manifest" rel="manifest" />
} }
@Html.Raw(Model.StyleSheets)
<link id="app-stylesheet-page" /> <link id="app-stylesheet-page" />
<link id="app-stylesheet-module" /> <link id="app-stylesheet-module" />
<component type="typeof(Oqtane.Head)" render-mode="@((RenderMode)Enum.Parse(typeof(RenderMode), Model.RenderMode, true))" /> <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.Extensions;
using Oqtane.Themes; using Oqtane.Themes;
using System.Collections.Generic; using System.Collections.Generic;
using Oqtane.UI;
namespace Oqtane.Pages namespace Oqtane.Pages
{ {
@ -69,6 +68,7 @@ namespace Oqtane.Pages
public string RemoteIPAddress = ""; public string RemoteIPAddress = "";
public string HeadResources = ""; public string HeadResources = "";
public string BodyResources = ""; public string BodyResources = "";
public string StyleSheets = "";
public string PWAScript = ""; public string PWAScript = "";
public string ReconnectScript = ""; public string ReconnectScript = "";
public string Message = ""; public string Message = "";
@ -167,6 +167,8 @@ namespace Oqtane.Pages
} }
// stylesheets // stylesheets
if (!HttpContext.Request.Query.ContainsKey("method") || (HttpContext.Request.Query.ContainsKey("method") && HttpContext.Request.Query["method"] == "old"))
{
var resources = new List<Resource>(); var resources = new List<Resource>();
if (string.IsNullOrEmpty(page.ThemeType)) if (string.IsNullOrEmpty(page.ThemeType))
{ {
@ -186,7 +188,8 @@ namespace Oqtane.Pages
resources.AddRange(obj.Resources.Where(item => item.ResourceType == ResourceType.Stylesheet).ToList()); resources.AddRange(obj.Resources.Where(item => item.ResourceType == ResourceType.Stylesheet).ToList());
} }
} }
ManageResources(resources, alias, theme.ThemeName); ManageStyleSheets(resources, alias, theme.ThemeName);
}
// scripts // scripts
if (Runtime == "Server") if (Runtime == "Server")
@ -494,7 +497,7 @@ namespace Oqtane.Pages
CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture))); 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) if (resources != null)
{ {
@ -510,15 +513,11 @@ namespace Oqtane.Pages
resource.Url = alias.BaseUrl + resource.Url; 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++; count++;
id = "id=\"app-stylesheet-" + ResourceLevel.Page.ToString().ToLower() + "-" + DateTime.UtcNow.ToString("yyyyMMddHHmmssfff") + "-" + count.ToString("00") + "\" "; 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;
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;
} }
} }
} }