Git Product home page Git Product logo

Comments (5)

subhero24 avatar subhero24 commented on July 18, 2024 1

Ah now I see that it is indeed relative, but not for the main entry point.

If I have a file A which has a partial B and that partial B includes another partial C, the path from A to B is relative to the cwd, but the path from B to C is relative to the file B. This was very confusing. But got it working now. Thanks!

from rehype-partials.

mrzmmr avatar mrzmmr commented on July 18, 2024

You can set options.cwd to the location of the document you want and then paths will be resolved from that location. options.handle is a function whilch takes the path currently being worked on and a callback function. For example the default behavior for options.handle is basically the same as doing

let options = {
    handle(filePath, callback) {
        // Do something with the location of the file like,
        fs.readFile(filePath, 'utf8', callback)
    }
}

Adding a custom resolver option probably wouldn't be too difficult. Hope this helps

from rehype-partials.

subhero24 avatar subhero24 commented on July 18, 2024

Thanks for your reply. What I really want to do is resolve the path relative to the file that specified the partial. Implementing the handler as you describe can only do something with the filepath that is already resolved relative to the cwd.

from rehype-partials.

mrzmmr avatar mrzmmr commented on July 18, 2024

Sorry I don't think i understand, maybe you can give an example? If you have a file at ${__dirname}/src/one/two/two.html

<div><!-- href='../../index.html' --></div>

the path will be resolved to ${__dirname}/index.html, or you can specify where to look from for example setting options.cwd = 'src' would resolve to ${__dirname}/src/index.html. Nodes path.resolve is used with options.cwd, the file that specified the partial's path dirs, and the value in the href comment.

from rehype-partials.

mrzmmr avatar mrzmmr commented on July 18, 2024

Glad you you got it working, I'm going to go ahead and close this.

from rehype-partials.

Related Issues (3)

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.