@@ -237,6 +237,16 @@ def _fix_relative_urls(self, url, tag_name, attr_name):
237237 # URLs /plain, /info, /info/model, /info/template.
238238 exercise_info = re .compile (r'/((plain)|(info(/model|/template)?))/?(#.+)?$' )
239239
240+ # If Gitmanager is in use, fix relative static URLs to that host
241+ if settings .GITMANAGER_URL :
242+ gmurl = urlparse (settings .GITMANAGER_URL )
243+ if settings .REMOTE_PAGE_HOSTS_MAP :
244+ domain = settings .REMOTE_PAGE_HOSTS_MAP .get (gmurl .netloc , gmurl .netloc )
245+ gmurl = gmurl ._replace (netloc = domain )
246+ staticurl = url ._replace (scheme = gmurl .scheme , netloc = gmurl .netloc )
247+ else :
248+ staticurl = url
249+
240250 for element in self .soup .find_all (tag_name , {attr_name :True }):
241251 value = element [attr_name ]
242252 if not value :
@@ -312,15 +322,16 @@ def _fix_relative_urls(self, url, tag_name, attr_name):
312322
313323 # url points to the exercise service, e.g., MOOC-Grader.
314324 # This fixes links to static files (such as images) in RST chapters.
315- # The image URL must be absolute and refer to the grader server
316- # instead of the A+ server. A relative URL with only path
317- # "/static/course/image.png" would target the A+ server when
318- # it is included in the A+ page. The value should be a relative
325+ # The image URL must be absolute and refer to the server with static content
326+ # instead of the A+ server. Traditionally this has been the grader server, but
327+ # recently gitmanager is used. If GITMANAGER_URL is specified, we assume gitmanager.
328+ # A relative URL with only path "/static/course/image.png" would target the A+ server
329+ # when it is included in the A+ page. The value should be a relative
319330 # path in the course build directory so that it becomes the full
320331 # correct URL to the target file.
321332 # E.g., urljoin('http://localhost:8080/static/default/module1/chapter.html', "../_images/image.png")
322333 # -> 'http://localhost:8080/static/default/_images/image.png'
323- element [attr_name ] = urljoin (url .geturl (), value )
334+ element [attr_name ] = urljoin (staticurl .geturl (), value )
324335
325336 def find_and_replace (self , attr_name , list_of_attributes ):
326337 l = len (list_of_attributes )
0 commit comments