Giter Site home page Giter Site logo

Comments (15)

loilo avatar loilo commented on June 15, 2024 1

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.

loilo avatar loilo commented on June 15, 2024 1

Sounds good. I'll take a look and attach a PR if I manage to wrap my head around it. ๐Ÿ˜‰

from remark-validate-links.

loilo avatar loilo commented on June 15, 2024 1

Alright, potential case of YAGNI detected. ๐Ÿ˜

from remark-validate-links.

loilo avatar loilo commented on June 15, 2024 1

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.

wooorm avatar wooorm commented on June 15, 2024

This wonโ€™t be trivial, but, may be doable, and is useful!

  • Here, new files are added on the CLI:

    fileSet.add(vfile({cwd: file.cwd, path: path.relative(file.cwd, fp)}))

  • 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:

    function checkIfExists(filePath) {
    fs.access(filePath, fs.F_OK, onaccess)
    function onaccess(err) {
    var noEntry = err && err.code === 'ENOENT'
    landmarks[filePath] = {'': !noEntry}

  • 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:

    https://github.com/remarkjs/remark/blob/24cd52d6075966e9113524f002c0cb37133f1a37/packages/remark-cli/cli.js#L5

  • 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.

loilo avatar loilo commented on June 15, 2024

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.

wooorm avatar wooorm commented on June 15, 2024

๐Ÿ‘

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.

wooorm avatar wooorm commented on June 15, 2024

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.

loilo avatar loilo commented on June 15, 2024

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.

wooorm avatar wooorm commented on June 15, 2024

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.

loilo avatar loilo commented on June 15, 2024

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.

wooorm avatar wooorm commented on June 15, 2024

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.

loilo avatar loilo commented on June 15, 2024

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.

wooorm avatar wooorm commented on June 15, 2024

๐Ÿค— 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.

loilo avatar loilo commented on June 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.