経緯
Material for Mkdocsではヘッダーにgitリポジトリの情報を表示することができます。
公式ドキュメントを見るとわかりますが、latest release
とstars
,forks
の情報が表示されていますが、私の環境ではリポジトリの設定をしてもlatest release
の情報は表示されませんでした。
調べると公式ドキュメントの脚注に以下の記載がありました。つまり、GitHubでリリースの作成を実行しなければ取得、表示はできないとのことでした。(9.2.8時点)
Unfortunately, GitHub only provides an API endpoint to obtain the latest release - not the latest tag. Thus, make sure to create a release (not pre-release) for the latest tag you want to display next to the number of stars and forks.
リポジトリではタグは作成していましたが、リリースの作成はしていませんでした。
本記事では確認した内容を備忘録としてまとめた内容になります。
表示内容
対象のURLは下記です。
7rikazhexde.github.io
リリース作成前後の表示は下記の通りです。
リリースの作成後はリリース情報(タグ)が表示されていることを確認できました。
リリース作成前
リリース作成後
補足: REST APIによる確認
脚注ではAPI Endpointで取得するとありますが、GitHub API V3(REST)で確認したところ確かに取得はできませんでした。(/releasesでも同様です。)
mkdocs-materialでどういう仕様でリリース情報を取得しているかは未確認ですが、下記の通りリリースの作成後は取得できました。
リリース作成前
% curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/7rikazhexde/dev-insights-tips/releases/latest { "message": "Not Found", "documentation_url": "https://docs.github.com/rest/releases/releases#get-the-latest-release" }
リリース作成後
% curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/7rikazhexde/dev-insights-tips/releases/latest { "url": "https://api.github.com/repos/7rikazhexde/dev-insights-tips/releases/120650944", "assets_url": "https://api.github.com/repos/7rikazhexde/dev-insights-tips/releases/120650944/assets", "upload_url": "https://uploads.github.com/repos/7rikazhexde/dev-insights-tips/releases/120650944/assets{?name,label}", "html_url": "https://github.com/7rikazhexde/dev-insights-tips/releases/tag/v0.1.42", "id": 120650944, "author": { "login": "7rikazhexde", "id": 33836132, "node_id": "MDQ6VXNlcjMzODM2MTMy", "avatar_url": "https://avatars.githubusercontent.com/u/33836132?v=4", "gravatar_id": "", "url": "https://api.github.com/users/7rikazhexde", "html_url": "https://github.com/7rikazhexde", "followers_url": "https://api.github.com/users/7rikazhexde/followers", "following_url": "https://api.github.com/users/7rikazhexde/following{/other_user}", "gists_url": "https://api.github.com/users/7rikazhexde/gists{/gist_id}", "starred_url": "https://api.github.com/users/7rikazhexde/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/7rikazhexde/subscriptions", "organizations_url": "https://api.github.com/users/7rikazhexde/orgs", "repos_url": "https://api.github.com/users/7rikazhexde/repos", "events_url": "https://api.github.com/users/7rikazhexde/events{/privacy}", "received_events_url": "https://api.github.com/users/7rikazhexde/received_events", "type": "User", "site_admin": false }, "node_id": "RE_kwDOJwRtyc4HMPzA", "tag_name": "v0.1.42", "target_commitish": "main", "name": "dev-insights-tips-v0.1.42", "draft": false, "prerelease": false, "created_at": "2023-09-09T16:09:49Z", "published_at": "2023-09-11T14:12:39Z", "assets": [ ], "tarball_url": "https://api.github.com/repos/7rikazhexde/dev-insights-tips/tarball/v0.1.42", "zipball_url": "https://api.github.com/repos/7rikazhexde/dev-insights-tips/zipball/v0.1.42", "body": "" }
手順
リリースの作成(GitHub)
Create a new release > Tags > タグ選択 / Create release > Release title入力 > Publish release
または、
Create a new release > Release > Chosen a tag / タグ選択 > Release title入力 > Publish release
リポジトリ設定
mkdocs.ymlの設定内容と合わせて記載します。(v1.42.0現在)
repo_name: 7rikazhexde/dev-insights-tips repo_url: https://github.com/7rikazhexde/dev-insights-tips theme: icon: repo: fontawesome/brands/github
まとめ
Material for Mkdocsでgitリポジトリの追加で最新のリリース情報(タグ)を表示する方法について紹介しました。 正直言われなければ気づかない部分ですが、タグ管理している場合はせっかくなので表示しましょう。
以上です。