Skip to content

Commit a0f66ff

Browse files
committed
Merge pull request #2849 from d0ugal/master
Migrate from Google search to MkDocs.
2 parents 24855f7 + daad630 commit a0f66ff

File tree

7 files changed

+123
-294
lines changed

7 files changed

+123
-294
lines changed

docs_theme/404.html

+6-213
Original file line numberDiff line numberDiff line change
@@ -1,216 +1,9 @@
1-
<!DOCTYPE html>
2-
<html lang="en">
1+
{% extends "base.html" %}
32

4-
<head>
5-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6-
<meta charset="utf-8">
7-
<title>Django REST framework - 404 - Page not found</title>
8-
<link href="http://www.django-rest-framework.org/img/favicon.ico" rel="icon" type="image/x-icon">
9-
<link rel="canonical" href="http://www.django-rest-framework.org/404" />
10-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
11-
<meta name="description" content="Django, API, REST, 404 - Page not found">
12-
<meta name="author" content="Tom Christie">
3+
{% block content %}
134

14-
<!-- Le styles -->
15-
<link href="http://www.django-rest-framework.org/css/prettify.css" rel="stylesheet">
16-
<link href="http://www.django-rest-framework.org/css/bootstrap.css" rel="stylesheet">
17-
<link href="http://www.django-rest-framework.org/css/bootstrap-responsive.css" rel="stylesheet">
18-
<link href="http://www.django-rest-framework.org/css/default.css" rel="stylesheet">
5+
<h1 id="404-page-not-found" style="text-align: center">404</h1>
6+
<p style="text-align: center"><strong>Page not found</strong></p>
7+
<p style="text-align: center">Try the <a href="http://www.django-rest-framework.org/">homepage</a>, or <a href="#searchModal" data-toggle="modal">search the documentation</a>.</p>
198

