@@ -99,34 +99,18 @@ def resolve_path(
99
99
cname = None ,
100
100
):
101
101
"""Resolve a URL with a subset of fields defined."""
102
- cname = cname or project .get_canonical_custom_domain ()
103
102
version_slug = version_slug or project .get_default_version ()
104
103
language = language or project .language
105
104
106
105
filename = self ._fix_filename (project , filename )
107
106
108
- current_project = project
109
- project_slug = project .slug
110
- subproject_slug = None
111
- # We currently support more than 2 levels of nesting subprojects and
112
- # translations, only loop twice to avoid sticking in the loop
113
- for _ in range (0 , 2 ):
114
- main_language_project = current_project .main_language_project
115
- relation = current_project .get_parent_relationship ()
116
-
117
- if main_language_project :
118
- current_project = main_language_project
119
- project_slug = main_language_project .slug
120
- language = project .language
121
- subproject_slug = None
122
- elif relation :
123
- current_project = relation .parent
124
- project_slug = relation .parent .slug
125
- subproject_slug = relation .alias
126
- cname = relation .parent .domains .filter (canonical = True ).first ()
127
- else :
128
- break
129
-
107
+ main_project , subproject_slug = self ._get_canonical_project_data (project )
108
+ project_slug = main_project .slug
109
+ cname = (
110
+ cname
111
+ or self ._use_subdomain ()
112
+ or main_project .get_canonical_custom_domain ()
113
+ )
130
114
single_version = bool (project .single_version or single_version )
131
115
132
116
return self .base_resolve_path (
@@ -195,6 +179,68 @@ def resolve(
195
179
)
196
180
return urlunparse ((protocol , domain , path , '' , query_params , '' ))
197
181
182
+ def _get_canonical_project_data (self , project ):
183
+ """
184
+ Returns a tuple with (project, subproject_slug) from the canonical project of `project`.
185
+
186
+ We currently support more than 2 levels of nesting subprojects and translations,
187
+ but we only serve 2 levels to avoid sticking in the loop.
188
+ This means, we can have the following cases:
189
+
190
+ - The project isn't a translation or subproject
191
+
192
+ We serve the documentation from the domain of the project itself
193
+ (main.docs.com/).
194
+
195
+ - The project is a translation of a project
196
+
197
+ We serve the documentation from the domain of the main translation
198
+ (main.docs.com/es/).
199
+
200
+ - The project is a subproject of a project
201
+
202
+ We serve the documentation from the domain of the super project
203
+ (main.docs.com/projects/subproject/).
204
+
205
+ - The project is a translation, and the main translation is a subproject of a project, like:
206
+
207
+ - docs
208
+ - api (subproject of ``docs``)
209
+ - api-es (translation of ``api``, and current project to be served)
210
+
211
+ We serve the documentation from the domain of the super project
212
+ (docs.docs.com/projects/api/es/).
213
+
214
+ - The project is a subproject, and the superproject is a translation of a project, like:
215
+
216
+ - docs
217
+ - docs-es (translation of ``docs``)
218
+ - api-es (subproject of ``docs-es``, and current project to be served)
219
+
220
+ We serve the documentation from the domain of the super project (the translation),
221
+ this is docs-es.docs.com/projects/api-es/es/.
222
+ We aren't going to support this case for now.
223
+
224
+ In summary: If the project is a subproject,
225
+ we don't care if the superproject is a translation,
226
+ we always serve from the domain of the superproject.
227
+ If the project is a translation,
228
+ we need to check if the main translation is a subproject.
229
+ """
230
+ main_project = project
231
+ subproject_slug = None
232
+
233
+ main_language_project = main_project .main_language_project
234
+ if main_language_project :
235
+ main_project = main_language_project
236
+
237
+ relation = main_project .get_parent_relationship ()
238
+ if relation :
239
+ main_project = relation .parent
240
+ subproject_slug = relation .alias
241
+
242
+ return (main_project , subproject_slug )
243
+
198
244
def _get_canonical_project (self , project , projects = None ):
199
245
"""
200
246
Recursively get canonical project for subproject or translations.
0 commit comments