Skip to content

Commit 7a7521b

Browse files
Docs: an "improve this page" feature (#144939)
* Docs: a start on an 'improve this page' feature * pr feedback: simplify the link, and don't scare people with the cla * pr feedback answered - use the actual page URL - tighten the wording * fix the improve link on the improve page * news item * Update Doc/improve-page.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> * fix whitespace * A nojs version of the page * comments to help people keep the two pages in sync * protect against XSS * use template for issues from the nojs page * use the template from the JS page as well * give the docs issue template a fillable description field * ugh, getting sloppy * remove more sloppiness --------- Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
1 parent 6f7e3d4 commit 7a7521b

File tree

5 files changed

+115
-2
lines changed

5 files changed

+115
-2
lines changed

.github/ISSUE_TEMPLATE/documentation.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ body:
88
> [!NOTE]
99
> Trivial changes (for example typos) don’t require an issue before opening a PR.
1010
- type: textarea
11+
id: description
1112
attributes:
1213
label: "Documentation"
13-
description: "A clear and concise description of the issue."
14+
description: "A clear and concise description of the issue. Include a link to the page."
1415
validations:
1516
required: true

Doc/improve-page-nojs.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
:orphan:
2+
3+
****************************
4+
Improve a documentation page
5+
****************************
6+
7+
.. This is the no-javascript version of this page. The one most people
8+
will see (with JavaScript enabled) is improve-page.rst. If you edit
9+
this page, please also edit that one, and vice versa.
10+
11+
.. only:: html and not epub
12+
13+
We are always interested to hear ideas about improvements to the documentation.
14+
15+
.. only:: translation
16+
17+
If the bug or suggested improvement concerns the translation of this
18+
documentation, open an issue or edit the page in
19+
`translation's repository <TRANSLATION_REPO_>`_ instead.
20+
21+
You have a few ways to ask questions or suggest changes:
22+
23+
- You can start a discussion about the page on the Python discussion forum.
24+
This link will start a topic in the Documentation category:
25+
`New Documentation topic <https://discuss.python.org/new-topic?category=documentation>`_.
26+
27+
- You can open an issue on the Python GitHub issue tracker. This link will
28+
create a new issue with the "docs" label:
29+
`New docs issue <https://github.com/python/cpython/issues/new?template=documentation.yml>`_.

Doc/improve-page.rst

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
:orphan:
2+
3+
****************************
4+
Improve a documentation page
5+
****************************
6+
7+
.. This is the JavaScript-enabled version of this page. Another version
8+
(for those with JavaScript disabled) is improve-page-nojs.rst. If you
9+
edit this page, please also edit that one, and vice versa.
10+
11+
.. only:: html and not epub
12+
13+
.. raw:: html
14+
15+
<script>
16+
function applyReplacements(text, params) {
17+
return text
18+
.replace(/PAGETITLE/g, params.get('pagetitle'))
19+
.replace(/PAGEURL/g, params.get('pageurl'))
20+
.replace(/PAGESOURCE/g, params.get('pagesource'));
21+
}
22+
23+
document.addEventListener('DOMContentLoaded', () => {
24+
const params = new URLSearchParams(window.location.search);
25+
const walker = document.createTreeWalker(
26+
document.body,
27+
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT,
28+
null
29+
);
30+
31+
while (walker.nextNode()) {
32+
const node = walker.currentNode;
33+
34+
if (node.nodeType === Node.TEXT_NODE) {
35+
node.textContent = applyReplacements(node.textContent, params)
36+
} else if (node.nodeName === 'A' && node.href) {
37+
node.setAttribute('href', applyReplacements(node.getAttribute('href'), params));
38+
}
39+
}
40+
});
41+
</script>
42+
43+
We are always interested to hear ideas about improvements to the documentation.
44+
45+
You were reading "PAGETITLE" at `<PAGEURL>`_. The source for that page is on
46+
`GitHub <https://github.com/python/cpython/blob/main/Doc/PAGESOURCE?plain=1>`_.
47+
48+
.. only:: translation
49+
50+
If the bug or suggested improvement concerns the translation of this
51+
documentation, open an issue or edit the page in
52+
`translation's repository <TRANSLATION_REPO_>`_ instead.
53+
54+
You have a few ways to ask questions or suggest changes:
55+
56+
- You can start a discussion about the page on the Python discussion forum.
57+
This link will start a pre-populated topic:
58+
`Question about page "PAGETITLE" <https://discuss.python.org/new-topic?category=documentation&title=Question+about+page+%22PAGETITLE%22&body=About+the+page+at+PAGEURL%3A>`_.
59+
60+
- You can open an issue on the Python GitHub issue tracker. This link will
61+
create a new pre-populated issue:
62+
`Docs: problem with page "PAGETITLE" <https://github.com/python/cpython/issues/new?template=documentation.yml&title=Docs%3A+problem+with+page+%22PAGETITLE%22&description=The+page+at+PAGEURL+has+a+problem%3A>`_.
63+
64+
- You can `edit the page on GitHub <https://github.com/python/cpython/blob/main/Doc/PAGESOURCE?plain=1>`_
65+
to open a pull request and begin the contribution process.

Doc/tools/templates/customsourcelink.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
{%- if show_source and has_source and sourcename %}
2+
<script>
3+
document.addEventListener('DOMContentLoaded', () => {
4+
const title = document.querySelector('meta[property="og:title"]').content;
5+
const elements = document.querySelectorAll('.improvepage');
6+
const pageurl = window.location.href.split('?')[0];
7+
elements.forEach(element => {
8+
const url = new URL(element.href.split('?')[0].replace("-nojs", ""));
9+
url.searchParams.set('pagetitle', title);
10+
url.searchParams.set('pageurl', pageurl);
11+
url.searchParams.set('pagesource', "{{ pagename }}.rst");
12+
element.href = url.toString();
13+
});
14+
});
15+
</script>
216
<div role="note" aria-label="source link">
317
<h3>{{ _('This page') }}</h3>
418
<ul class="this-page-menu">
519
<li><a href="{{ pathto('bugs') }}">{% trans %}Report a bug{% endtrans %}</a></li>
20+
<li><a class="improvepage" href="{{ pathto('improve-page-nojs') }}">{% trans %}Improve this page{% endtrans %}</a></li>
621
<li>
7-
<a href="https://github.com/python/cpython/blob/main/Doc/{{ sourcename|replace('.rst.txt', '.rst') }}?plain=1"
22+
<a href="https://github.com/python/cpython/blob/main/Doc/{{ pagename }}.rst?plain=1"
823
rel="nofollow">{{ _('Show source') }}
924
</a>
1025
</li>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
A new "Improve this page" link is available in the left-hand sidebar of the
2+
docs, offering links to create GitHub issues, discussion forum posts, or
3+
pull requests.

0 commit comments

Comments
 (0)