Open techfg opened 7 months ago
Changed this issue from "bug" to "question" after creating issue #57 which covers the specific situation regarding links to markdown outside of a content collection since current behavior to those will result in incorrect links being transformed.
The scenario and questions raised in this issue's OP still stands, however. Assuming PR #49 is merged, and preferrably #50 is merged and #53 implemented, links from anywhere to a markdown file within a content collection directory should be reliable. This means that question 1 & part of question 3 (outside collection dir linking to inside a collection dir) in this issue's OP are addressed - again, relies on at least #49 being merged to cover basic scenarios while PR #50 & addressing Issue #53 would provide the flexibility needed to support all known scenarios.
Repositioning this issue to clearly define expected behavior in all scenarios so that any remaining issues can be fixed and/or required gaps/features backlogged.
The questions are, what should occur in the following scenarios:
Currently, the plugin runs against ANY markdown file, even if the file exists outside of a content collection. However, there is logic in the plugin that assumes the file its processing is within a content collection. This yields three scenarios that could lead to issues:
Files within a content collection can reference files outside of its own content collection but within
contentDir
in another content collection. For example,src/content/posts/post-1.md
could contain a markdown link to../newsletter/post-1.md
(a different content collection). Currently, this transformation works IF the actual page path for the site to thenewsletter post-1
page includes the physical path name ofnewsletter
(e.g., /newsletter/post-1).Files within a content collection can reference files outside of the content directory entirely. For example,
src/content/posts/post-1.md
could contain a markdown link to../../pages/page-1.md
. Currently, this transformation fails because it transforms to/../pages/page-1
which is not a valid path.Files outside of the content collection can reference files inside or outside of a content collection. For example,
/pages/page-1.md
could contain a markdown link to../content/posts/post-1.md
. This scenario will fail because the transformed url will become/pages/post-1
I think there is something to be said for allowing the portability of file references to markdown files in/out/across pages, content collections, etc., however the current logic does not support it but does actually do a transformation.
The question on the table is what scenarios to support for file references to
{.md,.mdx}
files:contentDir
Repro: https://stackblitz.com/edit/github-pdzrjo-qqdlex
In the repro, there are two "Link" sections on each page to help navigate since a lot of links do not work because of the attempted transformations described above.
MD Links
- This section always points to the corresponding.md
file (e.g.,./page-1.md
)Explicit Links
- This section always points to the site relative root page (e.g.,/page-1
)Steps to reproduce:
MD Links
section, click any of the links starting withRoot
orSubdir
Expected Result: This is the question since this page is /pages/index.md and not in a content collection
Actual Result: Transformed url is based at
/pages
and all 404Newsletter 1
orPost 1
Expected Result: That is the question
Actual Result: Because of the physical directory structure is the same as the site url structure for the collection, the links actually work but if the directory structures were different, they would not
/pages/*
and/newsletter/*
and/posts/*
. They all contain the same set of links separated withMD Links
andExplicit Links
. All theexplicit links
work but only some of theMD Links
work based on physical directory structure, etc.My thought is that for v1, only links in/around a single content collection should be supported and everything else should fail the IsValidRelativeLink test. This would be consistent with how Astro treats content collections generally speaking.
See #27 as well since its somewhat related although still separate and distinct.
Thoughts?