-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
question: expected behavior for links from/to locations not in a current content collection #26
Comments
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:
|
I think reaching a decision on this one, especially given Astro v5 allowing content collections to live anywhere (see #74) is becoming more pressing. My thoughts, for now, are that the plugin only resolve relative references within the "current" collection directory. Any relative links to another collection or anywhere else would be skipped. Currently, #58 ensured that the link must be in a content collection directory but I think we take it step further and restrict to the "current" content collection directory. Although it could be done and likely done reliably, I think there are just too many possibilities and until there is stability with v5 and to limit potential issues, I think we still to "current collection" only. This would mean the answers to the questions I posed in my last comment are:
Let me know your thoughts. |
Sorry! I'll try to look at this one when I can (I've gotten through a few others though!) |
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?
The text was updated successfully, but these errors were encountered: