|
37 | 37 | # shutil.rmtree(target)
|
38 | 38 | # shutil.copytree(source, target)
|
39 | 39 |
|
| 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 | + |
40 | 94 | for (dirpath, dirnames, filenames) in os.walk(docs_dir):
|
41 | 95 | relative_dir = dirpath.replace(docs_dir, '').lstrip(os.path.sep)
|
42 | 96 | build_dir = os.path.join(html_dir, relative_dir)
|
|
46 | 100 |
|
47 | 101 | for filename in filenames:
|
48 | 102 | path = os.path.join(dirpath, filename)
|
| 103 | + relative_path = os.path.join(relative_dir, filename) |
49 | 104 |
|
50 | 105 | if not filename.endswith('.md'):
|
51 | 106 | if relative_dir:
|
|
78 | 133 | toc += template + '\n'
|
79 | 134 |
|
80 | 135 | if filename == 'index.md':
|
81 |
| - main_title = 'Django REST framework - APIs made easy' |
| 136 | + main_title = 'Django REST framework - Web Browseable APIs' |
82 | 137 | else:
|
83 | 138 | main_title = 'Django REST framework - ' + main_title
|
84 | 139 |
|
| 140 | + prev_url = prev_url_map.get(relative_path) |
| 141 | + next_url = next_url_map.get(relative_path) |
| 142 | + |
85 | 143 | content = markdown.markdown(text, ['headerid'])
|
86 | 144 |
|
87 | 145 | output = page.replace('{{ content }}', content).replace('{{ toc }}', toc).replace('{{ base_url }}', base_url).replace('{{ suffix }}', suffix).replace('{{ index }}', index)
|
88 | 146 | output = output.replace('{{ title }}', main_title)
|
89 | 147 | output = output.replace('{{ description }}', description)
|
90 | 148 | 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 | + |
91 | 164 | output = re.sub(r'a href="([^"]*)\.md"', r'a href="\1%s"' % suffix, output)
|
92 | 165 | output = re.sub(r'<pre><code>:::bash', r'<pre class="prettyprint lang-bsh">', output)
|
93 | 166 | output = re.sub(r'<pre>', r'<pre class="prettyprint lang-py">', output)
|
|
0 commit comments