Skip to content

Commit

Permalink
Gitmint integration
Browse files Browse the repository at this point in the history
  • Loading branch information
aimingoo committed Oct 3, 2017
1 parent d4e70a1 commit 5ae60ca
Show file tree
Hide file tree
Showing 5 changed files with 2,593 additions and 42 deletions.
18 changes: 12 additions & 6 deletions _config.yml
Expand Up @@ -375,12 +375,18 @@ valine:
# Gitment # Gitment
# Introduction: https://imsun.net/posts/gitment-introduction/ # Introduction: https://imsun.net/posts/gitment-introduction/
gitment: gitment:
enable: true enable: false
githubID: # Your Github ID mint: true # RECOMMEND, A mint on Gitment, to support count, language and proxy_gateway
repo: # The repo you use to store Gitment comments count: true # Show comments count in post meta area
ClientID: lazy: false # Comments lazy loading with a button
ClientSecret: cleanly: false # Hide 'Powered by ...' on footer, and more
lazy: false language: # Force language, or auto switch by theme
github_user: # MUST HAVE, Your Github ID
github_repo: # MUST HAVE, The repo you use to store Gitment comments
client_id: # MUST HAVE, Github client id for the Gitment
client_secret: # EITHER this or proxy_gateway, Github access secret token for the Gitment
proxy_gateway: # Address of api proxy, See: https://github.com/aimingoo/intersect
redirect_protocol: # Protocol of redirect_uri with force_redirect_protocol when mint enabled


# Baidu Share # Baidu Share
# Available value: # Available value:
Expand Down
10 changes: 10 additions & 0 deletions layout/_macro/post.swig
Expand Up @@ -176,6 +176,16 @@
<span id="url::{{ post.permalink }}" class="cy_cmt_count" data-xid="{{ post.path }}" itemprop="commentsCount" ></span> <span id="url::{{ post.permalink }}" class="cy_cmt_count" data-xid="{{ post.path }}" itemprop="commentsCount" ></span>
</a> </a>
{% endif %} {% endif %}
{% elseif is_post() and theme.gitment.enable and theme.gitment.mint and theme.gitment.count %}
<span class="post-comments-count">
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
<a href="{{ url_for(post.path) }}#comments" itemprop="discussionUrl">
<span class="post-comments-count gitment-comments-count" data-xid="{{ url_for(post.path) }}" itemprop="commentsCount"></span>
</a>
</span>
{% endif %} {% endif %}
{% endif %} {% endif %}


Expand Down
2 changes: 1 addition & 1 deletion layout/_partials/comments.swig
Expand Up @@ -30,7 +30,7 @@
<div id="SOHUCS"></div> <div id="SOHUCS"></div>
{% elseif theme.gitment.enable %} {% elseif theme.gitment.enable %}
{% if theme.gitment.lazy %} {% if theme.gitment.lazy %}
<div onclick="ShowGitment()" id="gitment-display-button">{{ __('gitmentbutton') }}</div> <div onclick="showGitment()" id="gitment-display-button">{{ __('gitmentbutton') }}</div>
<div id="gitment-container" style="display:none"></div> <div id="gitment-container" style="display:none"></div>
{% else %} {% else %}
<div id="gitment-container"></div> <div id="gitment-container"></div>
Expand Down
92 changes: 57 additions & 35 deletions layout/_third-party/comments/gitment.swig
@@ -1,37 +1,59 @@
{% if theme.gitment.enable %} {% if not (theme.duoshuo and theme.duoshuo.shortname) and not theme.duoshuo_shortname %}
{% set owner = theme.gitment.githubID %} {% if theme.gitment.enable and theme.gitment.client_id %}
{% set repo = theme.gitment.repo %} <!-- LOCAL: You can save these files to your site and update links -->
{% set cid = theme.gitment.ClientID %} {% if theme.gitment.mint %}
{% set cs = theme.gitment.ClientSecret %} {% set CommentsClass = "Gitmint" %}
<link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css"> <link rel="stylesheet" href="https://aimingoo.github.io/gitmint/style/default.css">
<script src="https://imsun.github.io/gitment/dist/gitment.browser.js"></script> <script src="https://aimingoo.github.io/gitmint/dist/gitmint.browser.js"></script>
{% if not theme.gitment.lazy %}
<script type="text/javascript">
var gitment = new Gitment({
id: document.location.href,
owner: '{{owner}}',
repo: '{{repo}}',
oauth: {
client_id: '{{cid}}',
client_secret: '{{cs}}',
}});
gitment.render('gitment-container');
</script>
{% else %} {% else %}
<script type="text/javascript"> {% set CommentsClass = "Gitment" %}
function ShowGitment(){ <link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css">
document.getElementById("gitment-display-button").style.display = "none"; <script src="https://imsun.github.io/gitment/dist/gitment.browser.js"></script>
document.getElementById("gitment-container").style.display = "block";
var gitment = new Gitment({
id: document.location.href,
owner: '{{owner}}',
repo: '{{repo}}',
oauth: {
client_id: '{{cid}}',
client_secret: '{{cs}}',
}});
gitment.render('gitment-container');
}
</script>
{% endif %} {% endif %}
{% endif %} <!-- END LOCAL -->

{% if theme.gitment.cleanly %}
<style>
a.gitment-editor-footer-tip { display: none; }
.gitment-container.gitment-footer-container { display: none; }
</style>
{% endif %}

{% if page.comments %}
<script type="text/javascript">
function renderGitment(){
var gitment = new {{CommentsClass}}({
id: document.location.href,
owner: '{{ theme.gitment.github_user }}',
repo: '{{ theme.gitment.github_repo }}',
{% if theme.gitment.mint %}
lang: "{{ theme.gitment.language }}" || navigator.language || navigator.systemLanguage || navigator.userLanguage,
{% endif %}
oauth: {
{% if theme.gitment.mint and theme.gitment.redirect_protocol %}
redirect_protocol: '{{ theme.gitment.redirect_protocol }}',
{% endif %}
{% if theme.gitment.mint and theme.gitment.proxy_gateway %}
proxy_gateway: '{{ theme.gitment.proxy_gateway }}',
{% else %}
client_secret: '{{ theme.gitment.client_secret }}',
{% endif %}
client_id: '{{ theme.gitment.client_id }}'
}});
gitment.render('gitment-container');
}

{% if not theme.gitment.lazy %}
renderGitment();
{% else %}
function showGitment(){
document.getElementById("gitment-display-button").style.display = "none";
document.getElementById("gitment-container").style.display = "block";
renderGitment();
}
{% endif %}
</script>
{% endif %}

{% endif %}
{% endif %}

0 comments on commit 5ae60ca

Please sign in to comment.