Skip to content
This repository has been archived by the owner on May 12, 2020. It is now read-only.

Commit

Permalink
Fixed #9: set the images url absolutely
Browse files Browse the repository at this point in the history
  • Loading branch information
lvxianchao committed May 11, 2019
1 parent d6c7606 commit 7f684af
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
</el-main>

<el-aside v-show="isTocShow" class="toc-aside">
<Toc :readmeHtmlWithoutAnchor="readmeHtml" @render="render"></Toc>
<Toc :readmeHtmlWithoutAnchor="readmeHtml" :repository="repository" @render="render"></Toc>
</el-aside>
</el-container>
</el-card>
Expand Down
20 changes: 20 additions & 0 deletions src/js/components/Toc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
type: String,
require: true,
},
repository: {
type: Object,
require: true,
}
},
data() {
return {
Expand All @@ -25,6 +29,7 @@
label: 'name',
},
jumpToNodeId: '',
repo: {},
}
},
Expand Down Expand Up @@ -87,9 +92,24 @@
// 去除标签图片后换行标签
html.find('p>a').siblings('br').remove();
// 将相对路径的图片转为绝对路径
let repository = this.repository.repo;
html.find('img').each(function () {
let src = $(this).attr('src');
if (!src.startsWith('https')) {
src = '/' + _.trimStart(src, '/');
src = 'https://raw.githubusercontent.com/' + repository.full_name + '/' + repository.default_branch + '/' + src;
$(this).attr('src', src);
}
});
this.$emit('render', html.html());
},
},
// mounted() {
// this.repo = this.repository.repo;
// }
}
</script>

Expand Down

0 comments on commit 7f684af

Please sign in to comment.