/// A Notebook plugin to render code from github
///
/// Usage:
///
import config from "../config";
import Notebook from "../notebook";
class GithubModule extends HTMLElement {
async connectedCallback() {
const notebook = Notebook.installed();
const module = await notebook.importModule(config.OKTOKIT);
// @ts-ignore
const octokit = new module.Octokit();
const path = this.getAttribute("path");
if (!path) {
this.innerHTML = "No path";
return;
}
const result = await octokit.rest.repos.getContent({
owner: this.getAttribute("owner"),
repo: this.getAttribute("repo"),
path,
});
const data = result.data;
if (result.status == 200 && data.type === "file") {
this.innerHTML = "
";
const code = this.querySelector("code");
const language = this.getAttribute("lang") || path.split(".").pop();
await notebook.renderCode(code, atob(data.content), language);
}
}
}
export default GithubModule;