Skip to content

Commit 9ef360f

Browse files
author
emplums
authored
Merge pull request #183 from primer/edit-links
Allow for default branches other than 'master'
2 parents 2d38518 + b40c379 commit 9ef360f

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

docs/content/usage/customization.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ To enable these features, you'll need to specify your site's [`repository`](http
5959
}
6060
```
6161

62+
## Subdirectories
63+
6264
If your site is located in a subdirectory of a repository, you'll also need to provide the relative path to the root of your git respository via the `repoRootPath` option in `gatsby-config.js`:
6365

6466
```js
@@ -75,6 +77,24 @@ module.exports = {
7577
}
7678
```
7779

80+
### Default branch
81+
82+
If your site uses a branch other than `master` for your default branch, you'll also need to let Doctocat know via the `defaultBranch` option in `gatsby-config.js`:
83+
84+
```js
85+
// gatsby-config.js
86+
module.exports = {
87+
plugins: [
88+
{
89+
resolve: '@primer/gatsby-theme-doctocat',
90+
options: {
91+
defaultBranch: 'main', // defaults to 'master'
92+
},
93+
},
94+
],
95+
}
96+
```
97+
7898
## Contributors
7999

80100
If you have the `repository` in `package.json` and `repoRootPath` in `gatsby-config.js` set up correctly (as described [above](#edit-on-github-link)), Doctocat will automatically display contributors on the bottom of every page, like so:

theme/gatsby-node.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ exports.createPages = async ({graphql, actions}, themeOptions) => {
5252
rootAbsolutePath,
5353
node.fileAbsolutePath,
5454
)
55-
56-
const editUrl = getEditUrl(repo, fileRelativePath)
55+
const defaultBranch = themeOptions.defaultBranch || 'master'
56+
const editUrl = getEditUrl(repo, fileRelativePath, defaultBranch)
5757

5858
let contributors = []
5959
if (process.env.GITHUB_TOKEN || process.env.NOW_GITHUB_DEPLOYMENT) {
@@ -83,8 +83,8 @@ exports.createPages = async ({graphql, actions}, themeOptions) => {
8383
)
8484
}
8585

86-
function getEditUrl(repo, filePath) {
87-
return `https://github.com/${repo.user}/${repo.project}/edit/master/${filePath}`
86+
function getEditUrl(repo, filePath, defaultBranch) {
87+
return `https://github.com/${repo.user}/${repo.project}/edit/${defaultBranch}/${filePath}`
8888
}
8989

9090
async function fetchContributors(repo, filePath, accessToken = "") {

theme/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@primer/gatsby-theme-doctocat",
3-
"version": "0.25.2",
3+
"version": "0.25.3",
44
"main": "index.js",
55
"license": "MIT",
66
"scripts": {

0 commit comments

Comments
 (0)