Repository: mkdocs/mkdocs
Pull request #978 (2016-06-28 12:54:38)

Use the edit url for the 'Edit on...' links
Rather than the view-based `blob` URL, default to the `edit` URL for GitHub-hosted repositories. Also update the release notes.

See #975 for previous work and the discussion leading to this change.

lorengordon: If anyone knows the equivalent URL for Bitbucket repos, I can change that as well.
waylan: I just checked my (mostly unused) Bitbucket account and they don't use a separate URL for edits. When you click the `[edit]` button, the internal content of the page is updated to a textarea via JavaScript. In fact, when I disable JavaScript, the button no longer works and I can't edit the page.

Patch:
diff --git a/docs/about/release-notes.md b/docs/about/release-notes.md
index b1185a58..59170ea7 100644
--- a/docs/about/release-notes.md
+++ b/docs/about/release-notes.md
@@ -107,6 +107,9 @@ to support such customization.
 * Bugfix: Support SOURCE_DATE_EPOCH environment variable for "reproducible"
   builds (#938)
 * Follow links when copying media files (#869).
+* Change "Edit on..." links to point directly to the file in the source
+  repository, rather than to the root of the repository (#975), configurable
+  via the new [`edit_uri`](../user-guide/configuration.md#edit_uri) setting.
 
 ## Version 0.15.3 (2016-02-18)
 
diff --git a/docs/user-guide/configuration.md b/docs/user-guide/configuration.md
index 6fbebe23..5859ef64 100644
--- a/docs/user-guide/configuration.md
+++ b/docs/user-guide/configuration.md
@@ -62,10 +62,10 @@ makes it easier to find and edit the source for the page. If `repo_url` is not
 set, this option is ignored.
 
 For example, for a GitHub-hosted repository, the `edit_uri` would be as follows.
-(Note the `blob` path and `master` branch...)
+(Note the `edit` path and `master` branch...)
 
 ```yaml
-edit_uri: blob/master/docs/
+edit_uri: edit/master/docs/
 ```
 
 For a Bitbucket-hosted repository, the equivalent `edit_uri` would be as
@@ -78,9 +78,16 @@ edit_uri: src/default/docs/
 For other repository hosts, `edit_uri` works the same way. Simply specify the
 relative path to the docs directory.
 
-**default**: `blob/master/docs/` or `src/default/docs/` for GitHub or Bitbucket
+**default**: `edit/master/docs/` or `src/default/docs/` for GitHub or Bitbucket
 repos, respectively, if `repo_url` matches those domains, otherwise `null`
 
+!!! note "Note:"
+    On GitHub, the `edit` path opens the page in the online GitHub editor. This
+    functionality requires that the user have and be logged in to a GitHub
+    account. Otherwise, the user will be redirected to a login/signup page.
+    Alternatively, use the `blob` path to open a read-only view, which supports
+    anonymous access. E.g. `blob/master/docs/`
+
 ### site_description
 
 Set the site description. This will add a meta tag to the generated HTML header.
diff --git a/mkdocs/config/config_options.py b/mkdocs/config/config_options.py
index 25dd8b09..8845e48a 100644
--- a/mkdocs/config/config_options.py
+++ b/mkdocs/config/config_options.py
@@ -204,7 +204,7 @@ class RepoURL(URL):
 
         if config['repo_url'] is not None and config.get('edit_uri') is None:
             if config['repo_name'].lower() == 'github':
-                config['edit_uri'] = 'blob/master/docs/'
+                config['edit_uri'] = 'edit/master/docs/'
             elif config['repo_name'].lower() == 'bitbucket':
                 config['edit_uri'] = 'src/default/docs/'
 


Test patch:
diff --git a/mkdocs/tests/config/config_options_tests.py b/mkdocs/tests/config/config_options_tests.py
index 05898b19..c492d797 100644
--- a/mkdocs/tests/config/config_options_tests.py
+++ b/mkdocs/tests/config/config_options_tests.py
@@ -130,7 +130,7 @@ class RepoURLTest(unittest.TestCase):
         option = config_options.RepoURL()
         config = {'repo_url': "https://github.com/mkdocs/mkdocs"}
         option.post_validation(config, 'repo_url')
-        self.assertEqual(config['edit_uri'], 'blob/master/docs/')
+        self.assertEqual(config['edit_uri'], 'edit/master/docs/')
 
     def test_edit_uri_bitbucket(self):