-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
299 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
MyApp/Components/Pages/Posts/All.razor → MyApp/Components/Pages/Posts/Index.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
@page "/posts/all" | ||
@page "/posts/" | ||
@inject MarkdownBlog Blog | ||
@inject AppConfig AppConfig | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using ServiceStack.IO; | ||
using ServiceStack.Text; | ||
|
||
namespace MyApp; | ||
|
||
public class MarkdownMeta | ||
{ | ||
public List<IMarkdownPages> Features { get; set; } = []; | ||
|
||
public async Task RenderToAsync(string metaDir, string baseUrl) | ||
{ | ||
FileSystemVirtualFiles.RecreateDirectory(metaDir); | ||
using var scope = JsConfig.With(new Config { ExcludeTypeInfo = true }); | ||
var featureDocs = new Dictionary<string, List<MarkdownFileBase>>(); | ||
var allYears = new HashSet<int>(); | ||
var index = new Dictionary<string, object>(); | ||
foreach (var feature in Features.Safe()) | ||
{ | ||
var allDocs = feature.GetAll() | ||
.OrderByDescending(x => x.Date!.Value) | ||
.ThenBy(x => x.Order) | ||
.ThenBy(x => x.FileName) | ||
.ToList(); | ||
allDocs.ForEach(x => { | ||
if (x.Url?.StartsWith("/") == true) | ||
x.Url = baseUrl.CombineWith(x.Url); | ||
if (x.Image?.StartsWith("/") == true) | ||
x.Image = baseUrl.CombineWith(x.Image); | ||
}); | ||
featureDocs[feature.Id] = allDocs; | ||
var featureYears = allDocs.Select(x => x.Date!.Value.Year).Distinct().OrderBy(x => x).ToList(); | ||
featureYears.ForEach(x => allYears.Add(x)); | ||
|
||
index[feature.Id] = featureYears.Map(x => baseUrl.CombineWith($"/meta/{x}/{feature.Id}.json")); | ||
foreach (var year in featureYears) | ||
{ | ||
var yearDocs = allDocs | ||
.Where(x => x.Date!.Value.Year == year) | ||
.ToList(); | ||
var yearDir = metaDir.CombineWith(year).AssertDir(); | ||
var metaPath = yearDir.CombineWith($"{feature.Id}.json"); | ||
await File.WriteAllTextAsync(metaPath, yearDocs.ToJson()); | ||
} | ||
} | ||
await File.WriteAllTextAsync(metaDir.CombineWith("index.json"), JSON.stringify(index)); | ||
|
||
await File.WriteAllTextAsync(metaDir.CombineWith("all.json"), JSON.stringify(featureDocs)); | ||
foreach (var year in allYears.OrderBy(x => x)) | ||
{ | ||
var yearDocs = new Dictionary<string, List<MarkdownFileBase>>(); | ||
foreach (var entry in featureDocs) | ||
{ | ||
yearDocs[entry.Key] = entry.Value | ||
.Where(x => x.Date!.Value.Year == year) | ||
.ToList(); | ||
} | ||
await File.WriteAllTextAsync(metaDir.CombineWith($"{year}/all.json"), JSON.stringify(yearDocs)); | ||
} | ||
} | ||
} |
Oops, something went wrong.