Skip to content

Commit 2237803

Browse files
committed
Fix Gist support for GHE
1 parent 51317e6 commit 2237803

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

nbviewer/providers/gist/handlers.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
33

4+
import os
45
import json
56

67
from tornado import web, gen
@@ -79,9 +80,11 @@ def get(self, user, **namespace):
7980
notebooks=notebooks,
8081
description=gist['description'] or '',
8182
))
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)
8385
html = self.render_usergists_template(entries=entries, user=user, provider_url=provider_url,
8486
prev_url=prev_url, next_url=next_url, **namespace
87+
8588
)
8689
yield self.cache_and_finish(html)
8790

@@ -169,7 +172,8 @@ def get(self, user, gist_id, filename=''):
169172
e['class'] = 'fa-book'
170173
ipynbs.append(e)
171174
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(
173177
user=user,
174178
gist_id=gist_id,
175179
clean_name=clean_filename(file['filename']),
@@ -228,9 +232,19 @@ def default_handlers(handlers=[], **handler_names):
228232

229233

230234
def uri_rewrites(rewrites=[]):
231-
return [
235+
gist_rewrites = [
232236
(r'^([a-f0-9]+)/?$',
233237
u'/{0}'),
234-
('^https?://gist.github.com/([^\/]+/)?([a-f0-9]+)/?$',
238+
(r'^https?://gist.github.com/([^\/]+/)?([a-f0-9]+)/?$',
235239
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

Comments
 (0)