-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Hosting: manual integrations via build contract #10127
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
5b28071
Hosting: manual integrations via build contract
humitos e18b40f
Use a single script to load everything
humitos 7754d5f
Include Read the Docs analytics to integrations
humitos 2925ed9
Initial work for hosting features
humitos 3385649
External version banner and doc-diff integration
humitos 1e391b8
Old version warning
humitos 6afca0b
Do not inject doc-diff on search page
humitos 7ce98a4
Inject old version warning only for non-external versions
humitos 3ca96ec
Comments!
humitos f4f1268
More comments
humitos a596512
Build: pass `PATH` environment variable to Docker container
humitos 33fdb2b
Lint: for some reason fails at CircleCI otherwise
humitos 4ced5c3
Merge branch 'humitos/build-cmd-environment' of github.com:readthedoc…
humitos ea2af4c
Feature flag for new hosting integrations
humitos 79b7393
Load `readthedocs-build.yaml` and generate `readthedocs-data.html`
humitos 17effaf
Load READTHEDOCS_DATA async
humitos 2b9cdbf
Absolute proxied API path
humitos 0116f41
Remove duplicated code
humitos d5130cc
New approach using `readthedocs-client.js` and `/_/readthedocs-config…
humitos 761e3b6
Do not require `readthedocs-build.YAML` for now
humitos bd9f70e
Expand the JSON response with more data
humitos 842a228
Remove non-required files and rely on `readthedocs-client.js` only
humitos 2ad30cc
Improve helper text
humitos 89662fa
Builds: save `readthedocs-build.yaml` into database
humitos f83eee6
Use `Version.build_data` from the endpoint
humitos d14115a
Flyout: return data required to generate flyout dynamically
humitos 067bb4c
Updates to the API
humitos 17c1af3
Minor updates
humitos 53366aa
Update the javascript client compiled version
humitos 0f89186
doc-diff object returned
humitos 48de597
Build: check if the YAML file exists before trying to open it
humitos 4b05e77
Proxito: don't inject the header if the feature is turned off
humitos e90af75
Merge branch 'main' of github.com:readthedocs/readthedocs.org into hu…
humitos 364de9c
Test: add hosting integrations tests
humitos c1cf8cb
Remove JS
humitos 3930915
Load the javascript from a local server for now
humitos 2d7b6fe
Update URL to remove .json from it
humitos ab43635
Remove non-required f-string
humitos 85ab2e7
Allow saving `build_data` via API endpoint
humitos 3439e24
Merge branch 'main' of github.com:readthedocs/readthedocs.org into hu…
humitos 6154c7f
Lint
humitos 0e8f245
Migrate nodejs installation to asdf
humitos a6c5977
Change port to match `npm run dev` from readthedocs-client
humitos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,26 @@ | ||
// Unique entry point that our servers will inject | ||
|
||
let link = document.createElement("link"); | ||
link.setAttribute("rel", "stylesheet"); | ||
link.setAttribute("type", "text/css"); | ||
link.setAttribute("href", "/_/static/css/readthedocs-doc-embed.css"); | ||
document.head.appendChild(link); | ||
|
||
let embed = document.createElement("script"); | ||
embed.setAttribute("async", "async"); | ||
embed.setAttribute("src", "/_/static/javascript/readthedocs-doc-embed.js"); | ||
document.head.appendChild(embed); | ||
|
||
let analytics = document.createElement("script"); | ||
analytics.setAttribute("async", "async"); | ||
analytics.setAttribute("src", "/_/static/javascript/readthedocs-analytics.js"); | ||
document.head.appendChild(analytics); | ||
|
||
let hosting = document.createElement("script"); | ||
hosting.setAttribute("async", "async"); | ||
hosting.setAttribute("src", "/_/static/core/js/readthedocs-hosting.js"); | ||
document.head.appendChild(hosting); | ||
|
||
// TODO: insert search-as-you-type once it becomes a JS library | ||
// decoupled from Sphinx. | ||
// See https://github.com/readthedocs/readthedocs-sphinx-search/issues/67 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,75 @@ | ||
function injectExternalVersionWarning() { | ||
// TODO: make all these banners (injected HTML) templates that users can override with their own. | ||
// This way, we allow customization of the look&feel without compromising the logic. | ||
let admonition = ` | ||
<div class="admonition warning"> | ||
<p class="admonition-title">Warning</p> | ||
<p> | ||
This page | ||
<a class="reference external" href="${ window.location.protocol }//${ window.location.hostname }/projects/${ READTHEDOCS_DATA.project }/builds/${ READTHEDOCS_DATA.build.id }/">was created </a> | ||
from a pull request | ||
(<a class="reference external" href="${ READTHEDOCS_DATA.repository_url }/pull/${ READTHEDOCS_DATA.version }">#${ READTHEDOCS_DATA.version }</a>). | ||
</p> | ||
</div> | ||
`; | ||
|
||
let main = document.querySelector('[role=main]'); | ||
let node = document.createElement("div"); | ||
node.innerHTML = admonition; | ||
main.insertBefore(node, main.firstChild); | ||
} | ||
|
||
function injectDocDiff() { | ||
let docdiff = document.createElement("script"); | ||
docdiff.setAttribute("async", "async"); | ||
docdiff.setAttribute("src", "/_/static/core/js/readthedocs-doc-diff.js"); | ||
document.head.appendChild(docdiff); | ||
} | ||
|
||
function injectOldVersionWarning() { | ||
// TODO: compute if the user is reading the latest version or not before showing the warning. | ||
let admonition = ` | ||
<div class="admonition warning"> | ||
<p class="admonition-title">Warning</p> | ||
<p> | ||
This page documents version | ||
<a class="reference" href="${ window.location.protocol }//${ window.location.hostname }/${ READTHEDOCS_DATA.language }/${ READTHEDOCS_DATA.version }/">${ READTHEDOCS_DATA.version }</a>. | ||
The latest version is | ||
<a class="reference" href="${ window.location.protocol }//${ window.location.hostname }/${ READTHEDOCS_DATA.language }/${ READTHEDOCS_DATA.version }/">${ READTHEDOCS_DATA.version }</a>. | ||
</p> | ||
</div> | ||
`; | ||
|
||
// Borrowed and adapted from: | ||
// https://github.com/readthedocs/readthedocs.org/blob/7ce98a4d4f34a4c1845dc6e3e0e5112af7c39b0c/readthedocs/core/static-src/core/js/doc-embed/version-compare.js#L1 | ||
let main = document.querySelector('[role=main]'); | ||
let node = document.createElement("div"); | ||
node.innerHTML = admonition; | ||
main.insertBefore(node, main.firstChild); | ||
} | ||
|
||
|
||
window.addEventListener("load", (event) => { | ||
// TODO: use the proxied API here | ||
// "repository_url" could be retrived using the API, but there are some CORS issues and design decisions | ||
// that it's probably smart to avoid and just rely on a fixed value from the build output :) | ||
if (READTHEDOCS_DATA.build.external_version === true) { | ||
injectExternalVersionWarning(); | ||
|
||
if (READTHEDOCS_DATA.features.docdiff.enabled === true) { | ||
if(!window.location.pathname.endsWith("search.html")) { | ||
// Avoid injecting doc-diff on search page because it doesn't make sense | ||
injectDocDiff(); | ||
} | ||
} | ||
} | ||
else { | ||
// TODO: there some data we need from `/api/v2/footer_html/`, | ||
// like `is_highest` and `show_version_warning`. | ||
// However, this call is happening inside the `readthedocs-doc-embed.js`. | ||
// We could make the call again here for now as demo, | ||
// but it would be good to refactor that code | ||
// Inject old version warning only for non-external versions | ||
injectOldVersionWarning(); | ||
} | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.