Get-NozGraph, Find-NozNote, Measure-NozGarden, Set-NozNoteStatus, Get-NozOrphans — graph edges, Meilisearch search, garden stats, frontmatter status patch, orphan detection from inbound link analysis.
38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using System.Management.Automation;
|
|
|
|
namespace Noz.PowerShell.Cmdlets;
|
|
|
|
[Cmdlet(VerbsCommon.Get, "NozGraph")]
|
|
[OutputType(typeof(NozGraphEdge))]
|
|
public sealed class GetNozGraphCmdlet : NozCmdletBase
|
|
{
|
|
[Parameter]
|
|
public string? Source { get; set; }
|
|
|
|
[Parameter]
|
|
public string? Target { get; set; }
|
|
|
|
protected override void ProcessRecord()
|
|
{
|
|
var graph = Run(Api.GetGraphAsync());
|
|
var nodeMap = graph.Nodes.ToDictionary(n => n.Id, n => n.Title);
|
|
|
|
var edges = graph.Edges.AsEnumerable();
|
|
|
|
if (Source is not null)
|
|
edges = edges.Where(e => e.Source.Contains(Source, StringComparison.OrdinalIgnoreCase));
|
|
if (Target is not null)
|
|
edges = edges.Where(e => e.Target.Contains(Target, StringComparison.OrdinalIgnoreCase));
|
|
|
|
foreach (var e in edges)
|
|
{
|
|
WriteObject(new NozGraphEdge
|
|
{
|
|
Source = e.Source,
|
|
Target = e.Target,
|
|
SourceTitle = nodeMap.GetValueOrDefault(e.Source, e.Source),
|
|
TargetTitle = nodeMap.GetValueOrDefault(e.Target, e.Target),
|
|
});
|
|
}
|
|
}
|
|
}
|