-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMarkdown.Videos.cs
More file actions
61 lines (52 loc) · 2 KB
/
Copy pathMarkdown.Videos.cs
File metadata and controls
61 lines (52 loc) · 2 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
// BSD License: https://docs.servicestack.net/BSD-LICENSE.txt
// run node postinstall.js to update to latest version
using ServiceStack.IO;
namespace MyApp;
public class MarkdownVideos(ILogger<MarkdownVideos> log, IWebHostEnvironment env, IVirtualFiles fs)
: MarkdownPagesBase<MarkdownFileInfo>(log, env, fs)
{
public override string Id => "videos";
public Dictionary<string, List<MarkdownFileInfo>> Groups { get; set; } = new();
public List<MarkdownFileInfo> GetVideos(string group)
{
return Groups.TryGetValue(group, out var docs)
? Fresh(docs.Where(IsVisible).OrderBy(x => x.Order).ThenBy(x => x.FileName).ToList())
: [];
}
public void LoadFrom(string fromDirectory)
{
Groups.Clear();
var dirs = VirtualFiles.GetDirectory(fromDirectory).GetDirectories().ToList();
log.LogInformation("Found {Count} video directories", dirs.Count);
var pipeline = CreatePipeline();
foreach (var dir in dirs)
{
var group = dir.Name;
foreach (var file in dir.GetFiles().OrderBy(x => x.Name))
{
try
{
var doc = Load(file.VirtualPath, pipeline);
if (doc == null)
continue;
doc.Group = group;
var groupVideos = Groups.GetOrAdd(group, v => new List<MarkdownFileInfo>());
groupVideos.Add(doc);
}
catch (Exception e)
{
log.LogError(e, "Couldn't load {VirtualPath}: {Message}", file.VirtualPath, e.Message);
}
}
}
}
public override List<MarkdownFileBase> GetAll()
{
var to = new List<MarkdownFileBase>();
foreach (var entry in Groups)
{
to.AddRange(entry.Value.Where(IsVisible).Map(doc => ToMetaDoc(doc, x => x.Content = StripFrontmatter(doc.Content))));
}
return to;
}
}