Search code examples
githubgithub-pagesgithub-api

Get a "page url" when a file is hosted using GitHub pages using a custom domain?


How can I get "GitHub Pages" URL for a file in GitHub repository, if there are pages configured and a custom domain attached using GitHub API? Value of this field basically, but using API:

github custom domain field

For "standard" repository, it is "<reponame>.github.io/bla-bla/page".

For example, there is a "has_pages" property that can be used to figure out if the repository has pages enabled, but I have not found anything called "custom_domain" or something?


Solution

  • This has been added in GitHub API in v.3.0: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#get-a-github-pages-site

    /repos/{owner}/{repo}/pages
    

    This will return custom URL, if configured (among other things):

    {
      ...
      "html_url": "https://your.custom.url/",
    }