@@ -33,6 +33,11 @@ def abspath_from_here(*args):
3333
3434
3535def 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
96110if __name__ == '__main__' :
97111 copy_notebooks ()
98- 99-
0 commit comments