Skip to content

Commit f817046

Browse files
authored
Config object: updates following API changes (#32)
Follow changes from readthedocs/readthedocs.org#10216
1 parent dcd5145 commit f817046

8 files changed

+161
-216
lines changed

dist/readthedocs-client.js

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/_/readthedocs-config.json

+94-103
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,107 @@
11
{
2-
"comment": "THIS RESPONSE IS IN ALPHA FOR TEST PURPOSES ONLY AND IT'S GOING TO CHANGE COMPLETELY -- DO NOT USE IT!",
3-
"project": {
4-
"slug": "example",
5-
"language": "en",
6-
"repository_url": "https://github.com/readthedocs/readthedocs-client",
7-
"programming_language": "words"
2+
"comment": "THIS RESPONSE IS IN ALPHA FOR TEST PURPOSES ONLY AND IT'S GOING TO CHANGE COMPLETELY -- DO NOT USE IT!",
3+
"projects": {
4+
"current": {
5+
"slug": "example",
6+
"language": "en",
7+
"repository_url": "https://github.com/readthedocs/readthedocs-client",
8+
"programming_language": "words"
9+
}
10+
},
11+
"versions": {
12+
"current": {
13+
"slug": "v1",
14+
"external": true
15+
}
16+
},
17+
"builds": {
18+
"current": {
19+
"id": 2801
20+
}
21+
},
22+
"domains": {
23+
"dashboard": "devthedocs.org"
24+
},
25+
"readthedocs": {
26+
"analytics": {
27+
"code": null
28+
}
29+
},
30+
"addons": {
31+
"search": {
32+
"enabled": true,
33+
"project": "readthedocs-client",
34+
"version": "latest",
35+
"api_endpoint": "/_/api/v3/search/",
36+
"filters": [
37+
["Search only in this project", "project:readthedocs-client/latest"],
38+
["Search subprojects", "subprojects:readthedocs-client/latest"]
39+
],
40+
"default_filter": "subprojects:readthedocs-client/latest"
841
},
9-
"version": {
10-
"slug": "v1",
11-
"external": true
42+
"analytics": {
43+
"enabled": true,
44+
"code": null
1245
},
13-
"build": {
14-
"id": 2801
46+
"external_version_warning": {
47+
"enabled": true,
48+
"query_selector": "[role=main]"
1549
},
16-
"domains": {
17-
"dashboard": "devthedocs.org"
50+
"non_latest_version_warning": {
51+
"enabled": true,
52+
"query_selector": "[role=main]",
53+
"versions": ["stable", "latest", "v1.0", "v1.4", "v2.0"]
1854
},
19-
"readthedocs": {
20-
"analytics": {
21-
"code": null
22-
}
55+
"doc_diff": {
56+
"enabled": true,
57+
"base_host": "http://test-builds.devthedocs.org",
58+
"base_url": "http://test-builds.devthedocs.org/en/latest/index.html",
59+
"root_selector": "[role=main]",
60+
"inject_styles": true
2361
},
24-
"features": {
25-
"search": {
26-
"project": "readthedocs-client",
27-
"version": "latest",
28-
"api_endpoint": "/_/api/v3/search/",
29-
"filters": [
30-
[
31-
"Search only in this project",
32-
"project:readthedocs-client/latest"
33-
],
34-
[
35-
"Search subprojects",
36-
"subprojects:readthedocs-client/latest"
37-
]
38-
],
39-
"default_filter": "subprojects:readthedocs-client/latest"
40-
},
41-
"analytics": {
42-
"code": null
62+
"flyout": {
63+
"translations": [],
64+
"versions": [
65+
{
66+
"slug": "stable",
67+
"url": "/en/stable/"
4368
},
44-
"external_version_warning": {
45-
"enabled": true,
46-
"query_selector": "[role=main]"
69+
{
70+
"slug": "latest",
71+
"url": "/en/latest/"
4772
},
48-
"non_latest_version_warning": {
49-
"enabled": true,
50-
"query_selector": "[role=main]",
51-
"versions": [
52-
"stable",
53-
"latest",
54-
"v1.0",
55-
"v1.4",
56-
"v2.0"
57-
]
73+
{
74+
"slug": "v1.0",
75+
"url": "/en/v1.0/"
5876
},
59-
"doc_diff": {
60-
"enabled": true,
61-
"base_host": "http://test-builds.devthedocs.org",
62-
"base_url": "http://test-builds.devthedocs.org/en/latest/index.html",
63-
"root_selector": "[role=main]",
64-
"inject_styles": true
77+
{
78+
"slug": "v1.4",
79+
"url": "/en/v1.4/"
6580
},
66-
"flyout": {
67-
"translations": [],
68-
"versions": [
69-
{
70-
"slug": "stable",
71-
"url": "/en/stable/"
72-
},
73-
{
74-
"slug": "latest",
75-
"url": "/en/latest/"
76-
},
77-
{
78-
"slug": "v1.0",
79-
"url": "/en/v1.0/"
80-
},
81-
{
82-
"slug": "v1.4",
83-
"url": "/en/v1.4/"
84-
},
85-
{
86-
"slug": "v2.0",
87-
"url": "/en/v2.0/"
88-
}
89-
],
90-
"downloads": [],
91-
"vcs": {
92-
"url": "https://github.com",
93-
"username": "readthedocs",
94-
"repository": "reathedocs-client",
95-
"branch": "main",
96-
"filepath": "/examples/sphinx/docs/index.rst"
97-
}
98-
},
99-
"search": {
100-
"project": "example",
101-
"version": "latest",
102-
"api_endpoint": "/_/api/v3/search/",
103-
"filters": [
104-
[
105-
"Search only in this project",
106-
"project:example/latest"
107-
],
108-
[
109-
"Search subprojects",
110-
"subprojects:example/latest"
111-
]
112-
],
113-
"default_filter": "subprojects:example/latest"
81+
{
82+
"slug": "v2.0",
83+
"url": "/en/v2.0/"
11484
}
85+
],
86+
"downloads": [],
87+
"vcs": {
88+
"url": "https://github.com",
89+
"username": "readthedocs",
90+
"repository": "reathedocs-client",
91+
"branch": "main",
92+
"filepath": "/examples/sphinx/docs/index.rst"
93+
}
94+
},
95+
"search": {
96+
"enabled": true,
97+
"project": "example",
98+
"version": "latest",
99+
"api_endpoint": "/_/api/v3/search/",
100+
"filters": [
101+
["Search only in this project", "project:example/latest"],
102+
["Search subprojects", "subprojects:example/latest"]
103+
],
104+
"default_filter": "subprojects:example/latest"
115105
}
106+
}
116107
}

src/analytics.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export class AnalyticsAddon extends AddonBase {
2626

2727
registerPageView() {
2828
const params = {
29-
project: this.config.project.slug,
30-
version: this.config.version.slug,
29+
project: this.config.projects.current.slug,
30+
version: this.config.versions.current.slug,
3131
absolute_uri: window.location.href,
3232
};
3333

@@ -75,17 +75,17 @@ export class AnalyticsAddon extends AddonBase {
7575
gtag("config", this.config.readthedocs.analytics.code, {
7676
anonymize_ip: true,
7777
cookie_expires: 0, // Session cookie (non-persistent)
78-
dimension1: this.config.project.slug,
79-
dimension2: this.config.version.slug,
80-
dimension3: this.config.project.language,
81-
dimension5: this.config.project.programming_language,
78+
dimension1: this.config.projects.current.slug,
79+
dimension2: this.config.versions.current.slug,
80+
dimension3: this.config.projects.current.language,
81+
dimension5: this.config.projects.current.programming_language,
8282
groups: "rtfd",
8383
});
8484
}
8585
}
8686
}
8787

8888
static isEnabled(config) {
89-
return config.features && config.features.analytics.enabled;
89+
return config.addons && config.addons.analytics.enabled;
9090
}
9191
}

src/docdiff.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { compare } from "doc-diff";
22

33
export function initializeDocDiff(config) {
4-
if (!config.features.doc_diff.enabled) {
4+
if (!config.addons.doc_diff.enabled) {
55
return false;
66
}
77

8-
return compare(config.features.doc_diff);
8+
return compare(config.addons.doc_diff);
99
}

src/flyout.js

+23-21
Original file line numberDiff line numberDiff line change
@@ -32,47 +32,47 @@ export function injectFlyout(config) {
3232
`;
3333

3434
function get_languages(config) {
35-
if (config.features.flyout.translations.length === 0) {
35+
if (config.addons.flyout.translations.length === 0) {
3636
return "";
3737
}
3838

3939
let result = [
4040
// TODO: how do we handle translations here?
4141
`<dl><dt>Languages</dt>`,
4242
];
43-
for (const language of config.features.flyout.translations) {
43+
for (const language of config.addons.flyout.translations) {
4444
result.push(languageTemplate(language));
4545
}
4646
result.push(`</dl>`);
4747
return result.join("");
4848
}
4949

5050
function get_versions(config) {
51-
if (config.features.flyout.versions.length === 0) {
51+
if (config.addons.flyout.versions.length === 0) {
5252
return "";
5353
}
5454

5555
let result = [
5656
// TODO: how do we handle translations here?
5757
`<dl><dt>Versions</dt>`,
5858
];
59-
for (const version of config.features.flyout.versions) {
59+
for (const version of config.addons.flyout.versions) {
6060
result.push(versionTemplate(version));
6161
}
6262
result.push(`</dl>`);
6363
return result.join("");
6464
}
6565

6666
function get_downloads(config) {
67-
if (config.features.flyout.downloads.length === 0) {
67+
if (config.addons.flyout.downloads.length === 0) {
6868
return "";
6969
}
7070

7171
let result = [
7272
// TODO: how do we handle translations here?
7373
`<dl><dt>Downloads</dt>`,
7474
];
75-
for (const download of config.features.flyout.downloads) {
75+
for (const download of config.addons.flyout.downloads) {
7676
result.push(downloadTemplate(download));
7777
}
7878
result.push(`</dl>`);
@@ -84,7 +84,7 @@ export function injectFlyout(config) {
8484
<div class="rst-versions rst-badge shift-down" data-toggle="rst-versions">
8585
<span class="rst-current-version" data-toggle="rst-current-version">
8686
<span class="fa fa-book">&nbsp;</span>
87-
v: ${config.version.slug}
87+
v: ${config.versions.current.slug}
8888
<span class="fa fa-caret-down"></span>
8989
</span>
9090
<div class="rst-other-versions">
@@ -98,36 +98,36 @@ export function injectFlyout(config) {
9898
<dt>On Read the Docs</dt>
9999
<dd>
100100
<a href="//${config.domains.dashboard}/projects/${
101-
config.project.slug
101+
config.projects.current.slug
102102
}/">Project Home</a>
103103
</dd>
104104
<dd>
105105
<a href="//${config.domains.dashboard}/projects/${
106-
config.project.slug
106+
config.projects.current.slug
107107
}/builds/">Builds</a>
108108
</dd>
109109
<dd>
110110
<a href="//${config.domains.dashboard}/projects/${
111-
config.project.slug
111+
config.projects.current.slug
112112
}/downloads/">Downloads</a>
113113
</dd>
114114
</dl>
115115
116116
<dl>
117117
<dt>On GitHub</dt>
118118
<dd>
119-
<a href="${config.features.flyout.vcs.url}/${
120-
config.features.flyout.vcs.username
121-
}/${config.features.flyout.vcs.repository}/blob/${
122-
config.features.flyout.vcs.branch
123-
}/${config.features.flyout.vcs.filepath}">View</a>
119+
<a href="${config.addons.flyout.vcs.url}/${
120+
config.addons.flyout.vcs.username
121+
}/${config.addons.flyout.vcs.repository}/blob/${
122+
config.addons.flyout.vcs.branch
123+
}/${config.addons.flyout.vcs.filepath}">View</a>
124124
</dd>
125125
<dd>
126-
<a href="${config.features.flyout.vcs.url}/${
127-
config.features.flyout.vcs.username
128-
}/${config.features.flyout.vcs.repository}/edit/${
129-
config.features.flyout.vcs.branch
130-
}/${config.features.flyout.vcs.filepath}">Edit</a>
126+
<a href="${config.addons.flyout.vcs.url}/${
127+
config.addons.flyout.vcs.username
128+
}/${config.addons.flyout.vcs.repository}/edit/${
129+
config.addons.flyout.vcs.branch
130+
}/${config.addons.flyout.vcs.filepath}">Edit</a>
131131
</dd>
132132
</dl>
133133
@@ -137,7 +137,9 @@ export function injectFlyout(config) {
137137
<div style="padding: 6px;">
138138
<form id="flyout-search-form" class="wy-form" target="_blank" action="//${
139139
config.domains.dashboard
140-
}/projects/${config.project.slug}/search/" method="get">
140+
}/projects/${
141+
config.projects.current.slug
142+
}/search/" method="get">
141143
<input type="text" name="q" aria-label="Search docs" placeholder="Search docs">
142144
</form>
143145
</div>

0 commit comments

Comments
 (0)