I want to add a share function to my blog. So that readers can share my articles easily. I use a plugin Share.js
. Even though this project has been not maintained for long, it’s still can be used.
使用 npm
1 | npm install social-share.js |
使用 cdnjs,引入 share.min.css
与 social-share.min.js
两个链接.
手动下载或者 git clone 本项目。
At first, I choose the easiest way to use npm to install. However, I ran into some bugs that the icons of the brand recurring many times. So I thinks maybe is that the npm version is not the newest.
So, I cloned the project.
Here I’m just going to introduce how to use it on hexo blog.
First, in your html file, you need to specify a class called social-share
.
1 | <div class="social-share"></div> |
Copy the files social-share.js
and qrcode.js
in directory share.js/src/js
to your program directory.
And then include them in the html file you just created.
1 | <script src="/js/social-share.js"></script> |
You should change your src
to your own file directory.
Copy share.min.css
to your work directory. And include it.
1 | <link rel="stylesheet" href="../dist/css/share.min.css"> |
If you want to specify your icons and share functions. you can use js code to configurate it.
1 | <script> |
There are many options to let you configurate:
1 | url : '', // 网址,默认使用 window.location.href |
Or you can simply write it in html as you create it:
1 | <div class="share-component" data-disabled="google,twitter,facebook" data-description="Share.js - 一键分享到微博,QQ空间,腾讯微博,人人,豆瓣"></div> |
For more usage, visits https://github.com/overtrue/share.js.
If you are using my theme, you can just configurate the switch in _config.yml
.
When you test the share function for qq friend or qqzone, you should use 127.0.0.1 instead of localhost. Or you will get an error while sharing because QQ blocks localhost by default.