20-
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
21-
<!--[if lt IE 9]>
22-
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
23-
<![endif]-->
24-
25-
<script type="text/javascript">
26-
var _gaq = _gaq || [];
27-
_gaq.push(['_setAccount', 'UA-18852272-2']);
28-
_gaq.push(['_trackPageview']);
29-
30-
(function() {
31-
var ga = document.createElement('script');
32-
ga.type = 'text/javascript';
33-
ga.async = true;
34-
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
35-
var s = document.getElementsByTagName('script')[0];
36-
s.parentNode.insertBefore(ga, s);
37-
})();
38-
</script>
39-
</head>
40-
41-
<body onload="prettyPrint()" class="404-page">
42-
43-
<div class="wrapper">
44-
45-
<div class="navbar navbar-inverse navbar-fixed-top">
46-
<div class="navbar-inner">
47-
<div class="container-fluid">
48-
<a class="repo-link btn btn-primary btn-small" href="https://github.com/tomchristie/django-rest-framework/tree/master">GitHub</a>
49-
<a class="repo-link btn btn-inverse btn-small disabled" href="#">Next <i class="icon-arrow-right icon-white"></i></a>
50-
<a class="repo-link btn btn-inverse btn-small disabled" href="#"><i class="icon-arrow-left icon-white"></i> Previous</a>
51-
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
52-
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
53-
<span class="icon-bar"></span>
54-
<span class="icon-bar"></span>
55-
<span class="icon-bar"></span>
56-
</a>
57-
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
58-
<div class="nav-collapse collapse">
59-
<ul class="nav">
60-
<li><a href="http://www.django-rest-framework.org">Home</a></li>
61-
<li class="dropdown">
62-
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
63-
<ul class="dropdown-menu">
64-
<li><a href="http://www.django-rest-framework.org/tutorial/quickstart">Quickstart</a></li>
65-
<li><a href="http://www.django-rest-framework.org/tutorial/1-serialization">1 - Serialization</a></li>
66-
<li><a href="http://www.django-rest-framework.org/tutorial/2-requests-and-responses">2 - Requests and responses</a></li>
67-
<li><a href="http://www.django-rest-framework.org/tutorial/3-class-based-views">3 - Class based views</a></li>
68-
<li><a href="http://www.django-rest-framework.org/tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a></li>
69-
<li><a href="http://www.django-rest-framework.org/tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a></li>
70-
<li><a href="http://www.django-rest-framework.org/tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a></li>
71-
</ul>
72-
</li>
73-
<li class="dropdown">
74-
<a href="#" class="dropdown-toggle" data-toggle="dropdown">API Guide <b class="caret"></b></a>
75-
<ul class="dropdown-menu">
76-
<li><a href="http://www.django-rest-framework.org/api-guide/requests">Requests</a></li>
77-
<li><a href="http://www.django-rest-framework.org/api-guide/responses">Responses</a></li>
78-
<li><a href="http://www.django-rest-framework.org/api-guide/views">Views</a></li>
79-
<li><a href="http://www.django-rest-framework.org/api-guide/generic-views">Generic views</a></li>
80-
<li><a href="http://www.django-rest-framework.org/api-guide/viewsets">Viewsets</a></li>
81-
<li><a href="http://www.django-rest-framework.org/api-guide/routers">Routers</a></li>
82-
<li><a href="http://www.django-rest-framework.org/api-guide/parsers">Parsers</a></li>
83-
<li><a href="http://www.django-rest-framework.org/api-guide/renderers">Renderers</a></li>
84-
<li><a href="http://www.django-rest-framework.org/api-guide/serializers">Serializers</a></li>
85-
<li><a href="http://www.django-rest-framework.org/api-guide/fields">Serializer fields</a></li>
86-
<li><a href="http://www.django-rest-framework.org/api-guide/relations">Serializer relations</a></li>
87-
<li><a href="http://www.django-rest-framework.org/api-guide/authentication">Authentication</a></li>
88-
<li><a href="http://www.django-rest-framework.org/api-guide/permissions">Permissions</a></li>
89-
<li><a href="http://www.django-rest-framework.org/api-guide/throttling">Throttling</a></li>
90-
<li><a href="http://www.django-rest-framework.org/api-guide/filtering">Filtering</a></li>
91-
<li><a href="http://www.django-rest-framework.org/api-guide/pagination">Pagination</a></li>
92-
<li><a href="http://www.django-rest-framework.org/api-guide/content-negotiation">Content negotiation</a></li>
93-
<li><a href="http://www.django-rest-framework.org/api-guide/format-suffixes">Format suffixes</a></li>
94-
<li><a href="http://www.django-rest-framework.org/api-guide/reverse">Returning URLs</a></li>
95-
<li><a href="http://www.django-rest-framework.org/api-guide/exceptions">Exceptions</a></li>
96-
<li><a href="http://www.django-rest-framework.org/api-guide/status-codes">Status codes</a></li>
97-
<li><a href="http://www.django-rest-framework.org/api-guide/testing">Testing</a></li>
98-
<li><a href="http://www.django-rest-framework.org/api-guide/settings">Settings</a></li>
99-
</ul>
100-
</li>
101-
<li class="dropdown">
102-
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Topics <b class="caret"></b></a>
103-
<ul class="dropdown-menu">
104-
<li><a href="http://www.django-rest-framework.org/topics/documenting-your-api">Documenting your API</a></li>
105-
<li><a href="http://www.django-rest-framework.org/topics/ajax-csrf-cors">AJAX, CSRF & CORS</a></li>
106-
<li><a href="http://www.django-rest-framework.org/topics/browser-enhancements">Browser enhancements</a></li>
107-
<li><a href="http://www.django-rest-framework.org/topics/browsable-api">The Browsable API</a></li>
108-
<li><a href="http://www.django-rest-framework.org/topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a></li>
109-
<li><a href="http://www.django-rest-framework.org/topics/rest-framework-2-announcement">2.0 Announcement</a></li>
110-
<li><a href="http://www.django-rest-framework.org/topics/2.2-announcement">2.2 Announcement</a></li>
111-
<li><a href="http://www.django-rest-framework.org/topics/2.3-announcement">2.3 Announcement</a></li>
112-
<li><a href="http://www.django-rest-framework.org/topics/release-notes">Release Notes</a></li>
113-
<li><a href="http://www.django-rest-framework.org/topics/credits">Credits</a></li>
114-
</ul>
115-
</li>
116-
</ul>
117-
<ul class="nav pull-right">
118-
<!-- TODO
119-
<li class="dropdown">
120-
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Version: 2.0.0 <b class="caret"></b></a>
121-
<ul class="dropdown-menu">
122-
<li><a href="#">Trunk</a></li>
123-
<li><a href="#">2.0.0</a></li>
124-
</ul>
125-
</li>
126-
-->
127-
</ul>
128-
</div>
129-
<!--/.nav-collapse -->
130-
</div>
131-
</div>
132-
</div>
133-
134-
<div class="body-content">
135-
<div class="container-fluid">
136-
<!-- Search Modal -->
137-
<div id="searchModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
138-
<div class="modal-header">
139-
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
140-
<h3 id="myModalLabel">Documentation search</h3>
141-
</div>
142-
<div class="modal-body">
143-
<!-- Custom google search -->
144-
<script>
145-
(function() {
146-
var cx = '015016005043623903336:rxraeohqk6w';
147-
var gcse = document.createElement('script');
148-
gcse.type = 'text/javascript';
149-
gcse.async = true;
150-
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
151-
'//www.google.com/cse/cse.js?cx=' + cx;
152-
var s = document.getElementsByTagName('script')[0];
153-
s.parentNode.insertBefore(gcse, s);
154-
})();
155-
</script>
156-
<gcse:search></gcse:search>
157-
</div>
158-
<div class="modal-footer">
159-
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
160-
</div>
161-
</div>
162-
163-
<div class="row-fluid">
164-
<div id="main-content" class="span12">
165-
<h1 id="404-page-not-found" style="text-align: center">404</h1>
166-
<p style="text-align: center"><strong>Page not found</strong>
167-
</p>
168-
<p style="text-align: center">Try the <a href="http://www.django-rest-framework.org/">homepage</a>, or <a href="#searchModal" data-toggle="modal">search the documentation</a>.</p>
169-
</div>
170-
<!--/span-->
171-
</div>
172-
<!--/row-->
173-
</div>
174-
<!--/.fluid-container-->
175-
</div>
176-
<!--/.body content-->
177-
178-
<div id="push"></div>
179-
</div>
180-
<!--/.wrapper -->
181-
182-
<footer class="span12">
183-
<p>Sponsored by <a href="http://dabapps.com/">DabApps</a>.</a>
184-
</p>
185-
</footer>
186-
187-
<!-- Le javascript
188-
================================================== -->
189-
<!-- Placed at the end of the document so the pages load faster -->
190-
<script src="http://www.django-rest-framework.org/js/jquery-1.8.1-min.js"></script>
191-
<script src="http://www.django-rest-framework.org/js/prettify-1.0.js"></script>
192-
<script src="http://www.django-rest-framework.org/js/bootstrap-2.1.1-min.js"></script>
193-
<script>
194-
//$('.side-nav').scrollspy()
195-
var shiftWindow = function() {
196-
scrollBy(0, -50)
197-
};
198-
if (location.hash) shiftWindow();
199-
window.addEventListener("hashchange", shiftWindow);
200-
201-
$('.dropdown-menu').on('click touchstart', function(event) {
202-
event.stopPropagation();
203-
});
204-
205-
// Dynamically force sidenav to no higher than browser window
206-
$('.side-nav').css('max-height', window.innerHeight - 130);
207-
208-
$(function() {
209-
$(window).resize(function() {
210-
$('.side-nav').css('max-height', window.innerHeight - 130);
211-
});
212-
});
213-
</script>
214-
</body>
215-
216-
</html>
9+
{% endblock %}

docs_theme/base.html

+30-30
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<head>
55
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
66
<meta charset="utf-8">
7-
<title>{{ page_title }}</title>
7+
<title>{% if page_title %}{{ page_title }} - {% endif %}{{ site_name }}</title>
88
<link href="{{ base_url }}/img/favicon.ico" rel="icon" type="image/x-icon">
99
<link rel="canonical" href="{{ canonical_url }}" />
1010
<meta name="viewport" content="width=device-width, initial-scale=1.0">
11-
<meta name="description" content="Django, API, REST, {{ current_page.title }}">
11+
<meta name="description" content="Django, API, REST{% if current_page %}, {{ current_page.title }}{% endif %}">
1212
<meta name="author" content="Tom Christie">
1313

1414
<!-- Le styles -->
@@ -54,7 +54,7 @@
5454
}
5555
</style>
5656
</head>
57-
<body onload="prettyPrint()" class="{% if current_page.is_homepage %}index{% endif %}-page">
57+
<body onload="prettyPrint()" class="{% if current_page and current_page.is_homepage %}index{% endif %}-page">
5858

5959
<div class="wrapper">
6060

@@ -64,27 +64,19 @@
6464
<div class="container-fluid">
6565

6666
<!-- Search Modal -->
67-
<div id="searchModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
67+
<div id="mkdocs_search_modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
6868
<div class="modal-header">
6969
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
7070
<h3 id="myModalLabel">Documentation search</h3>
7171
</div>
7272

7373
<div class="modal-body">
74-
<!-- Custom google search -->
75-
<script>
76-
(function() {
77-
var cx = '015016005043623903336:rxraeohqk6w';
78-
var gcse = document.createElement('script');
79-
gcse.type = 'text/javascript';
80-
gcse.async = true;
81-
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
82-
'//www.google.com/cse/cse.js?cx=' + cx;
83-
var s = document.getElementsByTagName('script')[0];
84-
s.parentNode.insertBefore(gcse, s);
85-
})();
86-
</script>
87-
<gcse:search></gcse:search>
74+
<form role="form">
75+
<div class="form-group">
76+
<input type="text" name="q" class="form-control" placeholder="Search..." id="mkdocs-search-query">
77+
</div>
78+
</form>
79+
<div id="mkdocs-search-results"></div>
8880
</div>
8981

