Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private void OnClickTheme(SelectedItem item)
{
_currentTheme.Clear();
WebsiteOption.CurrentValue.CurrentTheme = item.Value;
var theme = WebsiteOption.CurrentValue.Themes.Find(i => i.Key == item.Value);
var theme = WebsiteOption.CurrentValue.Themes.FirstOrDefault(i => i.Key == item.Value);
if (theme is { Files: not null })
{
_currentTheme.AddRange(theme.Files);
Expand Down
18 changes: 10 additions & 8 deletions src/BootstrapBlazor.Server/Data/WebsiteOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone

using System.Collections.Frozen;

namespace BootstrapBlazor.Server.Data;

/// <summary>
///
/// WebsiteOptions 网站配置类
/// </summary>
public class WebsiteOptions
{
Expand Down Expand Up @@ -102,12 +104,12 @@ public class WebsiteOptions
/// <summary>
/// 获得/设置 资源配置集合
/// </summary>
public Dictionary<string, string?> SourceCodes { get; private set; }
public FrozenDictionary<string, string?> SourceCodes { get; private set; }

/// <summary>
/// 获得/设置 资源配置集合
/// </summary>
public Dictionary<string, string?> Videos { get; private set; }
public FrozenDictionary<string, string?> Videos { get; private set; }

/// <summary>
/// 获得/设置 当前主题
Expand All @@ -127,23 +129,23 @@ public class WebsiteOptions
/// <summary>
/// 获得/设置 当前网站友联集合
/// </summary>
public Dictionary<string, string?> Links { get; set; }
public FrozenDictionary<string, string?> Links { get; set; }

/// <summary>
/// 获得/设置 网站主题配置集合
/// </summary>
[NotNull]
public List<ThemeOption>? Themes { get; set; }
public HashSet<ThemeOption>? Themes { get; set; }

/// <summary>
/// 构造函数
/// </summary>
public WebsiteOptions()
{
var config = GetConfiguration("docs.json");
SourceCodes = config.GetSection("src").GetChildren().Select(c => new KeyValuePair<string, string?>(c.Key, c.Value)).ToDictionary(item => item.Key, item => item.Value);
Videos = config.GetSection("video").GetChildren().Select(c => new KeyValuePair<string, string?>(c.Key, c.Value)).ToDictionary(item => item.Key, item => item.Value);
Links = config.GetSection("link").GetChildren().Select(c => new KeyValuePair<string, string?>(c.Key, c.Value)).ToDictionary(item => item.Key, item => item.Value);
SourceCodes = config.GetSection("src").GetChildren().Select(c => new KeyValuePair<string, string?>(c.Key, c.Value)).ToFrozenDictionary(item => item.Key, item => item.Value);
Videos = config.GetSection("video").GetChildren().Select(c => new KeyValuePair<string, string?>(c.Key, c.Value)).ToFrozenDictionary(item => item.Key, item => item.Value);
Links = config.GetSection("link").GetChildren().Select(c => new KeyValuePair<string, string?>(c.Key, c.Value)).ToFrozenDictionary(item => item.Key, item => item.Value);

#if DEBUG
IsDevelopment = true;
Expand Down
5 changes: 3 additions & 2 deletions src/BootstrapBlazor.Server/Services/CodeSnippetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone

using Microsoft.Extensions.Options;
using System.Collections.Frozen;

namespace BootstrapBlazor.Server.Services;

Expand All @@ -15,7 +16,7 @@ class CodeSnippetService

private string SourceCodePath { get; set; }

private Dictionary<string, string?> SourceCodes { get; set; }
private FrozenDictionary<string, string?> SourceCodes { get; set; }

private bool IsDevelopment { get; }

Expand Down Expand Up @@ -62,7 +63,7 @@ public async Task<string> GetCodeAsync(string codeFile)
// codeFile = ajax.razor.cs
var segs = codeFile.Split('.');
var key = segs[0];
var typeName = SourceCodes.TryGetValue(key, out var value) ? value : string.Empty;
var typeName = SourceCodes.TryGetValue(key.ToLowerInvariant(), out var value) ? value : string.Empty;
if (!string.IsNullOrEmpty(typeName))
{
var fileName = codeFile.Replace(key, typeName);
Expand Down
Loading