Website icon indicating copy to clipboard operation
Website copied to clipboard

Error when using the example to change the default cross reference name

Open flcdrg opened this issue 6 months ago • 1 comments

I get an error logged when I try and use the example from https://www.statiq.dev/guide/web/content-files/links-and-cross-references#changing-the-default-cross-reference-name (specifically the _directory.yml one)

Xref: => Config.FromDocument(doc => doc.Destination.FileNameWithoutExtension.Replace(' ', '-'))

Error:

[ERRO] 1 errors compiling script:
Line 1: CS1929: 'NormalizedPath' does not contain a definition for 'Replace' and the best extension method overload 'MemoryExtensions.Replace(in Memory<char>, char, char)' requires a receiver of type 'in Memory<char>'
[ERRO] Content/PostProcess » RenderContentPostProcessTemplates » ResolveXrefs » Exception of type 'Statiq.Core.ScriptCompilationException' was thrown.
[ERRO] Archives/PostProcess » ExecuteSwitch » RenderContentPostProcessTemplates » ResolveXrefs » Exception of type 'Statiq.Core.ScriptCompilationException' was thrown.

I changed the setting to this (adding the .GetTitle()) and the error was resolved:

Xref: => Config.FromDocument(doc => doc.Destination.FileNameWithoutExtension.GetTitle().Replace(' ', '-'))

flcdrg avatar Dec 30 '23 06:12 flcdrg

If that is the correct fix I'm happy to raise a PR

flcdrg avatar Dec 30 '23 10:12 flcdrg