Skip to content

Docs: a start on an 'improve this page' feature#136246

Open
nedbat wants to merge 16 commits intopython:mainfrom
nedbat:nedbat/improve-docs-page
Open

Docs: a start on an 'improve this page' feature#136246
nedbat wants to merge 16 commits intopython:mainfrom
nedbat:nedbat/improve-docs-page

Conversation

@nedbat
Copy link
Member

@nedbat nedbat commented Jul 3, 2025

At the Docs WG meeting, we talked about smoothing the path for people to suggest improvements to the docs. This is a start. It uses more JavaScript than we are used to.

I haven't done anything to trim down the "Report a bug" page. Ideas welcome.


📚 Documentation preview 📚: https://cpython-previews--136246.org.readthedocs.build/

@nedbat nedbat force-pushed the nedbat/improve-docs-page branch from b8f50bc to 673e347 Compare July 3, 2025 14:57
Copy link
Member

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

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

This looks great. I have some little thoughts.

Also, this should probably get an issue and blurb?

`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.

@ryan-duve
Copy link
Contributor

I like the "This link will start a pre-populated topic:" link, but I wonder whether "less is more" applies here. In particular, I mean if the "Improve this page" link directly goes to the pre-populated Discourse form, would that more directly get users to where they can make a suggestion? If so, would it be better for "Improve this page" to link straight to Discourse?

@nedbat
Copy link
Member Author

nedbat commented Jul 4, 2025

I like the "This link will start a pre-populated topic:" link, but I wonder whether "less is more" applies here. In particular, I mean if the "Improve this page" link directly goes to the pre-populated Discourse form, would that more directly get users to where they can make a suggestion? If so, would it be better for "Improve this page" to link straight to Discourse?

I'm not sure Discourse is the right place for everyone. Some people will have edits, some will have questions, some will want to discuss ideas for improvement. I appreciate the desire to make the path as well-greased as possible. If we do decide to link straight to Discourse, we'll need to change the link from "Improve this page", because Discourse is not the place to do that directly.

@nedbat nedbat marked this pull request as ready for review August 2, 2025 11:37
@nedbat nedbat requested review from AA-Turner and hugovk as code owners August 2, 2025 11:37
Comment on lines 13 to 21
<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?

Copy link
Member

@AA-Turner AA-Turner left a comment

Choose a reason for hiding this comment

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

I'd like to see if we can make this work as far as reasonably practical without JS -- we currently don't require users to have JS enabled to use the documentation.

On Hugo's point on translations, we could add another .. only:: block for non-English containing a brief description of changes to the translation vs source content.

A

@StanFromIreland
Copy link
Member

StanFromIreland commented Aug 2, 2025

On Hugo's point on translations, we could add another .. only:: block for non-English containing a brief description of changes to the translation vs source content.

For reference, the current practice for bugs.po, per PEP 545, is to stick it in somewhere at the end of an existing message.

I’m not a Sphinx expert but I don’t see how it would work, from my experience it can only exclude builders. If you could please share some Sphinx magic I’d love to open a PR for bugs.

@nedbat
Copy link
Member Author

nedbat commented Aug 2, 2025

I'd like to see if we can make this work as far as reasonably practical without JS -- we currently don't require users to have JS enabled to use the documentation.

I'm happy to try another approach, but I'm not sure what we can do. The goal is for the Improve page to know what page the user was reading. Do you have another way?

nedbat added 2 commits August 2, 2025 16:20
- use the actual page URL
- tighten the wording
@nedbat
Copy link
Member Author

nedbat commented Aug 2, 2025

On Hugo's point on translations, we could add another .. only:: block for non-English containing a brief description of changes to the translation vs source content.

For reference, the current practice for bugs.po, per PEP 545, is to stick it in somewhere at the end of an existing message.

I’m not a Sphinx expert but I don’t see how it would work, from my experience it can only exclude builders. If you could please share some Sphinx magic I’d love to open a PR for bugs.

Maybe I don't understand the translation issue. What is the .. only:: block for?

@StanFromIreland
Copy link
Member

Maybe I don't understand the translation issue. What is the .. only:: block for?

See #137449 for bugs.rst, a similar thing could then be added here.

@nedbat
Copy link
Member Author

nedbat commented Aug 18, 2025

BTW, #81792 also discusses ideas for these pages. Anyone have changes needed to this PR before we merge and iterate?

@AA-Turner
Copy link
Member

AA-Turner commented Aug 18, 2025

Anyone have changes needed to this PR before we merge and iterate?

Yes, see above. I'll have a quick go at a less-JS version, apologies for not seeing your reply.

@nedbat
Copy link
Member Author

nedbat commented Feb 11, 2026

I lost track of the PR. What are people's opinions now?

@hugovk
Copy link
Member

hugovk commented Feb 11, 2026

These are pretty short chunks of JavaScript so I'm fine with them. We can always replace with non-JS later.

But after clicking "Improve this page" when JS is disabled we get a load of placeholders:

image

So we'll need some fallback when JS is disabled or unavailable.

@nedbat
Copy link
Member Author

nedbat commented Feb 12, 2026

I've dealt with the "No JS" problem by having a separate -nojs version of the page which is linked in the sidebar. The existing JavaScript snippet changes the URL to the js-enabled version of the page.

<script>
document.addEventListener('DOMContentLoaded', () => {
const params = new URLSearchParams(window.location.search);
document.body.innerHTML = document.body.innerHTML
Copy link
Member

@StanFromIreland StanFromIreland Feb 12, 2026

Choose a reason for hiding this comment

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

This is vulnerable to a DOM based XSS, no? We should escape the params.

Copy link
Member Author

Choose a reason for hiding this comment

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

Excellent point, and I should have known better. I will fix it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.


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

Choose a reason for hiding this comment

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

Similarly to above,

Suggested change
`Docs: problem with page "PAGETITLE" <https://github.com/python/cpython/issues/new?title=Docs%3A+problem+with+page+%22PAGETITLE%22&labels=docs&body=The+page+at+PAGEURL+has+a+problem%3A>`_.
`Docs: problem with page "PAGETITLE" <https://github.com/python/cpython/issues/new?title=Docs%3A+problem+with+page+%22PAGETITLE%22&template=documentation.yml&body=The+page+at+PAGEURL+has+a+problem%3A>`_.

I expect this will also require updating body.

Copy link
Member Author

Choose a reason for hiding this comment

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

The URL works to create the title and body, but does not apply the label, as tested here: #144780. I think this is fine.


- You can open an issue on the Python GitHub issue tracker. This link will
create a new issue with the "docs" label:
`New docs issue <https://github.com/python/cpython/issues/new?labels=docs>`_.
Copy link
Member

@StanFromIreland StanFromIreland Feb 13, 2026

Choose a reason for hiding this comment

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

I think this (specifically labels=docs) link won't work for anyone who doesn’t have triage permissions in CPython (otherwise, spammers could create "triaged" issues), I suggest linking to the template instead, i.e.: https://github.com/python/cpython/issues/new?template=documentation.yml

Copy link
Member Author

Choose a reason for hiding this comment

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

Here the template is a better choice, I'll change it.

@nedbat
Copy link
Member Author

nedbat commented Feb 13, 2026

OK, I've used the documentation.yml template from both pages. It lets me set a title but not a body, but will apply the docs label no matter who uses it.

@StanFromIreland
Copy link
Member

It lets me set a title but not a body

This need not be the case :-) You can add an id: X for the section to allow you to pre-fill it (&id=text). For example, see my repo where I added an id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants