-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mkdocs: Values with special !
syntax are set to null on mkdocs.yml
#8529
Comments
Reading that documentation, I arrived at https://github.com/waylan/pyyaml-env-tag#enabling-the-tag. It doesn't work on Read the Docs because we are using our own YAML parser for security reasons ( readthedocs.org/readthedocs/doc_builder/backends/mkdocs.py Lines 347 to 363 in f0da2a4
!ENV syntax is not recognized.
Unfortunately, I don't think there is a workaround, currently. This may be solved by our "Future builders" (#8190) because we may not require a safe YAML loader when it gets implemented. |
Thank you for the feedback. So far I've been left with the only choice of loading the (otherwise undocumented!) script This bring the next followup question, not sure if worth a separate bug report: why the RTD context injection is not working either? I was hoping to use that as alternative to the env vars, but the values don't resolve either and the build fails. Seems to me that the general state of MkDocs support in RTD is pretty weak, as soon as you try to do anything beyond the most basic use cases; no problem with that, but I do believe that adding appropriate comments in some of these doc pages would save long hours of frustration to users (at least I know it would have for me...) |
Hi @j1elo! Thanks for replying. You have mentioned here some interesting points that have been in our discussions lately but we haven't yet had the time to fix them.
This is not documented on purpose because we don't expect users to use this data as it may change without communication. I don't think it has changed in years now. However, we can't compromise ourselves on that.
All the pages under
Unfortunately, this is true. Due to security restrictions, there are advanced MkDocs configurations that we cannot support currently and we haven't had the time to change our internal implementation to reduce those risks. For the
I'm sorry to read that. I hope we can clarify these limitations in our documentation. @astrojuanlu what do you think about mentioning that non-standard (or advanced) YAML usage is not supported currently? |
Thank you very much for the comprehensive answer! :)
At the end of the day what I'm trying to do is make a small decision (to set Are there any more alternatives that I could try with MkDocs? Otherwise, I'm willing to make the compromise of using a private RTD feature that is subject to change. |
Do we have an issue for that already? Or are we only tracking it internally? Besides, I think that design doc in particular has a confusing prose. It talks to "you" (the user) in a way a tutorial would do, and besides there is an admonition on top of https://docs.readthedocs.io/en/stable/guides/vcs.html that leads users into thinking that the new vision is already in place. I'll address this separately. |
Note for my future self or anyone with a similar need: Editing the This is my current solution. Very hacky, very ugly, very brittle. But that's the only thing that has worked so far. Only tested with the <head>
<meta charset="utf-8">
<!--
Create a `<base>` element that matches the current RTD version.
There are 2 parts of the URL slug we need to get:
* Language.
* Version name. Something like "latest", "stable", "2.20.0", etc.
-->
{%- if config.extra.READTHEDOCS %}
<!--
This would be a nicer method to get the values. Load the RTD env vars into the MkDocs config,
which itself gets passed by MkDocs into the Jinja's template context.
However as of this writing, this method won't work.
-->
<base href="/{{ config.extra.READTHEDOCS_LANGUAGE }}/{{ config.extra.READTHEDOCS_VERSION }}/" />
{%- elif "doc.example.org" in config.site_url %}
<!--
Ugly Hack:
* Language: Obtained from the theme's locale config.
* Version name: RTD checks out the repo into a directory named like the
version that is being built. So we get the version name from there.
Sample `docs_dir` string for a build of the `latest` version:
"/home/docs/checkouts/readthedocs.org/user_builds/openvidu/checkouts/latest/docs".
-->
<base href="/{{ config.theme.locale.language }}/{{ config.docs_dir.split('/')[-2] }}/" />
{%- else %}
<!--
When not deploying in our production subdomain, default to root.
This is the case when using `mkdocs serve` for local authoring.
-->
<base href="/" />
{%- endif %} Needless to say, it would be really nice if RTD ends up adding some of its build information to the context that gets passed to Jinja. Meanwhile, I sincerely wasn't able to find any solution that doesn't obtain the info in such indirect way. Regardless, thank you all very much for your help and your support |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
It seems this is the only actionable item from this issue for now. I'm marking it as accepted. |
Hi,
I guess an additional one was suggested from these sentences, but was never stated as a proper actionable item:
Which I'd take to become either of:
|
!
syntax are set to null on mkdocs.yml
Once #10166 gets merged we will be exposing the canonical URL as Due to that, I see two possible solutions here:
I think that 1) should definitely happens at some time when we can prioritize, but at least 2) is a good workaround for now and unblock users. |
Closes #443 ### Summary of Changes The 404 page was previously not properly rendered on Read the Docs (RTD). This PR overrides the build commands of RTD. While this makes the 404 page work properly, it also removes the RTD flyout to select a version. For now, however, we deem the 404 page as more essential. Once readthedocs/readthedocs.org#8529 is done, we can use the default build again to make everything work as expected.
### Summary of Changes The 404 page was previously not properly rendered on Read the Docs (RTD). This PR overrides the build commands of RTD. While this makes the 404 page work properly, it also removes the RTD flyout to select a version. For now, however, we deem the 404 page as more essential. Once readthedocs/readthedocs.org#8529 is done, we can use the default build again to make everything work as expected.
### Summary of Changes The 404 page was previously not properly rendered on Read the Docs (RTD). This PR overrides the build commands of RTD. While this makes the 404 page work properly, it also removes the RTD flyout to select a version. For now, however, we deem the 404 page as more essential. Once readthedocs/readthedocs.org#8529 is done, we can use the default build again to make everything work as expected.
### Summary of Changes The 404 page was previously not properly rendered on Read the Docs (RTD). This PR overrides the build commands of RTD. While this makes the 404 page work properly, it also removes the RTD flyout to select a version. For now, however, we deem the 404 page as more essential. Once readthedocs/readthedocs.org#8529 is done, we can use the default build again to make everything work as expected.
### Summary of Changes The 404 page was previously not properly rendered on Read the Docs (RTD). This PR overrides the build commands of RTD. While this makes the 404 page work properly, it also removes the RTD flyout to select a version. For now, however, we deem the 404 page as more essential. Once readthedocs/readthedocs.org#8529 is done, we can use the default build again to make everything work as expected. --------- Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
### Summary of Changes The 404 page was previously not properly rendered on Read the Docs (RTD). This PR overrides the build commands of RTD. While this makes the 404 page work properly, it also removes the RTD flyout to select a version. For now, however, we deem the 404 page as more essential. Once readthedocs/readthedocs.org#8529 is done, we can use the default build again to make everything work as expected. --------- Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
So on this issue, is there any proper solution to this? I've been struggling trying to use the !ENV argument on my mkdocs.yml ... |
@MetalKnight56 yes, take a look at option 2) from #8529 (comment) |
Thanks for replying, i was able to fix it on my side using poetry :) |
Delete all the magic around MkDocs YAML that processes the `mkdocs.yml`. file and define `readthedocs` theme automatically based on a feature flag, `MKDOCS_THEME_RTD`. This PR removes: - automatically defining `readthedocs` as theme when `MKDOCS_THEME_RTD` feature flag is defined. - processing `mkdocs.yml` to add internal JS and CSS (embed and analytics) files automatically This is another step forward on removing all the magic we perform on behalf the users and being more explicit about how to configure each doctool. Reference: * readthedocs/addons#72 (comment) Closes #8529
Blog post announcing the depreaction of the `mkdocs.yml` manipulation done by Read the Docs at build time, following the plan described. Related: * readthedocs/addons#72 (comment) * readthedocs/readthedocs.org#11206 * readthedocs/readthedocs.org#8529
* Post: MkDocs YAML manipulation Blog post announcing the depreaction of the `mkdocs.yml` manipulation done by Read the Docs at build time, following the plan described. Related: * readthedocs/addons#72 (comment) * readthedocs/readthedocs.org#11206 * readthedocs/readthedocs.org#8529 * Use double quotes The other ones don't render properly. * Apply suggestions from code review Co-authored-by: Eric Holscher <25510+ericholscher@users.noreply.github.com> --------- Co-authored-by: Eric Holscher <25510+ericholscher@users.noreply.github.com>
Hi 👋🏼 . Starting on April 15th the usage of special |
* Build: remove `append_conf` _magic_ from MkDocs Delete all the magic around MkDocs YAML that processes the `mkdocs.yml`. file and define `readthedocs` theme automatically based on a feature flag, `MKDOCS_THEME_RTD`. This PR removes: - automatically defining `readthedocs` as theme when `MKDOCS_THEME_RTD` feature flag is defined. - processing `mkdocs.yml` to add internal JS and CSS (embed and analytics) files automatically This is another step forward on removing all the magic we perform on behalf the users and being more explicit about how to configure each doctool. Reference: * readthedocs/addons#72 (comment) Closes #8529 * Enable Addons if project is MkDocs Listen to `Project.post_save` signal and enable Addons if the project was created after a specific date, it's MkDocs and it's the first time the `AddonsConfig` is created. * Listen to Version instead * Typo * Update readthedocs/projects/signals.py Co-authored-by: Santos Gallegos <stsewd@proton.me> * Remove datetime restriction --------- Co-authored-by: Santos Gallegos <stsewd@proton.me>
Details
Our project is using:
MkDocs 1.2.2
Extra Context option in
mkdocs.yml
, with the ENV syntax to read environment variables, making theREADTHEDOCS
vars available to the template context:Attempting to read the RtD environment variables as explained in Build environment and How do I change behavior when building with Read the Docs?.
Expected Result
The
cat mkdocs.yml
build step should show proper values for env varsREADTHEDOCS
,READTHEDOCS_VERSION
, andREADTHEDOCS_PROJECT
.A test html file with these contents:
should print something similar to this in the browser console:
Actual Result
The
cat mkdocs.yml
build step shows thatREADTHEDOCS
,READTHEDOCS_VERSION
, andREADTHEDOCS_PROJECT
are allnull
:The browser console shows this output:
Extra
Question / potential extra bug in the documentation: the technique shown in How do I change behavior when building with Read the Docs? would not really work with MkDocs, would it?
The sample is:
but in MkDocs the
READTHEDOCS
is not directly available, is it expected to be? (sorry to ask here but is just a yes/no question that seems very relevant given the topic of the issue)The text was updated successfully, but these errors were encountered: