Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 97c8c91

Browse files
committed
Adjust website build to work with colab badges:
1 parent 70ba408 commit 97c8c91

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

‎website/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Tools for creating http://jakevdp.github.io/PythonDataScienceHandbook/
1+
2# Tools for creating http://jakevdp.github.io/PythonDataScienceHandbook/
22

33
The website is generated using the [Pelican](http://docs.getpelican.com/) static site generator.
44
The themes here are adapted from those used for my blog: https://github.com/jakevdp/jakevdp.github.io-source
@@ -20,6 +20,9 @@ Install the required packages:
2020
$ conda create -n pelican-blog python=3.5 jupyter notebook
2121
$ source activate pelican-blog
2222
$ pip install pelican Markdown ghp-import
23+
$ mkdir plugins
24+
$ git submodule add git://github.com/danielfrg/pelican-ipynb.git plugins/ipynb
25+
$ git submodule add https://github.com/getpelican/pelican-plugins.git plugins/pelican-plugins
2326
```
2427

2528
Copy the notebook content to the right location (this script also modifies some links for the HTML):

‎website/copy_notebooks.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ def abspath_from_here(*args):
3333

3434

3535
def copy_notebooks():
36+
if not os.path.exists(NB_DEST_DIR):
37+
os.makedirs(NB_DEST_DIR)
38+
if not os.path.exists(PAGE_DEST_DIR):
39+
os.makedirs(PAGE_DEST_DIR)
40+
3641
nblist = sorted(nb for nb in os.listdir(NB_SOURCE_DIR)
3742
if nb.endswith('.ipynb'))
3843
name_map = {nb: nb.rsplit('.', 1)[0].lower() + '.html'
@@ -57,11 +62,17 @@ def copy_notebooks():
5762
as_version=4)
5863

5964
if nb == 'Index.ipynb':
65+
# content[0] is the title
66+
# content[1] is the cover image
67+
# content[2] is the license
6068
cells = '1:'
6169
template = 'page'
6270
title = 'Python Data Science Handbook'
6371
content.cells[2].source = INTRO_TEXT
6472
else:
73+
# content[0] is the book information
74+
# content[1] is the navigation bar
75+
# content[2] is the title
6576
cells = '2:'
6677
template = 'booksection'
6778
title = content.cells[2].source
@@ -70,7 +81,7 @@ def copy_notebooks():
7081
title = title.lstrip('#').strip()
7182

7283
# put nav below title
73-
content.cells[0], content.cells[1], content.cells[2] =content.cells[2], content.cells[0], content.cells[1]
84+
content.cells.insert(0, content.cells.pop(2))
7485

7586
# Replace internal URLs and figure links in notebook
7687
for cell in content.cells:
@@ -81,7 +92,10 @@ def copy_notebooks():
8192
for figname, newfigname in figure_map.items():
8293
if figname in cell.source:
8394
cell.source = cell.source.replace(figname, newfigname)
84-
95+
if cell.source.startswith("<!--NAVIGATION-->"):
96+
# Undo replacement of notebook link in the colab badge
97+
cell.source = nb.join(cell.source.rsplit(name_map[nb], 1))
98+
8599
nbformat.write(content, os.path.join(NB_DEST_DIR, nb))
86100

87101
pagefile = os.path.join(PAGE_DEST_DIR, base + '.md')
@@ -95,5 +109,3 @@ def copy_notebooks():
95109

96110
if __name__ == '__main__':
97111
copy_notebooks()
98-
99-

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /