-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25362 from noahdesu/mimic-docs
mimic: docs: backport edit on github changes Reviewed-by: Josh Durgin <jdurgin@redhat.com>
- Loading branch information
Showing
5 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Adapted from https://gist.github.com/mgedmin/6052926 | ||
Sphinx extension to add ReadTheDocs-style "Edit on GitHub" links to the | ||
sidebar. | ||
Loosely based on https://github.com/astropy/astropy/pull/347 | ||
""" | ||
|
||
import os | ||
import warnings | ||
|
||
|
||
__licence__ = 'BSD (3 clause)' | ||
|
||
|
||
def get_github_url(app, view, path): | ||
return 'https://github.com/{project}/{view}/{branch}/doc/{path}'.format( | ||
project=app.config.edit_on_github_project, | ||
view=view, | ||
branch=app.config.edit_on_github_branch, | ||
path=path) | ||
|
||
|
||
def html_page_context(app, pagename, templatename, context, doctree): | ||
if templatename != 'page.html': | ||
return | ||
|
||
if not app.config.edit_on_github_project: | ||
warnings.warn("edit_on_github_project not specified") | ||
return | ||
|
||
path = os.path.relpath(doctree.get('source'), app.builder.srcdir) | ||
show_url = get_github_url(app, 'blob', path) | ||
edit_url = get_github_url(app, 'edit', path) | ||
|
||
context['show_on_github_url'] = show_url | ||
context['edit_on_github_url'] = edit_url | ||
|
||
def setup(app): | ||
app.add_config_value('edit_on_github_project', '', True) | ||
app.add_config_value('edit_on_github_branch', 'master', True) | ||
app.connect('html-page-context', html_page_context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
$(function() { | ||
var releases_url = "http://docs.ceph.com/docs/master/releases.json"; | ||
|
||
function show_edit(branch, data) { | ||
if (branch) { | ||
if (branch === "master") { | ||
$("#dev-warning").show(); | ||
return true; | ||
} | ||
if (data && data.releases && branch in data.releases) { | ||
var eol = ("actual_eol" in data.releases[branch]); | ||
if (eol) { | ||
$("#eol-warning").show(); | ||
} | ||
return !eol; | ||
} | ||
} | ||
$("#dev-warning").show(); | ||
return false; | ||
} | ||
|
||
function get_branch() { | ||
var url = window.location.href; | ||
var res = url.match(/docs.ceph.com\/docs\/([a-z]+)\/?/i) | ||
if (res) { | ||
return res[1] | ||
} | ||
return null; | ||
} | ||
|
||
$.getJSON(releases_url, function(data) { | ||
var branch = get_branch(); | ||
if (show_edit(branch, data)) { | ||
// patch the edit-on-github URL for correct branch | ||
var url = $("#edit-on-github").attr("href"); | ||
url = url.replace("master", branch); | ||
$("#edit-on-github").attr("href", url); | ||
$("#docubetter").show(); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{% extends "!page.html" %} | ||
{% block body %} | ||
|
||
<div id="dev-warning" class="admonition note" style="display:none;"> | ||
<p class="first admonition-title">Notice</p> | ||
<p class="last">This document is for a development version of Ceph.</p> | ||
</div> | ||
|
||
<div id="eol-warning" class="admonition warning" style="display:none;"> | ||
<p class="first admonition-title">Warning</p> | ||
<p class="last">This document is for an unsupported version of Ceph.</p> | ||
</div> | ||
|
||
{%- if edit_on_github_url %} | ||
<div id="docubetter" align="right" style="display:none; padding: 15px; font-weight: bold;"> | ||
<a id="edit-on-github" href="{{ edit_on_github_url }}" rel="nofollow">{{ _('Edit on GitHub')}}</a> | <a href="https://github.com/ceph/ceph/projects/4">Report a Documentation Bug</a> | ||
</div> | ||
{%- endif %} | ||
|
||
{{ super() }} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters