下面是一些针对 Disqus 和 IntenseDebate 的扩展方法:
首先,Disqus 助手(向 PieterG 致敬):
/// <summary>
/// Display Comments for Post
/// </summary>
/// <param name="html"></param>
/// <param name="postIdentifier"></param>
/// <returns></returns>
public static MvcHtmlString DisqusScript(this HtmlHelper html, string postIdentifier)
{
var commentsBuilder = new StringBuilder();
var id = Config.DisqusId; // get the Disqus id from config file
var devMode = Config.DevMode; // get the devmode ('0' or '1') from config file
commentsBuilder.Append("<div id=\"disqus_thread\"></div>");
commentsBuilder.Append("<script type=\"text/javascript\">");
commentsBuilder.Append("var disqus_shortname = '" + id + "';");
commentsBuilder.Append("var disqus_identifier = '" + postIdentifier + "';");
commentsBuilder.Append("var disqus_url = '" + HttpContext.Current.Request.Url + "';");
commentsBuilder.Append("var disqus_developer = '" + devMode + "';");
/* * * DON'T EDIT BELOW THIS LINE * * */
commentsBuilder.Append("(function () {");
commentsBuilder.Append("var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;");
commentsBuilder.Append("dsq.src = 'http://" + id + ".disqus.com/embed.js';");
commentsBuilder.Append("(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);");
commentsBuilder.Append("})();");
commentsBuilder.Append("</script>");
commentsBuilder.Append("<noscript>");
commentsBuilder.Append("Please enable JavaScript to view the <a href=\"http://disqus.com/?ref_noscript\">comments");
commentsBuilder.Append("powered by Disqus.</a>");
commentsBuilder.Append("</noscript>");
return MvcHtmlString.Create(commentsBuilder.ToString());
}
然后是激烈的辩论版本:
/// <summary>
/// Display Comments for Post
/// </summary>
/// <param name="html"></param>
/// <param name="postIdentifier"></param>
/// <returns></returns>
public static MvcHtmlString IntenseDebateScript(this HtmlHelper html, string postIdentifier)
{
var commentsBuilder = new StringBuilder();
var id = Config.IntenseDebateId; // get the IntenseDebate id from config file
// js variables for embedded wrapper script
commentsBuilder.Append("<script type=\"text/javascript\">");
commentsBuilder.Append("var idcomments_acct = '" + id + "';");
commentsBuilder.Append("var idcomments_post_id = '" + postIdentifier + "';");
commentsBuilder.Append("var idcomments_post_url = '" + HttpContext.Current.Request.Url + "';");
commentsBuilder.Append("</script>");
/* * * DON'T EDIT BELOW THIS LINE * * */
commentsBuilder.Append("<script type=\"text/javascript\" ");
commentsBuilder.Append("src = 'http://www.intensedebate.com/js/genericCommentWrapperV2.js'>");
commentsBuilder.Append("</script>");
// add the target span for the comments
commentsBuilder.Append("<span id='IDCommentsPostTitle' style='display:none'></span>");
commentsBuilder.Append("<noscript>");
commentsBuilder.Append("Please enable JavaScript to view the IntenseDebate comments");
commentsBuilder.Append("</noscript>");
return MvcHtmlString.Create(commentsBuilder.ToString());
}
两种情况下的用法:
// for intensedebate
<%=Html.IntenseDebateScript("comments-id-that-i-can-use") %>
//and for disqus
<%=Html.DisqusScript("another-comments-id-that-i-can-use") %>
请享用...