Skip to content

Commit 69cbafc

Browse files
committed
Add search and next/prev
1 parent d243538 commit 69cbafc

File tree

3 files changed

+116
-1
lines changed

3 files changed

+116
-1
lines changed

docs/css/default.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,14 @@ footer a {
277277
footer a:hover {
278278
color: gray;
279279
}
280+
281+
.btn-inverse {
282+
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#606060), to(#404040)) !important;
283+
background-image: -webkit-linear-gradient(top, #606060, #404040) !important;
284+
}
285+
286+
.modal-open .modal,.btn:focus{outline:none;}
287+
288+
@media (max-width: 650px) {
289+
.repo-link.btn-inverse {display: none;}
290+
}

docs/template.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
<div class="navbar-inner">
4242
<div class="container-fluid">
4343
<a class="repo-link btn btn-primary btn-small" href="https://github.com/tomchristie/django-rest-framework/tree/master">GitHub</a>
44+
<a class="repo-link btn btn-inverse btn-small {{ next_url_disabled }}" href="{{ next_url }}">Next <i class="icon-arrow-right icon-white"></i></a>
45+
<a class="repo-link btn btn-inverse btn-small {{ prev_url_disabled }}" href="{{ prev_url }}"><i class="icon-arrow-left icon-white"></i> Previous</a>
46+
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
4447
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
4548
<span class="icon-bar"></span>
4649
<span class="icon-bar"></span>
@@ -118,6 +121,34 @@
118121

119122
<div class="body-content">
120123
<div class="container-fluid">
124+
125+
<!-- Search Modal -->
126+
<div id="searchModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
127+
<div class="modal-header">
128+
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
129+
<h3 id="myModalLabel">Documentation search</h3>
130+
</div>
131+
<div class="modal-body">
132+
<!-- Custom google search -->
133+
<script>
134+
(function() {
135+
var cx = '015016005043623903336:rxraeohqk6w';
136+
var gcse = document.createElement('script');
137+
gcse.type = 'text/javascript';
138+
gcse.async = true;
139+
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
140+
'//www.google.com/cse/cse.js?cx=' + cx;
141+
var s = document.getElementsByTagName('script')[0];
142+
s.parentNode.insertBefore(gcse, s);
143+
})();
144+
</script>
145+
<gcse:search></gcse:search>
146+
</div>
147+
<div class="modal-footer">
148+
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
149+
</div>
150+
</div>
151+
121152
<div class="row-fluid">
122153

123154
<div class="span3">

mkdocs.py

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,60 @@
3737
# shutil.rmtree(target)
3838
# shutil.copytree(source, target)
3939

40+
41+
# Hacky, but what the hell, it'll do the job
42+
path_list = [
43+
'index.md',
44+
'tutorial/quickstart.md',
45+
'tutorial/1-serialization.md',
46+
'tutorial/2-requests-and-responses.md',
47+
'tutorial/3-class-based-views.md',
48+
'tutorial/4-authentication-and-permissions.md',
49+
'tutorial/5-relationships-and-hyperlinked-apis.md',
50+
'api-guide/requests.md',
51+
'api-guide/responses.md',
52+
'api-guide/views.md',
53+
'api-guide/generic-views.md',
54+
'api-guide/parsers.md',
55+
'api-guide/renderers.md',
56+
'api-guide/serializers.md',
57+
'api-guide/fields.md',
58+
'api-guide/relations.md',
59+
'api-guide/authentication.md',
60+
'api-guide/permissions.md',
61+
'api-guide/throttling.md',
62+
'api-guide/filtering.md',
63+
'api-guide/pagination.md',
64+
'api-guide/content-negotiation.md',
65+
'api-guide/format-suffixes.md',
66+
'api-guide/reverse.md',
67+
'api-guide/exceptions.md',
68+
'api-guide/status-codes.md',
69+
'api-guide/settings.md',
70+
'topics/ajax-csrf-cors.md',
71+
'topics/browser-enhancements.md',
72+
'topics/browsable-api.md',
73+
'topics/rest-hypermedia-hateoas.md',
74+
'topics/contributing.md',
75+
'topics/rest-framework-2-announcement.md',
76+
'topics/2.2-announcement.md',
77+
'topics/release-notes.md',
78+
'topics/credits.md',
79+
]
80+
81+
prev_url_map = {}
82+
next_url_map = {}
83+
for idx in range(len(path_list)):
84+
path = path_list[idx]
85+
rel = '../' * path.count('/')
86+
87+
if idx > 0:
88+
prev_url_map[path] = rel + path_list[idx - 1][:-3] + suffix
89+
90+
if idx < len(path_list) - 1:
91+
next_url_map[path] = rel + path_list[idx + 1][:-3] + suffix
92+
93+
4094
for (dirpath, dirnames, filenames) in os.walk(docs_dir):
4195
relative_dir = dirpath.replace(docs_dir, '').lstrip(os.path.sep)
4296
build_dir = os.path.join(html_dir, relative_dir)
@@ -46,6 +100,7 @@
46100

47101
for filename in filenames:
48102
path = os.path.join(dirpath, filename)
103+
relative_path = os.path.join(relative_dir, filename)
49104

50105
if not filename.endswith('.md'):
51106
if relative_dir:
@@ -78,16 +133,34 @@
78133
toc += template + '\n'
79134

80135
if filename == 'index.md':
81-
main_title = 'Django REST framework - APIs made easy'
136+
main_title = 'Django REST framework - Web Browseable APIs'
82137
else:
83138
main_title = 'Django REST framework - ' + main_title
84139

140+
prev_url = prev_url_map.get(relative_path)
141+
next_url = next_url_map.get(relative_path)
142+
85143
content = markdown.markdown(text, ['headerid'])
86144

87145
output = page.replace('{{ content }}', content).replace('{{ toc }}', toc).replace('{{ base_url }}', base_url).replace('{{ suffix }}', suffix).replace('{{ index }}', index)
88146
output = output.replace('{{ title }}', main_title)
89147
output = output.replace('{{ description }}', description)
90148
output = output.replace('{{ page_id }}', filename[:-3])
149+
150+
if prev_url:
151+
output = output.replace('{{ prev_url }}', prev_url)
152+
output = output.replace('{{ prev_url_disabled }}', '')
153+
else:
154+
output = output.replace('{{ prev_url }}', '#')
155+
output = output.replace('{{ prev_url_disabled }}', 'disabled')
156+
157+
if next_url:
158+
output = output.replace('{{ next_url }}', next_url)
159+
output = output.replace('{{ next_url_disabled }}', '')
160+
else:
161+
output = output.replace('{{ next_url }}', '#')
162+
output = output.replace('{{ next_url_disabled }}', 'disabled')
163+
91164
output = re.sub(r'a href="([^"]*)\.md"', r'a href="\1%s"' % suffix, output)
92165
output = re.sub(r'<pre><code>:::bash', r'<pre class="prettyprint lang-bsh">', output)
93166
output = re.sub(r'<pre>', r'<pre class="prettyprint lang-py">', output)

0 commit comments

Comments
 (0)