diff --git a/Lombiq.BaseTheme.Samples/Manifest.cs b/Lombiq.BaseTheme.Samples/Manifest.cs index 29ccf98..83524b1 100644 --- a/Lombiq.BaseTheme.Samples/Manifest.cs +++ b/Lombiq.BaseTheme.Samples/Manifest.cs @@ -11,7 +11,9 @@ Website = "https://github.com/Lombiq/Orchard-Base-Theme", Description = "A sample theme that builds on Lombiq Base Theme.", // This is a new property in DerivedTheme. By setting it to a static resource you can define a default icon for this - // theme. You can define other "link" resources too, using the Link property. + // theme. You can define other "link" resources too, using the LinkJson property. They should be valid Json strings. + // For example: + // LinksJson = "[{\"Href\": \"~/example/style.css\", \"Rel\": \"stylesheet\"}]" Favicon = "~/Lombiq.BaseTheme.Samples/icons/favicon.ico" )] diff --git a/Lombiq.BaseTheme/Attributes/DerivedThemeAttribute.cs b/Lombiq.BaseTheme/Attributes/DerivedThemeAttribute.cs index d5f47a5..aafb917 100644 --- a/Lombiq.BaseTheme/Attributes/DerivedThemeAttribute.cs +++ b/Lombiq.BaseTheme/Attributes/DerivedThemeAttribute.cs @@ -1,8 +1,10 @@ -using Lombiq.BaseTheme.Constants; +using Lombiq.BaseTheme.Constants; using OrchardCore.DisplayManagement.Manifest; using OrchardCore.ResourceManagement; using System; using System.Collections.Generic; +using System.Linq; +using System.Text.Json; namespace Lombiq.BaseTheme.Attributes; @@ -12,9 +14,13 @@ namespace Lombiq.BaseTheme.Attributes; [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)] public sealed class DerivedThemeAttribute : ThemeAttribute { - public IEnumerable Links { get; set; } + public string LinksJson { get; set; } public string Favicon { get; set; } + public IEnumerable Links => LinksJson == null + ? Enumerable.Empty() + : JsonSerializer.Deserialize>(LinksJson); + public DerivedThemeAttribute() => BaseTheme = FeatureIds.BaseTheme; } diff --git a/Lombiq.BaseTheme/Services/IconResourceFilter.cs b/Lombiq.BaseTheme/Services/IconResourceFilter.cs index f2b4f00..861c2b8 100644 --- a/Lombiq.BaseTheme/Services/IconResourceFilter.cs +++ b/Lombiq.BaseTheme/Services/IconResourceFilter.cs @@ -8,6 +8,7 @@ using OrchardCore.Themes.Services; using System; using System.Collections.Generic; +using System.Linq; namespace Lombiq.BaseTheme.Services; @@ -47,7 +48,13 @@ public void AddResourceFilter(ResourceFilterBuilder builder) => AddIcon(resourceManager, icon); } - theme.Links?.ForEach(resourceManager.RegisterLink); + var themeLinks = theme.Links; + + if (themeLinks?.Any() == true) + { + themeLinks.ForEach(linkEntry => linkEntry.Href = _orchardHelper.ResourceUrl(linkEntry.Href)); + themeLinks.ForEach(resourceManager.RegisterLink); + } } // If the site setting icon is set, that should take priority.