Skip to content

Commit

Permalink
Merge pull request #118 from Lombiq/issue/LMBQ-346
Browse files Browse the repository at this point in the history
LMBQ-346: Fixing Links attribute
  • Loading branch information
MZole authored Jun 5, 2024
2 parents 4b603e6 + 74b24cf commit ab3e223
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Lombiq.BaseTheme.Samples/Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)]

Expand Down
10 changes: 8 additions & 2 deletions Lombiq.BaseTheme/Attributes/DerivedThemeAttribute.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -12,9 +14,13 @@ namespace Lombiq.BaseTheme.Attributes;
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
public sealed class DerivedThemeAttribute : ThemeAttribute
{
public IEnumerable<LinkEntry> Links { get; set; }
public string LinksJson { get; set; }
public string Favicon { get; set; }

public IEnumerable<LinkEntry> Links => LinksJson == null
? Enumerable.Empty<LinkEntry>()
: JsonSerializer.Deserialize<IEnumerable<LinkEntry>>(LinksJson);

public DerivedThemeAttribute() =>
BaseTheme = FeatureIds.BaseTheme;
}
9 changes: 8 additions & 1 deletion Lombiq.BaseTheme/Services/IconResourceFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using OrchardCore.Themes.Services;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Lombiq.BaseTheme.Services;

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ab3e223

Please sign in to comment.