Browse Source

Add Duoshuo supports

Fechin 8 years ago
parent
commit
9075492f73
4 changed files with 34 additions and 5 deletions
  1. 2 0
      _config.yml
  2. 2 2
      layout/_partial/post/article.ejs
  3. 3 0
      layout/_partial/post/duoshuo.ejs
  4. 27 3
      source/js/diaspora.js

+ 2 - 0
_config.yml

@@ -18,6 +18,8 @@ cover: /img/cover.jpg
 keywords: 
 # 要使用google_analytics进行统计的话,这里需要配置ID
 google_analytics: 
+# 多说系统站点名称
+duoshuo_shortname: 
 # 网站ico
 favicon: /img/favicon.png
 rss: atom.xml

+ 2 - 2
layout/_partial/post/article.ejs

@@ -11,6 +11,6 @@
                 <source type="audio/mpeg" src="<%- page.mp3 || theme.mp3 %>">
             </audio>
         </div>
-        <!--<div class="comment link">添加评论</div>-->
+        <%- partial('duoshuo', {post: page}) %>
     </div>
-</div>
+</div>

+ 3 - 0
layout/_partial/post/duoshuo.ejs

@@ -0,0 +1,3 @@
+<% if (theme.duoshuo_shortname){ %>
+<div class="comment link" data-id="<%= post.path %>" data-title="<%= post.title %>" data-url="<%= post.permalink %>" data-shortname="<%- theme.duoshuo_shortname%>">查看评论</div>
+<% } %>

+ 27 - 3
source/js/diaspora.js

@@ -412,13 +412,13 @@ $(function() {
                     return
                 }
 
-                tag.html('加载中..').data('status', 'loading')
+                tag.html('åŠ è½½ä¸­..').data('status', 'loading')
                 Diaspora.loading()
 
                 Diaspora.L(tag.attr('href'), function(data) {
                     var link = $(data).find('.more').attr('href');
                     if (link != undefined) {
-                        tag.attr('href', link).html('加载更多').data('status', 'loaded')
+                        tag.attr('href', link).html('åŠ è½½æ›´å¤š').data('status', 'loaded')
                         tag.data('page', parseInt(tag.data('page')) + 1)
                     } else {
                         $('#pager').remove()
@@ -428,7 +428,7 @@ $(function() {
 
                     Diaspora.loaded()
                 }, function() {
-                    tag.html('加载更多').data('status', 'loaded')
+                    tag.html('åŠ è½½æ›´å¤š').data('status', 'loaded')
                 })
 
                 return false;
@@ -503,6 +503,30 @@ $(function() {
                 return false;
                 break;
 
+				// comment
+			case - 1 != tag.indexOf("comment") : Diaspora.loading(),
+				$(".comment").removeClass("link").html("");
+				var id = $(".comment").data("id"),
+				    title = $(".comment").data("title"),
+				    url = $(".comment").data("url"),
+				    shortname = $(".comment").data("shortname");
+                window.duoshuoQuery = {short_name: shortname};
+				var f = function() {
+					var a = document.createElement("div");
+					a.setAttribute("data-thread-key", id);
+					a.setAttribute("data-title", title);
+					a.setAttribute("data-url", url);
+					DUOSHUO.EmbedThread(a);
+					$(".comment").html(a);
+					Diaspora.loaded();
+				};
+				window.DUOSHUO ? f() : $.getScript("http://static.duoshuo.com/embed.js",
+				function() {
+					f()
+				});
+				return false;
+				break;
+
             default:
                 return;
                 break;