NoteLinkHelper inserts wikilinks into an existing 'Siehe auch' section
or appends one. ApplyPlaceholders fills {{title}}/{{date}}/{{topic}} in
template bodies. new --template <name> fetches a server-side template
before opening the editor. SlugGuard moved to NozCli.Core in a previous
session — remove stale copy from NozCli.
43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using System.Management.Automation;
|
|
using NozCli.Core.Client;
|
|
|
|
namespace Noz.PowerShell.Cmdlets;
|
|
|
|
[Cmdlet(VerbsCommon.Add, "NozLink", SupportsShouldProcess = true)]
|
|
public sealed class AddNozLinkCmdlet : NozCmdletBase
|
|
{
|
|
[Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true)]
|
|
public string Source { get; set; } = "";
|
|
|
|
[Parameter(Mandatory = true, Position = 1)]
|
|
public string Target { get; set; } = "";
|
|
|
|
[Parameter]
|
|
public SwitchParameter Both { get; set; }
|
|
|
|
[Parameter]
|
|
public string Section { get; set; } = "Siehe auch";
|
|
|
|
protected override void ProcessRecord()
|
|
{
|
|
if (!ShouldProcess(Source, $"Add-NozLink → {Target}")) return;
|
|
|
|
LinkOne(Source, Target);
|
|
if (Both) LinkOne(Target, Source);
|
|
}
|
|
|
|
private void LinkOne(string source, string target)
|
|
{
|
|
var note = Run(Api.GetNoteAsync(source));
|
|
var updated = NoteLinkHelper.AddLink(note.Markdown, target, Section);
|
|
|
|
if (updated == note.Markdown)
|
|
{
|
|
WriteVerbose($"{source} → {target}: bereits verlinkt.");
|
|
return;
|
|
}
|
|
|
|
Run(Api.PutNoteAsync(source, updated));
|
|
WriteVerbose($"{source} → {target}: verlinkt.");
|
|
}
|
|
}
|