-
Notifications
You must be signed in to change notification settings - Fork 5
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
ページを編集した人リストをGitHubアイコンで列挙したい #83
Comments
yohhoyさんとかonihusubeさんが、メールアドレスからアカウント名をとれないですね。。。 |
ユーザーページにメールアドレスを載せてる人しかとれないっぽい |
@faithandbrave https://github.com/cpprefjp/site/blob/master/README.md などで一番上に表示されるアイコンのリストが |
@k-satoda ありがとうございます。全ページの対応するGitHubページのHTMLをとってきて解析になっちゃいますが、それでできそうですね。 |
コミットを取ってくる GitHub API があります。
使用例UserScript コード// ==UserScript==
// @name Add Author Icons on cpprefjp
// @version 0.1
// @description cpprefjp に編集者のアイコンを追加
// @match https://cpprefjp.github.io/*
// ==/UserScript==
(async function () {
"use strict";
const path = ((location.pathname === "/") ? "/index.md" : location.pathname.replace(/\.html$/, ".md"));
const res = await fetch(`https://api.github.com/repos/cpprefjp/site/commits?path=${path}`);
const commits = await res.json();
const authors = commits.map(commit => commit.author).filter(author => (author !== null));
const uniqueAuthors = authors.filter(author => (authors.find(a => (a.id === author.id)) === author));
const icons = document.createElement("p");
icons.classList.add("text-right");
for (const author of uniqueAuthors) {
const iconURL = new URL(author.avatar_url);
iconURL.searchParams.append("size", "40");
const icon = new Image(20, 20);
icon.src = iconURL.href;
icon.style.borderRadius = "50%";
icon.style.boxShadow = "0 0 0 1px #1f232826";
icon.style.verticalAlign = "middle";
icon.style.marginLeft = "3px";
const a = document.createElement("a");
a.href = author.html_url;
a.append(icon);
icons.append(a);
}
const editButtonDiv = document.querySelector("div.edit-button");
editButtonDiv.children[0].after(icons);
})(); |
いまは各ページの右上に、そのページを最後に編集した人の名前が表示されています (git logからとってきてる)。
ここは元々GitHubユーザーページへのリンクまで貼りたかったのですが、技術的難易度から実装されていませんでした。
目的としては、編集者のモチベーションのためです。
このGitHub APIで、メールアドレスからGitHubアカウント名をとってこれるので、これを使ってアカウント名をとってきてキャッシュしつつ、
可能であればgit logでそのページを編集した人のリストをとって (無理そうなら最終コミットした人)、ページにはGitHubアイコンとそのユーザーへのリンクを貼りたいです。
作業時間がなかなかとれないので、ひとまずタスクissueにしておきます。
The text was updated successfully, but these errors were encountered: