总结一下魔改博客时所需要的js、css文件引入的问题。
一种可以满足“页面打开时就加载网上js、css文件的办法”(对于指定页面)
即:将文件放在github仓库中,在index.md中使用src="https://raw.githack.com/[账户名]/[仓库名]/master/[文件名]"来引用
假如有如下的js文件想在html代码中引入,怎么弄呢?
错误方式1:
<script type="text/javascript"
src="https://github.com/han-suyu/others/blob/master/sudoku.js">
</script>
错误方式2:
<script type="text/javascript"
src="https://raw.githubusercontent.com/han-suyu/others/master/sudoku.js"></script>
错误方式3:
<script type="text/javascript"
src="//https://raw.githubusercontent.com/han-suyu/others/master/sudoku.js"></script>
错误方式4:
<script type="text/javascript"
src="http://raw.githack.com/han-suyu/others/master/sudoku.js">
</script>
正确方式:
<script type="text/javascript"
src="https://raw.githack.com/han-suyu/others/master/sudoku.js">
</script>
即:
- 把
raw.githubusercontent.com替换成:raw.githack.com - 把
http替换成https https前不能加//
一种可以满足“页面打开时就加载本地js、css文件的办法”(对于所有页面)
将js、css文件放在themes\next\source中。
比如有themes\next\source\test\js\snow.js和themes\next\source\test\css\style.css
在themes\next\layout\_layout.swig中添加引用,详细为:
-
如果是css文件,则在标签中添加引用
例如:
-
如果是css文件,则在标签中添加引用
例如: