提交 ca98dca1 编写于 作者: 璃白.'s avatar 璃白. 🌻

fix:优化规则

上级 cd0387cd
......@@ -16,10 +16,11 @@
<body>
<!-- <div class="app"></div>
<div class="app"></div> -->
<div
<a
data-type="jupyter"
data-url="/api/odewahn/ipynb-examples/raw/master/Custom%20Display%20Logic.ipynb"
></div>
data-url="http://test-code.csdn.net/cpongo6/ipynb-test/-/blob/master/Cell%20Magics.ipynb"
>http://test-code.csdn.net/cpongo6/ipynb-test/-/blob/master/Cell%20Magics.ipynb</a
>
<!-- <div
data-type="jupyter"
data-url="/api/xiongjiamu/jupyter-101/-/raw/master/002-demo.ipynb"
......
......@@ -29,14 +29,24 @@ export default defineComponent({
},
methods: {
fetchCells() {
api.fetchCells(this.url).then(({ data: res }) => {
const url = this.url;
if (!url) return;
const {
groups: urlInfo
} = /(?<prex>^https?:\/\/\S+.net)\/(?<project_path>\S*)\/\-\/blob\/(?<branch>\S+)\/(?<path>\S*)/.exec(
url
) as any;
const fetchUrl = `${urlInfo.prex}/api/v4/projects/${encodeURIComponent(
urlInfo.project_path
)}/repository/files/${urlInfo.path}/raw?ref=${urlInfo.branch}`;
api.fetchCells(fetchUrl).then(({ data: res }) => {
this.cells = this.getCells(res);
});
},
getCells(obj: CellObject) {
const list = [];
if (obj.cells) {
list.push(obj.cells);
list.push(...obj.cells);
}
obj.worksheets?.forEach((item: CellObject) => {
list.push(...item.cells);
......
......@@ -5,14 +5,15 @@ import './assets/css/style.less';
document.addEventListener('DOMContentLoaded', () => {
console.log('render jupyter')
const jupyterLinks = Array.from(document.querySelectorAll('.jupyter.jupyterEl'))
const jupyterLinks = Array.from(document.querySelectorAll('a'))
if (jupyterLinks.length) {
jupyterLinks.forEach(item => {
const url = item.innerHTML
createApp(App, {
url
}).mount(item)
if (url.includes('.ipynb'))
createApp(App, {
url
}).mount(item)
})
};
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册