-
Notifications
You must be signed in to change notification settings - Fork 22
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
Importing local notebook #20
Comments
If you put your local notebook modules in // copied from src/utils.js
const extractPath = path => {
let source = path;
let m;
// "https://api.observablehq.com/@jashkenas/inputs.js?v=3" => strip off ".js"
if ((m = /\.js(\?|$)/i.exec(source))) source = source.slice(0, m.index);
// "74f872c4fde62e35" => "d/..."
if ((m = /^[0-9a-f]{16}$/i.test(source))) source = `d/${source}`;
// link of notebook
if ((m = /^https:\/\/(api\.|beta\.|)observablehq\.com\//i.exec(source)))
source = source.slice(m[0].length);
return source;
};
// copied from src/compiler.js
const defaultResolver = async path => {
const source = extractPath(path);
return import(`https://api.observablehq.com/${source}.js?v=3`).then(
m => m.default
);
};
const resolve = async path => {
let module;
try {
// look for the notebook module on observablehq.com
return await defaultResolver(path);
} catch (e) { // if loading fails
// look for the notebook module in the notebooks/ directory
const source = extractPath(path);
return (await import(`notebooks/${source}.js`)).default;
}
};
const compile = new Compiler(resolve); You could also write logic in the import {cell} from "local/notebook" Then your |
awesome I will try this soon! we should make this somehow a default in the library |
btw, I am planning to use this lib for importing local and remote ojs notebooks in this ext. for vscode I've been working on: https://github.com/RandomFractals/js-notebook-inspector relevant issue in my repo: RandomFractals/js-notebook-inspector#29 |
What is your strategy for importing local notebooks (I also want to keep supporting importing them from observablehq)?
The text was updated successfully, but these errors were encountered: