gitment icon indicating copy to clipboard operation
gitment copied to clipboard

所有文章一键初始化评论

Open Jandaes opened this issue 7 years ago • 33 comments

@ystyle 我们新开个讨论、哈哈

Jandaes avatar Apr 10 '17 03:04 Jandaes

我是Jekyll建站的、post.ejs文件怎么添加进去呢?

Jandaes avatar Apr 10 '17 03:04 Jandaes

@Jandaes 我随意看了个第三方主题, 主题应该都有个_layout吧? 里边也有个post.html 页面, 放这里应该可以的

ystyle avatar Apr 10 '17 04:04 ystyle

http://www.liujilu.com/ 看我的博客、我第一个文章手动初始化了,后面的都没有初始化,所以还是显示需要初始化的按钮,这咋破

Jandaes avatar Apr 10 '17 04:04 Jandaes

你主题呢

ystyle avatar Apr 10 '17 04:04 ystyle

https://github.com/Jandaes/Jandaes.github.io 这是我的仓库地址

Jandaes avatar Apr 10 '17 04:04 Jandaes

[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(…)

报错了, 没用过这东西, 不知道出什么问题了

ystyle avatar Apr 10 '17 04:04 ystyle

你这是哪里看的?

Jandaes avatar Apr 10 '17 05:04 Jandaes

按f12 啊,

ystyle avatar Apr 10 '17 06:04 ystyle

为什么我访问、控制台没有打印啊

Jandaes avatar Apr 10 '17 06:04 Jandaes

我好像理解错你的问题了, @imsun 请问在加载评论时不能做到自动判定并自动新建issue吗?

ystyle avatar Apr 10 '17 06:04 ystyle

https://github.com/imsun/gitment/issues/5#issuecomment-292844531 点了初始化后再刷新还是会出来初始化的提示……所以我觉得不能直接放posh.html里,可能会重复创建多个……

ghostzhang avatar May 27 '17 02:05 ghostzhang

同问,我的情况是fork了一个别人的repo,在此基础上添加gitment,也是每次都要initialize

advpetc avatar Jun 25 '17 02:06 advpetc

@advpetc 目前这种情况、好像也只能手动一个个初始化了!等作者发布下一个版本吧

Jandaes avatar Jun 30 '17 01:06 Jandaes

那就静等自动初始化吧,,话说直接在github里开issue不需要初始化的,要不以后就在github里直接写文章算了。

newdee avatar Sep 17 '17 13:09 newdee

暂时没有沙发评论自动初始化 Issue 的可行性的。 因为路人虽然可以创建 Issue,但是不能够创建标签或者挂标签上去。

后续可能会有一个 python 脚本一键初始化所有 Issue 的吧。 实在没人撸,我也可以撸一个。

wusisu avatar Oct 19 '17 05:10 wusisu

有办法可以做到的, https://github.com/imsun/gitment/issues/8 中间说的方案。 指定一个索引页就好了

ystyle avatar Oct 19 '17 06:10 ystyle

666 好复杂。 其实用一个脚本,分析 sitemap.xml,然后发调用初始化,也是可以的。

@ystyle

wusisu avatar Oct 19 '17 06:10 wusisu

@wusisu 这方法不通用啊, 博客又不一定是有 sitemap.xml的· 要配置那么多博客工具, 是做不完的

ystyle avatar Oct 19 '17 06:10 ystyle

@wusisu @ystyle 可以分析RSS,这个一般博客都有

newdee avatar Oct 19 '17 07:10 newdee

@newdee 但是rss一般只有前10或20条的。。。

ystyle avatar Oct 19 '17 10:10 ystyle

@ystyle 直接在_post目录下找吧,然后分析下相对地址,这个感觉还比较靠谱点。

newdee avatar Oct 20 '17 02:10 newdee

@newdee @ystyle 撸了一个 Coding Comments 版本的,根据 sitemap 去玩。

https://coding.coding.me/Comments/help/init.html

有空可以改改,部署一个到 github 上。(gitment 版)

image

代码: https://coding.net/u/coding/p/Comments/git/blob/coding-pages/help/app.js

wusisu avatar Oct 20 '17 06:10 wusisu

写了个自动初始化的脚本:

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

详情可以看:自动初始化 Gitalk 和 Gitment 评论

draveness avatar Oct 29 '17 14:10 draveness

mark

StayZeal avatar Mar 08 '18 12:03 StayZeal

mark

chenzunyin avatar Mar 16 '18 06:03 chenzunyin

你好,请问你那边是成功了吗? 我这边报错“Validation Failed” @StayZeal @Draveness

taoyouxian avatar Apr 05 '18 14:04 taoyouxian

上面的脚本也不熟悉,只好写了个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

taoyouxian avatar Apr 07 '18 08:04 taoyouxian

hexo g 阶段自动初始化怎么样?hexo有接口

ESblog avatar Aug 06 '18 00:08 ESblog

昨天按照 @Draveness 的思路改了一番😂

由于我的文章很多链接都比较长,所以十之八九都Validation Failed,所以按照 #116 的提议将URL的path部分MD5了一下,顺便解决了锚点问题。

另外发现脚本多次运行会创建多个isuse😂 然后也改了一下。。

详细的细节放在了这里:gitment自动初始化

madordie avatar Aug 30 '18 06:08 madordie

mark

AnowBC avatar Jul 06 '19 17:07 AnowBC