Skip to content

Commit

Permalink
feat: 项目页面支持展示 Gitee 仓库
Browse files Browse the repository at this point in the history
  • Loading branch information
ichenpipi committed Mar 15, 2022
1 parent 6977eb7 commit c922613
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 57 deletions.
16 changes: 15 additions & 1 deletion README.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,24 @@ pv:

如果不需要第三方来统计浏览量,只需将相应设置改为false即可(设置为false后不会加载第三方JS脚本)

### Github respostory
### 项目

复制`theme/pure/_source/` 目录下`repository`文件夹到`blog path/source/` 目录下

新版配置(支持 Github 和 Gitee):

*新版配置将会覆盖旧版的 github 配置!*

```
# Repository Info (This will override 'github' option)
# 项目仓库展示信息(将会覆盖 github 项)
repository:
platform: github # 托管平台(github | gitee)
username: *** # 用户名
```

旧版配置(仅支持 Github):

```
# Github
github:
Expand Down
10 changes: 8 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,14 @@ share:
mobile_sites: weibo,qq,qzone # 移动端显示的分享图标

# Github
github:
username: cofess # github username
# github:
# username: cofess # github username

# Repository Info (This will override 'github' option)
# 项目仓库信息(将会覆盖 github 项)
repository:
platform: github # 托管平台(github | gitee)
username: cofess # 用户名

# Comment
# Gitment
Expand Down
6 changes: 4 additions & 2 deletions layout/_partial/archive-repository.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<article class="article article-repository article-type-list" itemscope="">
<header class="article-header">
<h1 itemprop="title"><%= page.title %></h1>
<p class="text-muted">I have <span id="repo-count">0</span> projects on Github</p>
<p class="text-muted">I have <span id="repo-count">0</span> projects on <span id="repo-platform">Github</span></p>
</header>
<div class="article-body">
<div class="repo-content">
Expand All @@ -11,11 +11,12 @@
</div>
</div>
</article>

<% if (theme.comment.type && !is_home()) { %>
<%- partial('post/comment', {post: page}) %>
<% } %>

<!--Github项模版-->
<!--项模版-->
<script type="text/template" id="list-template">
<li class="col-sm-6 col-md-6 col-lg-4">
<div class="repo hover-shadow hover-grow">
Expand All @@ -32,6 +33,7 @@
</div>
</li>
</script>

<!--获取失败模版-->
<script type="text/template" id="error-template">
<h3>加载失败</h3><p>请刷新或稍后再试...</p>
Expand Down
64 changes: 64 additions & 0 deletions layout/_script/_repository/gitee.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<% if (typeof(script) !== 'undefined' && script) { %>
<script type="text/javascript">
var open = function () {
var baiduTpl = new Object();
var handleTpl = function () {
baiduTpl.list = baidu.template("list-template");
baiduTpl.error = baidu.template("error-template");
};
var handleRepo = function () {
var repoContainer = $('.repo-content');
var errorContainer = repoContainer.find(".blankslate");
var countContainer = $("#repo-count");
var platformContainer = $("#repo-platform");
platformContainer.text("Gitee");
url = "https://gitee.com/api/v5/users/<%=theme.repository.username%>/repos";
$.get(url, function (result) {
if (result) {
errorContainer.remove();
countContainer.text(result.length);
var ul = $("<ul class='repo-list row clearfix'></ul>");
result.sort(function (a, b) {
return new Date(b.updated_at) - new Date(a.updated_at);
}).sort(function (a, b) {
var a_start = a.stargazers_count;
var b_start = b.stargazers_count;
if (a.fork) a_start * 0.5;
if (b.fork) b_start * 0.5;
return b_start - a_start;
}).map(function (repo) {
if (!repo.description) {
repo.description = "";
}
if (!repo.clone_url) {
repo.clone_url = repo.html_url;
}
repo.updated_at = repo.pushed_at.substring(0, repo.pushed_at.lastIndexOf("T"));
var html = baiduTpl.list(repo);
ul.append(html);
});
repoContainer.append(ul);
$(".geopattern").each(function () {
$(this).geopattern($(this).data('pattern-id'));
});
} else {
errorContainer.append(baiduTpl.error());
}
});
};
return {
init: function () {
handleTpl();
handleRepo();
}
}
};
$(open().init);
</script>
<% } %>
61 changes: 61 additions & 0 deletions layout/_script/_repository/github.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<% if (typeof(script) !== 'undefined' && script) { %>
<script type="text/javascript">
var open = function () {
var baiduTpl = new Object();
var handleTpl = function () {
baiduTpl.list = baidu.template("list-template");
baiduTpl.error = baidu.template("error-template");
};
var handleRepo = function () {
var repoContainer = $('.repo-content');
var errorContainer = repoContainer.find(".blankslate");
var countContainer = $("#repo-count");
var platformContainer = $("#repo-platform");
platformContainer.text("Github");
url = "https://api.github.com/users/<%=theme.repository.username%>/repos";
$.get(url, function (result) {
if (result) {
errorContainer.remove();
countContainer.text(result.length);
var ul = $("<ul class='repo-list row clearfix'></ul>");
result.sort(function (a, b) {
return new Date(b.updated_at) - new Date(a.updated_at);
}).sort(function (a, b) {
var a_start = a.stargazers_count;
var b_start = b.stargazers_count;
if (a.fork) a_start * 0.5;
if (b.fork) b_start * 0.5;
return b_start - a_start;
}).map(function (repo) {
if (!repo.description) {
repo.description = "";
}
repo.updated_at = repo.updated_at.substring(0, repo.updated_at.lastIndexOf("T"));
var html = baiduTpl.list(repo);
ul.append(html);
});
repoContainer.append(ul);
$(".geopattern").each(function () {
$(this).geopattern($(this).data('pattern-id'));
});
} else {
errorContainer.append(baiduTpl.error());
}
});
};
return {
init: function () {
handleTpl();
handleRepo();
}
}
};
$(open().init);
</script>
<% } %>
54 changes: 54 additions & 0 deletions layout/_script/_repository/legacy.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<% if (typeof(script) !== 'undefined' && script) { %>
<script type="text/javascript">
var open = function () {
var baiduTpl = new Object();
var handleTpl = function () {
baiduTpl.list = baidu.template("list-template");
baiduTpl.error = baidu.template("error-template");
};
var handleGithub = function () {
var repoContainer = $('.repo-content');
var errorContainer = repoContainer.find(".blankslate");
var countContainer = $("#repo-count");
$.get("https://api.github.com/users/<%=theme.github.username%>/repos", function (result) {
if (result) {
errorContainer.remove();
countContainer.text(result.length); //设置项目个数
var ul = $("<ul class='repo-list row clearfix'></ul>");
result.sort(function (a, b) {
return new Date(b.updated_at) - new Date(a.updated_at)
}).sort(function (a, b) {
var a_start = a.stargazers_count;
var b_start = b.stargazers_count;
if (a.fork) a_start * 0.5;
if (b.fork) b_start * 0.5;
return b_start - a_start;
}).map(function (repo) {
if (!repo.description) repo.description = "";
repo.updated_at = repo.updated_at.substring(0, repo.updated_at.lastIndexOf("T"));
var html = baiduTpl.list(repo);
ul.append(html);
})
repoContainer.append(ul);
$(".geopattern").each(function () {
$(this).geopattern($(this).data('pattern-id'));
});
} else {
errorContainer.append(baiduTpl.error());
}
});
};
return {
init: function () {
handleTpl();
handleGithub();
}
}
};
$(open().init);
</script>
<% } %>
61 changes: 9 additions & 52 deletions layout/_script/repository.ejs
Original file line number Diff line number Diff line change
@@ -1,52 +1,9 @@
<script type="text/javascript">
var open = function() {
var baiduTpl = new Object();
var handleTpl = function() {
baiduTpl.list = baidu.template("list-template");
baiduTpl.error = baidu.template("error-template");
};
var handleGithub = function() {
var repoContainer = $('.repo-content');
var errorContainer = repoContainer.find(".blankslate");
var countContainer = $("#repo-count");
$.get("https://api.github.com/users/<%=theme.github.username%>/repos", function(result) {
if (result) {
errorContainer.remove();
countContainer.text(result.length); //设置项目个数
var ul = $("<ul class='repo-list row clearfix'></ul>");
result.sort(function(a, b) {
return new Date(b.updated_at) - new Date(a.updated_at)
}).sort(function(a, b) {
var a_start = a.stargazers_count;
var b_start = b.stargazers_count;
if (a.fork) a_start * 0.5;
if (b.fork) b_start * 0.5;
return b_start - a_start;
}).map(function(repo) {
if (!repo.description) repo.description = "";
repo.updated_at = repo.updated_at.substring(0, repo.updated_at.lastIndexOf("T"));
var html = baiduTpl.list(repo);
ul.append(html);
})
repoContainer.append(ul);
$(".geopattern").each(function() {
$(this).geopattern($(this).data('pattern-id'));
});
} else {
errorContainer.append(baiduTpl.error());
}
});
};
return {
init: function() {
handleTpl();
handleGithub();
}
}
};
$(open().init);
</script>
<% if (theme.repository) { %>
<% if (theme.repository.platform === 'github') { %>
<%- partial('_script/_repository/github', { script: true }) %>
<% } else if (theme.repository.platform === 'gitee') { %>
<%- partial('_script/_repository/gitee', { script: true }) %>
<% } %>
<% } else if (theme.github) { %>
<%- partial('_script/_repository/legacy', { script: true }) %>
<% } %>

0 comments on commit c922613

Please sign in to comment.