@@ -33,6 +33,11 @@ def abspath_from_here(*args):
33
33
34
34
35
35
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
+
36
41
nblist = sorted (nb for nb in os .listdir (NB_SOURCE_DIR )
37
42
if nb .endswith ('.ipynb' ))
38
43
name_map = {nb : nb .rsplit ('.' , 1 )[0 ].lower () + '.html'
@@ -57,11 +62,17 @@ def copy_notebooks():
57
62
as_version = 4 )
58
63
59
64
if nb == 'Index.ipynb' :
65
+ # content[0] is the title
66
+ # content[1] is the cover image
67
+ # content[2] is the license
60
68
cells = '1:'
61
69
template = 'page'
62
70
title = 'Python Data Science Handbook'
63
71
content .cells [2 ].source = INTRO_TEXT
64
72
else :
73
+ # content[0] is the book information
74
+ # content[1] is the navigation bar
75
+ # content[2] is the title
65
76
cells = '2:'
66
77
template = 'booksection'
67
78
title = content .cells [2 ].source
@@ -70,7 +81,7 @@ def copy_notebooks():
70
81
title = title .lstrip ('#' ).strip ()
71
82
72
83
# 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 ))
74
85
75
86
# Replace internal URLs and figure links in notebook
76
87
for cell in content .cells :
@@ -81,7 +92,10 @@ def copy_notebooks():
81
92
for figname , newfigname in figure_map .items ():
82
93
if figname in cell .source :
83
94
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
+
85
99
nbformat .write (content , os .path .join (NB_DEST_DIR , nb ))
86
100
87
101
pagefile = os .path .join (PAGE_DEST_DIR , base + '.md' )
@@ -95,5 +109,3 @@ def copy_notebooks():
95
109
96
110
if __name__ == '__main__' :
97
111
copy_notebooks ()
98
-
99
-
0 commit comments