refactoring of #518 to simplify registration of scripts in modules and themes
This commit is contained in:
@ -30,27 +30,18 @@
|
||||
await interop.UpdateTitle(PageState.Site.Name + " - " + PageState.Page.Name);
|
||||
}
|
||||
|
||||
// include page resources
|
||||
// manage stylesheets for this page
|
||||
string batch = DateTime.Now.ToString("yyyyMMddHHmmssfff");
|
||||
var links = new List<object>();
|
||||
var scripts = new List<object>();
|
||||
foreach (Resource resource in PageState.Page.Resources)
|
||||
{
|
||||
switch (resource.ResourceType)
|
||||
if (resource.ResourceType == ResourceType.Stylesheet)
|
||||
{
|
||||
case ResourceType.Stylesheet:
|
||||
links.Add(new { id = "app-stylesheet-" + batch + "-" + (links.Count + 1).ToString("00"), rel = "stylesheet", href = resource.Url, type = "text/css", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", key = "" });
|
||||
break;
|
||||
case ResourceType.Script:
|
||||
scripts.Add(new { id = "app-script-" + batch + "-" + (scripts.Count + 1).ToString("00"), src = resource.Url, integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", content = "", location = "body", key = "" });
|
||||
break;
|
||||
links.Add(new { id = "app-stylesheet-" + batch + "-" + (links.Count + 1).ToString("00"), rel = "stylesheet", href = resource.Url, type = "text/css", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", key = "" });
|
||||
}
|
||||
}
|
||||
await interop.IncludeLinks(links.ToArray());
|
||||
await interop.IncludeScripts(scripts.ToArray());
|
||||
// remove any page resource references which are no longer required for this page
|
||||
await interop.RemoveElementsById("app-stylesheet", "", "app-stylesheet-" + batch + "-00");
|
||||
await interop.RemoveElementsById("app-script", "", "app-script-" + batch + "-00");
|
||||
|
||||
// add favicon
|
||||
if (PageState.Site.FaviconFileId != null)
|
||||
|
Reference in New Issue
Block a user