Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

所有文章一键初始化评论 #5

Open
Jandaes opened this issue Apr 10, 2017 · 33 comments
Open

所有文章一键初始化评论 #5

Jandaes opened this issue Apr 10, 2017 · 33 comments

Comments

@Jandaes
Copy link

Jandaes commented Apr 10, 2017

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

@Jandaes
Copy link
Author

Jandaes commented Apr 10, 2017

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

@ystyle
Copy link

ystyle commented Apr 10, 2017

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

@Jandaes
Copy link
Author

Jandaes commented Apr 10, 2017

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

@ystyle
Copy link

ystyle commented Apr 10, 2017

你主题呢

@Jandaes
Copy link
Author

Jandaes commented Apr 10, 2017

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

@ystyle
Copy link

ystyle commented Apr 10, 2017

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

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

@Jandaes
Copy link
Author

Jandaes commented Apr 10, 2017

你这是哪里看的?

@ystyle
Copy link

ystyle commented Apr 10, 2017

按f12 啊,

@Jandaes
Copy link
Author

Jandaes commented Apr 10, 2017

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

@ystyle
Copy link

ystyle commented Apr 10, 2017

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

@imsun imsun changed the title 所有文章一件初始化评论 所有文章一键初始化评论 Apr 11, 2017
@ghostzhang
Copy link

#5 (comment) 点了初始化后再刷新还是会出来初始化的提示……所以我觉得不能直接放posh.html里,可能会重复创建多个……

@advpetc
Copy link

advpetc commented Jun 25, 2017

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

@Jandaes
Copy link
Author

Jandaes commented Jun 30, 2017

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

@newdee
Copy link

newdee commented Sep 17, 2017

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

@wusisu
Copy link

wusisu commented Oct 19, 2017

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

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

@ystyle
Copy link

ystyle commented Oct 19, 2017

有办法可以做到的, #8 中间说的方案。 指定一个索引页就好了

@wusisu
Copy link

wusisu commented Oct 19, 2017

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

@ystyle

@ystyle
Copy link

ystyle commented Oct 19, 2017

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

@newdee
Copy link

newdee commented Oct 19, 2017

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

@ystyle
Copy link

ystyle commented Oct 19, 2017

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

@newdee
Copy link

newdee commented Oct 20, 2017

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

@wusisu
Copy link

wusisu commented Oct 20, 2017

@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

@draveness
Copy link

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

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 评论

@StayZeal
Copy link

StayZeal commented Mar 8, 2018

mark

@chenzunyin
Copy link

mark

@taoyouxian
Copy link

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

@taoyouxian
Copy link

taoyouxian commented Apr 7, 2018

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

@ESblog
Copy link

ESblog commented Aug 6, 2018

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

@madordie
Copy link

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

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

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

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

@AnowBC
Copy link

AnowBC commented Jul 6, 2019

mark

@qcnhy
Copy link

qcnhy commented Aug 17, 2019

写了个自动初始化的脚本:
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 评论

ruby执行总是提示libcurl.lib等等错误,请教如何运行?

@loveminimal
Copy link

自己写了个脚本,加到那个 script 标签中就可以了 :)

  // Auto Initialize Comments

  let cmtBtns = document.getElementsByClassName('gitment-comments-init-btn');
  let isClicked = false;

  let timer = setInterval(() => {
    Array.prototype.forEach.call(cmtBtns, item => {
      item.click();
      isClicked = true;
      if(isClicked) {
        clearInterval(timer);
        console.log('Clear timer.')
      }        
    })
  }, 1000)

@qcnhy
Copy link

qcnhy commented Dec 1, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests