Comments (15)
Oh okay, I think I got it. So instead of internally resolving the directory to the readme file as I suggested, we'd do it the other way around and internally copy over the found anchors from each readme to its corresponding directory?
from remark-validate-links.
Sounds good. I'll take a look and attach a PR if I manage to wrap my head around it. ๐
from remark-validate-links.
Alright, potential case of YAGNI detected. ๐
from remark-validate-links.
By the way, here is the markdown file that I added to my branch for future tests of this feature. All links containing the term "invalid" should produce some kind of warning, all others should pass.
(The link to the project root at the end of the file might be a bit odd, but it's there to prevent regression of a currently present bug: Linking to the project root at some point leads to effectively calling path.relative(baseFolder, baseFolder)
, which results in the empty string. That empty string is in turn used as the path
for a vfile, which causes a runtime error.)
from remark-validate-links.
This wonโt be trivial, but, may be doable, and is useful!
-
Here, new files are added on the CLI:
remark-validate-links/lib/find/find.js
Line 79 in f613df5
-
Here, files are accessed. We could use
fs.stats
instead. Stats has a method.isDirectory
that could be used to find out that something is a folder and that we need to find out which readme file is probably uses:remark-validate-links/lib/check/check-files.js
Lines 29 to 35 in 13a54a5
-
The file extensions to support for readmes are documented in
github/markup
. For the file name,/^readme$/i
should be fine. On the CLI, we use: -
Maybe you are right about older-file-first! That would be difficult. I was thinking that maybe they do alpha-sort, and prefer the first? That suggests why
.asciidoc
is preferred here. I would say to ignore all non-markdown extensions entirely. This is a markdown project. People using it will probably only use Markdown. -
What may be hard is that we now have URLs to things (
/path/to/folder#heading
) and (/path/to/folder/readme.md#heading
) that are populated from different URLs: (/path/to/folder/readme.md#heading
). Maybe a solution is, for every/^readme.md$/i
file, to also expose URLs to its folder?
from remark-validate-links.
I was thinking that maybe they do alpha-sort, and prefer the first?
I just tested again, and you're absolutely correct. Either my memory trolled me or GitHub changed this.
I would say to ignore all non-markdown extensions entirely.
Definitely. But GitHub still allows you to have a README.md
and a readme.md
in the same folder. However, README.md
is always preferred, so apparently alphasort it is.
What may be hard is that we now have URLs to things (
/path/to/folder#heading
) and (/path/to/folder/readme.md#heading
) that are populated from different URLs: (/path/to/folder/readme.md#heading
). Maybe a solution is, for every/^readme.md$/i
file, to also expose URLs to its folder?
Sorry, couldn't really follow you on that. Would you mind to rephrase or elaborate on this? ๐
from remark-validate-links.
๐
We process every file to find outgoing links and defined links.
I think that when generating defined links (/path/to/folder/readme.md#heading
) it makes sense to set defined links for the folder if the file matches a supported readme filename (/path/to/folder#heading
).
These places are I believe here and here
from remark-validate-links.
Yes! So, paths to folders currently fail, we fix them, by loading a correct readme.
For every file that is processed, that has a valid readme name, expose both links from that file, but also links from its directory!
This solves the case where links are mixed: both to a readme, and to its folder. Only need to process that file once.
from remark-validate-links.
One more concern I just came up with: If we want to detect a readme file in a folder, we'd have to read all files in the directory and match them against the readme pattern. This might become a performance concern with really big folders.
Do you think it would be worth it to check for for the most common readme.md
and README.md
explicitely, and only then fall back to scanning the directory?
from remark-validate-links.
Hmm, Readme.md
is also likely.
I donโt know, the list becomes relatively long that Iโm worried it wouldnโt add much of a performance improvement.
One potential approach is fs.Dir
for streaming directory entries. Itโs able to stop reading when a match is found. However, it doesnโt return results in a particular order, so thatโs annoying.
๐คทโโ๏ธ I donโt know! Maybe just go with the simplest approach and see if there are bottlenecks later? We can always fix it in the future.
from remark-validate-links.
Ok, I'm a bit stuck and need a little heads-up: Given I don't want to do a major program flow change to the plugin, I'll have to detect readme files inside the find
function.
Is it fine to do it there using the fs
module?
I'm asking because I don't know what the browser support story is for this module and how it relates to vfile
.
from remark-validate-links.
I would suggest using adding a resolve
file, with a resolve.browser.js
alternative that is a โnoopโ like find-repo.browser.js
.
I think actual fs access can go in check-files.js, which already has a simplified version for browsers?
from remark-validate-links.
That's pretty much where I'm stuck.
My latest approach was roughly like "inject the file set into the check-files.js and add the readme vfile from there". This works in part as the added file will actually go through a find
call, however that call only comes when the previous check & validation cycle is already finished (which is too late, obviously).
To be honest, I'm not sure whether it's a good idea for me to finish up this issue. I'm not too confident working with Node streams and not at all familiar with how remark works overall โ I'll probably cause you more work by live-learning these things and then delivering a mediocre solution than I would if I left the implementation to you. ๐
from remark-validate-links.
๐ค alright, thanks for working on it! And for helping figure out a solution. I'm away for the weekend so can't code on it now. But I'll get to it soon!
from remark-validate-links.
No hurry, thanks for offering all these great packages in the first place. ๐
Looking forward to how you're going to approach this, I'll probably learn more about remark from the resulting code diff than from the last hours of reading the existing code. ๐
from remark-validate-links.
Related Issues (20)
- External links always report as failures HOT 10
- How to pass `urlConfig` HOT 10
- Fails on projects not versioned with Git HOT 6
- Error when using with Bazel HOT 4
- No warning or error in case of missing reference HOT 3
- Link checker fails on a matching substring HOT 6
- Multiple hyphens in a row are not collapsed in headings HOT 4
- Support Root-Relative Links (Absolute Links)? HOT 8
- Emoji headings are not supported HOT 1
- Images in headings not slugged correctly HOT 6
- Links are failing when the link is using any of the restricted names like "constructor"/"concat" etc. HOT 2
- `missing-heading-in-file` after upgrade to latest `remark-cli` (v10) HOT 9
- Links checks are failing when the header contains any special character in it. HOT 1
- Support [[wikilinks]] HOT 5
- Validate links for Foliant projects HOT 7
- Headings with inline comments are slugged incorrectly HOT 5
- Nonexistent reference-style links don't cause an error HOT 3
- Does not catch bad links that use absolute paths to repo root HOT 5
- Allow selection between warning, error and ignoring regarding the validity of links HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from remark-validate-links.