9082
<div class="modal-footer">
@@ -104,15 +96,15 @@ <h3 id="myModalLabel">Documentation search</h3>
10496
<div id="table-of-contents">
10597
<ul class="nav nav-list side-nav well sidebar-nav-fixed">
10698

107-
{% if current_page.is_homepage %}
99+
{% if current_page and current_page.is_homepage %}
108100
<li class="main">
109101
<a href="#">Django REST framework</a>
110102
</li>
111103
{% endif %}
112104

113105
{% for toc_item in toc %}
114106

115-
<li class="{% if not current_page.is_homepage %}main{% endif %}">
107+
<li class="{% if current_page and not current_page.is_homepage %}main{% endif %}">
116108
<a href="{{ toc_item.url }}">{{ toc_item.title }}</a>
117109
</li>
118110

@@ -124,7 +116,7 @@ <h3 id="myModalLabel">Documentation search</h3>
124116

125117
{% endfor %}
126118

127-
{% if current_page.is_homepage %}
119+
{% if current_page and current_page.is_homepage %}
128120
<div class="promo">
129121
<hr/>
130122
<script type="text/javascript" src="//cdn.fusionads.net/fusion.js?zoneid=1332&serve=C6SDP2Y&placement=djangorestframework" id="_fusionads_js"></script>
@@ -137,15 +129,21 @@ <h3 id="myModalLabel">Documentation search</h3>
137129
</div>
138130

139131
<div id="main-content" class="span9">
140-
{% if meta.source %}
141-
{% for filename in meta.source %}
142-
<a class="github" href="https://github.com/tomchristie/django-rest-framework/tree/master/rest_framework/{{ filename }}">
143-
<span class="label label-info">{{ filename }}</span>
144-
</a>
145-
{% endfor %}
146-
{% endif %}
147-
148-
{{ content }}
132+
133+
{% block content %}
134+
135+
{% if meta.source %}
136+
{% for filename in meta.source %}
137+
<a class="github" href="https://github.com/tomchristie/django-rest-framework/tree/master/rest_framework/{{ filename }}">
138+
<span class="label label-info">{{ filename }}</span>
139+
</a>
140+
{% endfor %}
141+
{% endif %}
142+
143+
{{ content }}
144+
145+
{% endblock %}
146+
149147
</div>
150148
<!--/span-->
151149
</div>
@@ -169,6 +167,8 @@ <h3 id="myModalLabel">Documentation search</h3>
169167
<script src="{{ base_url }}/js/jquery-1.8.1-min.js"></script>
170168
<script src="{{ base_url }}/js/prettify-1.0.js"></script>
171169
<script src="{{ base_url }}/js/bootstrap-2.1.1-min.js"></script>
170+
<script>var base_url = '{{ base_url }}';</script>
171+
<script src="{{ base_url }}/mkdocs/js/require.js"></script>
172172
<script src="{{ base_url }}/js/theme.js"></script>
173173

174174
<script>

docs_theme/css/default.css

+4
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,7 @@ ul.sponsor {
415415
list-style: none;
416416
display: block;
417417
}
418+
419+
#mkdocs_search_modal article p{
420+
word-wrap: break-word;
421+
}

docs_theme/js/theme.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
1-
$(function(){
1+
function getSearchTerm()
2+
{
3+
var sPageURL = window.location.search.substring(1);
4+
var sURLVariables = sPageURL.split('&');
5+
for (var i = 0; i < sURLVariables.length; i++)
6+
{
7+
var sParameterName = sURLVariables[i].split('=');
8+
if (sParameterName[0] == 'q')
9+
{
10+
return sParameterName[1];
11+
}
12+
}
13+
}
14+
15+
$(function() {
16+
17+
var initialise_search = function(){
18+
require.config({"baseUrl":"/mkdocs/js"});
19+
require(["search",]);
20+
}
21+
22+
var search_term = getSearchTerm();
23+
if(search_term){
24+
$('#mkdocs_search_modal').modal();
25+
}
226

327
$('pre code').parent().addClass('prettyprint well');
428

29+
$(document).on("submit", "#mkdocs_search_modal form", function (e) {
30+
$("#mkdocs-search-results").html("Searching...");
31+
initialise_search();
32+
return false;
33+
});
34+
535
});

0 commit comments

Comments
 (0)