|
1 | 1 | # Copyright (c) Jupyter Development Team.
|
2 | 2 | # Distributed under the terms of the Modified BSD License.
|
3 | 3 |
|
| 4 | +import os |
4 | 5 | import json
|
5 | 6 |
|
6 | 7 | from tornado import web, gen
|
@@ -79,9 +80,11 @@ def get(self, user, **namespace):
|
79 | 80 | notebooks=notebooks,
|
80 | 81 | description=gist['description'] or '',
|
81 | 82 | ))
|
82 |
| - provider_url = u"https://gist.github.com/{user}".format(user=user) |
| 83 | + gist_url = os.environ.get('GIST_URL', 'https://gist.github.com/') |
| 84 | + provider_url = gist_url + u"{user}".format(user=user) |
83 | 85 | html = self.render_usergists_template(entries=entries, user=user, provider_url=provider_url,
|
84 | 86 | prev_url=prev_url, next_url=next_url, **namespace
|
| 87 | + |
85 | 88 | )
|
86 | 89 | yield self.cache_and_finish(html)
|
87 | 90 |
|
@@ -169,7 +172,8 @@ def get(self, user, gist_id, filename=''):
|
169 | 172 | e['class'] = 'fa-book'
|
170 | 173 | ipynbs.append(e)
|
171 | 174 | else:
|
172 |
| - provider_url = u"https://gist.github.com/{user}/{gist_id}#file-{clean_name}".format( |
| 175 | + gist_url = os.environ.get('GIST_URL', 'https://gist.github.com/') |
| 176 | + provider_url = gist_url + u"{user}/{gist_id}#file-{clean_name}".format( |
173 | 177 | user=user,
|
174 | 178 | gist_id=gist_id,
|
175 | 179 | clean_name=clean_filename(file['filename']),
|
@@ -228,9 +232,19 @@ def default_handlers(handlers=[], **handler_names):
|
228 | 232 |
|
229 | 233 |
|
230 | 234 | def uri_rewrites(rewrites=[]):
|
231 |
| - return [ |
| 235 | + gist_rewrites = [ |
232 | 236 | (r'^([a-f0-9]+)/?$',
|
233 | 237 | u'/{0}'),
|
234 |
| - ('^https?://gist.github.com/([^\/]+/)?([a-f0-9]+)/?$', |
| 238 | + (r'^https?://gist.github.com/([^\/]+/)?([a-f0-9]+)/?$', |
235 | 239 | u'/{1}'),
|
236 |
| - ] + rewrites |
| 240 | + ] |
| 241 | + # github enterprise |
| 242 | + if os.environ.get('GIST_URL', '') != '': |
| 243 | + gist_url = os.environ.get('GIST_URL') |
| 244 | + gist_rewrites.extend([ |
| 245 | + # embedded in URL |
| 246 | + (r'^' + gist_url + r'([^\/]+/)?([a-f0-9]+)/?$', |
| 247 | + u'/{1}'), |
| 248 | + ]) |
| 249 | + |
| 250 | + return gist_rewrites + rewrites |
0 commit comments