gitment
gitment copied to clipboard
所有文章一键初始化评论
@ystyle 我们新开个讨论、哈哈
我是Jekyll建站的、post.ejs文件怎么添加进去呢?
@Jandaes 我随意看了个第三方主题, 主题应该都有个_layout吧? 里边也有个post.html 页面, 放这里应该可以的
http://www.liujilu.com/ 看我的博客、我第一个文章手动初始化了,后面的都没有初始化,所以还是显示需要初始化的按钮,这咋破
你主题呢
[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: 'Reaction[Autorun@8] TypeError: Invalid attempt to destructure non-iterable instance(…)
报错了, 没用过这东西, 不知道出什么问题了
你这是哪里看的?
按f12 啊,
为什么我访问、控制台没有打印啊
我好像理解错你的问题了, @imsun 请问在加载评论时不能做到自动判定并自动新建issue吗?
https://github.com/imsun/gitment/issues/5#issuecomment-292844531 点了初始化后再刷新还是会出来初始化的提示……所以我觉得不能直接放posh.html里,可能会重复创建多个……
同问,我的情况是fork了一个别人的repo,在此基础上添加gitment,也是每次都要initialize
@advpetc 目前这种情况、好像也只能手动一个个初始化了!等作者发布下一个版本吧
那就静等自动初始化吧,,话说直接在github里开issue不需要初始化的,要不以后就在github里直接写文章算了。
暂时没有沙发评论自动初始化 Issue 的可行性的。 因为路人虽然可以创建 Issue,但是不能够创建标签或者挂标签上去。
后续可能会有一个 python 脚本一键初始化所有 Issue 的吧。 实在没人撸,我也可以撸一个。
有办法可以做到的, https://github.com/imsun/gitment/issues/8 中间说的方案。 指定一个索引页就好了
666 好复杂。 其实用一个脚本,分析 sitemap.xml,然后发调用初始化,也是可以的。
@ystyle
@wusisu 这方法不通用啊, 博客又不一定是有 sitemap.xml的· 要配置那么多博客工具, 是做不完的
@wusisu @ystyle 可以分析RSS,这个一般博客都有
@newdee 但是rss一般只有前10或20条的。。。
@ystyle 直接在_post目录下找吧,然后分析下相对地址,这个感觉还比较靠谱点。
@newdee @ystyle 撸了一个 Coding Comments 版本的,根据 sitemap 去玩。
https://coding.coding.me/Comments/help/init.html
有空可以改改,部署一个到 github 上。(gitment 版)
代码: https://coding.net/u/coding/p/Comments/git/blob/coding-pages/help/app.js
写了个自动初始化的脚本:
username = "draveness" # GitHub 用户名
new_token = "xxxxxxx" # GitHub Token
repo_name = "github-comments-repo" # 存放 issues
sitemap_url = "https://draveness.me/sitemap.xml" # sitemap
kind = "Gitalk" # "Gitalk" or "gitment"
require 'open-uri'
require 'faraday'
require 'active_support'
require 'active_support/core_ext'
require 'sitemap-parser'
sitemap = SitemapParser.new sitemap_url
urls = sitemap.to_a
conn = Faraday.new(:url => "https://api.github.com/repos/#{username}/#{repo_name}/issues") do |conn|
conn.basic_auth(username, token)
conn.adapter Faraday.default_adapter
end
urls.each_with_index do |url, index|
title = open(url).read.scan(/<title>(.*?)<\/title>/).first.first.force_encoding('UTF-8')
response = conn.post do |req|
req.body = { body: url, labels: [kind, url], title: title }.to_json
end
puts response.body
sleep 15 if index % 20 == 0
end
mark
mark
你好,请问你那边是成功了吗? 我这边报错“Validation Failed” @StayZeal @Draveness
上面的脚本也不熟悉,只好写了个Java-Post
提交的程序:
public class HttpUtil {
public static Object acHttpPost(String aUrl, String param) {
PrintWriter out = null;
BufferedReader in = null;
String result = "";
try {
URL realUrl = new URL(aUrl);
URLConnection conn = realUrl.openConnection();
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36");
conn.setRequestProperty("Authorization",
"token #token_needed#");
conn.setDoOutput(true);
conn.setDoInput(true);
out = new PrintWriter(conn.getOutputStream());
out.print(param);
out.flush();
in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("POST error!" + e);
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return result;
}
public static void main(String[] args) {
String aUrl = "https://api.github.com/repos/taoyouxian/taoyouxian.github.io/issues";
String param = "{\"title\":\"Hello World | gcoder.tao的博客\",\"labels\":[\"gitment\",\"Thu Apr 05 2018 10:30:51 GMT+0800\"],\"body\":\"https://taoyouxian.github.io/2018/04/05/hello-world/\\n\\n\"}";
String res = (String) HttpUtil.acHttpPost(aUrl, param);
System.out.println(res);
}
}
#token_needed# 存放GitHub Token
在 hexo g
阶段自动初始化怎么样?hexo有接口
昨天按照 @Draveness 的思路改了一番😂
由于我的文章很多链接都比较长,所以十之八九都Validation Failed
,所以按照 #116 的提议将URL的path部分MD5了一下,顺便解决了锚点问题。
另外发现脚本多次运行会创建多个isuse😂 然后也改了一下。。
详细的细节放在了这里:gitment自动初始化
mark