Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Doc/improvepage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
:orphan:

.. _improve-a-page:

****************************
Improve a documentation page
****************************

.. only:: html and not epub

.. raw:: html

<script>
document.addEventListener('DOMContentLoaded', () => {
const params = new URLSearchParams(window.location.search);
document.body.innerHTML = document.body.innerHTML
.replace(/PAGETITLE/g, params.get('pagetitle'))
.replace(/PAGEURL/g, params.get('pageurl'))
.replace(/PAGESOURCE/g, params.get('pagesource'));
});
</script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid inline JS? Ideally both here and the <script> in the template would be moved to .js files.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are already two instances of inline script, and tbh, for small one-off chunks like this it might be more understandable to have them on the page where they are used. But in any case, would it be OK to land this feature first and then decide on centralization?


We are always interested to hear about ways to improve the documentation.

You were reading "PAGETITLE" at `<PAGEURL>`_. The source for that page is on
`GitHub <https://github.com/python/cpython/blob/main/Doc/PAGESOURCE?plain=1>`_.

You have a few options for asking questions or suggesting changes:

- You can start a discussion about the page on the Python discussion forum.
This link will start a pre-populated topic:
`Question about "PAGETITLE" <https://discuss.python.org/new-topic?category=documentation&title=Question+about+%22PAGETITLE%22&body=About+the+page+at+PAGEURL%3A>`_.

- You can open an issue on the Python GitHub issue tracker. This link will
create a new issue pre-populated with some information for you:
`Docs: problem with "PAGETITLE" <https://github.com/python/cpython/issues/new?title=Docs%3A+problem+with+%22PAGETITLE%22&labels=docs&body=The+page+at+PAGEURL+has+a+problem%3A>`_.

- You can `edit the page on GitHub <https://github.com/python/cpython/blob/main/Doc/PAGESOURCE?plain=1>`_
and open a pull request, though you will need to have signed a contributor agreement before it can be merged.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a little note, I think mentioning the contribution agreement here may scare away people, as it does not explain much about it, and does not pop up when they edit the page.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was torn about putting it here, we can drop it if needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to "open a pull request and begin the contribution process." to at least hint at the idea that there will be steps needed.

14 changes: 13 additions & 1 deletion Doc/tools/templates/customsourcelink.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
{%- if show_source and has_source and sourcename %}
<script>
document.addEventListener('DOMContentLoaded', () => {
const title = document.querySelector('meta[property="og:title"]').content;
const elements = document.querySelectorAll('.improvepage');
elements.forEach(element => {
const url = new URL(element.href);
url.searchParams.set('pagetitle', title);
element.href = url.toString();
});
});
</script>
<div role="note" aria-label="source link">
<h3>{{ _('This page') }}</h3>
<ul class="this-page-menu">
<li><a href="{{ pathto('bugs') }}">{% trans %}Report a bug{% endtrans %}</a></li>
<li><a class="improvepage" href="{{ pathto('improvepage') }}?pageurl=https://docs.python.org/3/{{ pagename }}.html&pagesource={{ sourcename|replace('.rst.txt', '.rst') }}">{% trans %}Improve this page{% endtrans %}</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/{{ sourcename|replace('.rst.txt', '.rst') }}"
<a href="https://github.com/python/cpython/blob/main/Doc/{{ sourcename|replace('.rst.txt', '.rst?plain=1') }}"
rel="nofollow">{{ _('Show source') }}
</a>
</li>
Expand Down
Loading