Skip to content

Commit 464d1e0

Browse files
committed
Wiki v2, now with navigation and stuff
1 parent fc21c53 commit 464d1e0

File tree

18 files changed

+511
-23
lines changed

18 files changed

+511
-23
lines changed

.github/workflows/publish.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,33 @@ jobs:
1313
steps:
1414

1515
- uses: actions/checkout@v2
16-
16+
17+
- name: Setup Node.js environment
18+
uses: actions/[email protected]
19+
1720
# Wiki files: Compact Machines
1821
- uses: actions/checkout@v2
1922
with:
2023
repository: "compactmods/compactmachines.wiki"
2124
path: "Web/wwwroot/wiki-pages/machines"
2225
- run: rm -rf Web/wwwroot/wiki-pages/machines/.git
26+
- run: node Web/wwwroot/wiki-pages/wiki-pages.js Web/wwwroot/wiki-pages/machines
2327

2428
# Wiki files: Compact Crafting
2529
- uses: actions/checkout@v2
2630
with:
2731
repository: "compactmods/compactcrafting.wiki"
2832
path: "Web/wwwroot/wiki-pages/crafting"
2933
- run: rm -rf Web/wwwroot/wiki-pages/crafting/.git
34+
- run: node Web/wwwroot/wiki-pages/wiki-pages.js Web/wwwroot/wiki-pages/crafting
3035

3136
# sets up .NET Core SDK 3.1
3237
- name: Setup .NET Core SDK
3338
uses: actions/setup-dotnet@v1
3439
with:
3540
dotnet-version: '6.0.x'
41+
42+
3643

3744
# publishes Blazor project to the release-folder
3845
- name: Publish .NET Core Project

Web/Components/Markdown.razor

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<div class="markdown">
2+
@((MarkupString) Content)
3+
</div>
4+
5+
@inject IJSRuntime JS
6+
@code {
7+
[Parameter]
8+
public string Content { get; set; }
9+
10+
protected override async Task OnAfterRenderAsync(bool firstRender)
11+
{
12+
await JS.InvokeVoidAsync("Prism.highlightAll");
13+
}
14+
}

Web/Components/Markdown.razor.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
div.markdown pre {
2+
display: block;
3+
background-color: #2d2d2d !important;
4+
padding: 1rem;
5+
border-radius: 0.5rem;
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
div.markdown pre{display:block;background-color:#2d2d2d !important;padding:1rem;border-radius:.5rem;}

Web/Components/Markdown.razor.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
div.markdown pre {
2+
display: block;
3+
background-color: #2d2d2d !important;
4+
padding: 1rem;
5+
border-radius: 0.5rem;
6+
}

Web/Pages/WikiPage.razor

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
@page "/wiki/{project}/{route?}"
22
@using Markdig
3-
@using Markdig.SyntaxHighlighting
3+
@using Markdig.Prism
44
@using Web.Services
5+
56
@inject HttpClient Http
67
@inject ProjectsService Projects
78

@@ -23,14 +24,27 @@ else
2324
}
2425
else
2526
{
26-
@if (mdSource != null)
27-
{
28-
@((MarkupString) mdSource)
29-
}
30-
else
31-
{
32-
<p>Route not found; please check the URL and try again, or <a href="/wiki">go back to the wiki root</a>.</p>
33-
}
27+
<div class="wiki-page">
28+
<nav class="wiki-nav">
29+
<ul>
30+
@foreach (var p in ProjectPages.OrderBy(x => x.Slug))
31+
{
32+
<li><a href="/wiki/@Project/@p.Slug">@PrettyPageTitle(p)</a></li>
33+
}
34+
</ul>
35+
</nav>
36+
37+
<main class="wiki-main">
38+
@if (mdSource != null)
39+
{
40+
<Web.Components.Markdown Content="@mdSource" />
41+
}
42+
else
43+
{
44+
<p>Route not found; please check the URL and try again, or <a href="/wiki">go back to the wiki root</a>.</p>
45+
}
46+
</main>
47+
</div>
3448
}
3549
}
3650

@@ -41,6 +55,8 @@ else
4155
[Parameter]
4256
public string? Route { get; set; }
4357

58+
public ICollection<ProjectsService.WikiPage> ProjectPages { get; set; } = Array.Empty<ProjectsService.WikiPage>();
59+
4460
public string? mdSource;
4561

4662
public bool IsErrored = false;
@@ -52,7 +68,7 @@ else
5268
if (string.IsNullOrWhiteSpace(Route))
5369
Route = "home";
5470

55-
if(string.IsNullOrEmpty(Project))
71+
if (string.IsNullOrEmpty(Project))
5672
{
5773
IsErrored = true;
5874
IsLoading = false;
@@ -61,7 +77,7 @@ else
6177
}
6278

