statiqdev / Statiq.Web

Statiq Web is a flexible static site generator written in .NET.
https://statiq.dev/web
Other
1.64k stars 234 forks source link

Multiple ambiguous matching documents found for xref starting 1.0.0-beta.45 #988

Closed zivkan closed 2 years ago

zivkan commented 2 years ago

I'm not sure if it's Statiq.Web, or Statiq.Framework that introduced the regression, but a project using Statiq.Web 1.0.0-beta.45 or 46, using the CleanBlog theme, will fail if you try to link any blog post to another blog post:

[ERRO] Archives/PostProcess » ExecuteSwitch » RenderContentPostProcessTemplates » ResolveXrefs » 1 xref resolution failures:
C:/src/test/NotWorking/theme/input/index.cshtml
 - Multiple ambiguous matching documents found for xref "first"
[ERRO] Content/PostProcess » RenderContentPostProcessTemplates » ResolveXrefs » 1 xref resolution failures:
C:/src/test/NotWorking/input/posts/second.md
 - Multiple ambiguous matching documents found for xref "first"
[ERRO] Archives/PostProcess » ExecuteSwitch » RenderContentPostProcessTemplates » ResolveXrefs » Encountered some invalid xrefs
[ERRO] Content/PostProcess » RenderContentPostProcessTemplates » ResolveXrefs » Encountered some invalid xrefs

Putting a breakpoint here: https://github.com/statiqdev/Statiq.Web/blob/0a4e0ba8b318615674e2dea1fa5cf4dcc12a3887/src/Statiq.Web/IExecutionContextXrefExtensions.cs#L30-L35

The variable matches has 3 documents, but all pointing to the same source: image

That's as far as I got with debugging.

If I change my project's PackageReference for Statiq.Web to 1.0.0-beta.44, then I no longer get the error.

daveaglick commented 2 years ago

Thanks for the report! This is probably Statiq Web since that's where the xref functionality is, and possibly related to some work that happened in there to support xrefs to API documents as part of Statiq Docs.

I'll move this and tag as a bug and take a look. Stay tuned.

daveaglick commented 2 years ago

Identified and fixed, rolling out a new release now.

This was caused by a change to expand the pipelines that we look at for locating xrefs. In and of itself, that change was good because it means you can reference documents from custom pipelines (this ability was introduced in Statiq Web 1.0.0-beta.45 which is where you noticed it breaking). The not-good part was that the routine to find referenced documents "flattened" the document hierarchy so that nested documents were also considered. Since the archive pipeline nests the documents-per-page, the blog posts were turning up in the xref matches for every archive page they appeared on. This behavior doesn't make sense anyway since a xref is presumably to a document that got output, and we only output top-level documents to disk. Changing the behavior not to flatten document trees resolved the issue.