Comments (5)
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.
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.
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.
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.
Glad you you got it working, I'm going to go ahead and close this.
from rehype-partials.
Related Issues (3)
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 rehype-partials.