6379
var projList = await Projects.GetProjectSlugs();
64-
if(!projList.Contains(Project, StringComparer.InvariantCultureIgnoreCase))
80+
if (!projList.Contains(Project, StringComparer.InvariantCultureIgnoreCase))
6581
{
6682
IsErrored = true;
6783
IsLoading = false;
@@ -71,17 +87,34 @@ else
7187

7288
if (!string.IsNullOrEmpty(Project) && !string.IsNullOrEmpty(Route))
7389
{
74-
var source = $"wiki-pages/{Project}/{Route}.md";
75-
var sourceStr = await Http.GetAsync(source);
76-
if (sourceStr.IsSuccessStatusCode)
90+
this.ProjectPages = await Projects.GetPagesForProject(Project.ToLower());
91+
if (ProjectPages.Count == 0)
92+
{
93+
IsErrored = true;
94+
CustomError = "Requested page not found.";
95+
}
96+
else
7797
{
78-
var pl = new Markdig.MarkdownPipelineBuilder()
79-
.UseAdvancedExtensions()
80-
.UseSyntaxHighlighting()
81-
.Build();
98+
var source = ProjectPages.Where(x => x.Slug.Equals(Route, StringComparison.InvariantCultureIgnoreCase)).ToArray();
99+
if (source.Length == 0)
100+
{
101+
IsErrored = true;
102+
CustomError = "Requested page not found.";
103+
}
104+
else
105+
{
106+
var sourceStr = await Http.GetAsync($"wiki-pages/{Project}/{source[0].Original}");
107+
if (sourceStr.IsSuccessStatusCode)
108+
{
109+
var pl = new Markdig.MarkdownPipelineBuilder()
110+
.UseAdvancedExtensions()
111+
.UsePrism()
112+
.Build();
82113

83-
var mdSourceStr = await sourceStr.Content.ReadAsStringAsync();
84-
mdSource = Markdown.ToHtml(mdSourceStr, pl);
114+
var mdSourceStr = await sourceStr.Content.ReadAsStringAsync();
115+
mdSource = Markdig.Markdown.ToHtml(mdSourceStr, pl);
116+
}
117+
}
85118
}
86119

87120
IsLoading = false;
@@ -92,4 +125,10 @@ else
92125
IsLoading = false;
93126
}
94127
}
128+
129+
public string PrettyPageTitle(ProjectsService.WikiPage page)
130+
{
131+
var or = page.Original;
132+
return or.Replace('-', ' ').Substring(0, or.Length - 3);
133+
}
95134
}

Web/Pages/WikiPage.razor.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
div.wiki-page {
2+
display: flex;
3+
flex-direction: row;
4+
flex-wrap: nowrap;
5+
}
6+
7+
nav.wiki-nav {
8+
width: 30rem;
9+
margin-right: 1.6rem;
10+
padding: 1rem;
11+
background-color: lightslategray;
12+
color: white;
13+
border-radius: 0.5rem;
14+
}
15+
nav.wiki-nav ul {
16+
list-style: none;
17+
margin: 0;
18+
padding: 0;
19+
}
20+
nav.wiki-nav li {
21+
margin-bottom: 0.6em;
22+
}
23+
nav.wiki-nav a {
24+
text-decoration: none;
25+
color: currentColor;
26+
}

Web/Pages/WikiPage.razor.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Web/Pages/WikiPage.razor.scss

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
div.wiki-page {
2+
display: flex;
3+
flex-direction: row;
4+
flex-wrap: nowrap;
5+
}
6+
7+
nav.wiki-nav {
8+
width: 30rem;
9+
margin-right: 1.6rem;
10+
padding: 1rem;
11+
background-color: lightslategray;
12+
color: white;
13+
border-radius: .5rem;
14+
15+
ul {
16+
list-style: none;
17+
margin: 0;
18+
padding: 0;
19+
}
20+
21+
li {
22+
margin-bottom: .6em;
23+
}
24+
25+
a {
26+
text-decoration: none;
27+
color: currentColor;
28+
}
29+
}

Web/Services/ProjectsService.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,25 @@ public async Task<ICollection<Project>> GetProjects()
2727
return Array.Empty<Project>();
2828
}
2929

30+
public async Task<ICollection<WikiPage>> GetPagesForProject(string project)
31+
{
32+
var root = await Client.GetAsync($"wiki-pages/{project}/project.json");
33+
if (root.IsSuccessStatusCode && root.Content is not null)
34+
return await root.Content.ReadFromJsonAsync<ICollection<WikiPage>>();
35+
36+
return Array.Empty<WikiPage>();
37+
}
38+
3039
public struct Project
3140
{
3241
public string Name { get; set; }
3342
public string Slug { get; set; }
3443
}
44+
45+
public struct WikiPage
46+
{
47+
public string Original { get; set; }
48+
public string Slug { get; set; }
49+
}
3550
}
3651
}

0 commit comments

Comments
 (0)