Repository navigation
Expand file tree
/
Copy pathSiteNavigation.cs
More file actions
64 lines (59 loc) · 2.33 KB
/
Copy pathSiteNavigation.cs
File metadata and controls
64 lines (59 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Linq;
namespace MahApps.Docs
{
/// <summary>
/// The grouping behind the top navigation and the left sidebar.
/// </summary>
/// <remarks>
/// The page tree cannot express it: Dialogs and Helper Classes are siblings
/// of Controls, not children. Both _RightNavigation.cshtml and
/// _Sidebar.cshtml read it from here so the two never drift apart.
/// </remarks>
public static class SiteNavigation
{
/// <summary>
/// Each group, keyed by the section that heads it. The first entry of a
/// group is also its top level navigation entry.
/// </summary>
public static readonly string[][] Groups =
{
new[] { "docs/controls", "docs/dialogs", "docs/helper" },
new[] { "docs/styles", "docs/themes", "docs/stylevariants" },
new[] { "docs/guides" }
};
/// <summary>
/// The group the given output path belongs to, or <c>null</c> when the
/// page sits outside the grouped sections (the home page, About, the
/// API reference).
/// </summary>
/// <param name="destination">
/// The rendered page's output path, with or without a leading slash,
/// for example <c>docs/controls/splitview.html</c>.
/// </param>
public static string[]? GroupOf(string? destination)
{
if (string.IsNullOrEmpty(destination))
{
return null;
}
string path = destination.TrimStart('/');
return Groups.FirstOrDefault(group => group.Any(section => IsInSection(path, section)));
}
/// <summary>
/// Whether the given output path is the index of <paramref name="section"/>
/// or one of the pages below it.
/// </summary>
public static bool IsInSection(string? destination, string section)
{
if (string.IsNullOrEmpty(destination))
{
return false;
}
string path = destination.TrimStart('/');
return path.Equals(section + "/index.html", StringComparison.OrdinalIgnoreCase)
|| path.Equals(section + ".html", StringComparison.OrdinalIgnoreCase)
|| path.StartsWith(section + "/", StringComparison.OrdinalIgnoreCase);
}
}
}