Adjust website build to work with colab badges:
parent
70ba408aa9
commit
97c8c91c59
|
@ -1,4 +1,4 @@
|
|||
# Tools for creating http://jakevdp.github.io/PythonDataScienceHandbook/
|
||||
2# Tools for creating http://jakevdp.github.io/PythonDataScienceHandbook/
|
||||
|
||||
The website is generated using the [Pelican](http://docs.getpelican.com/) static site generator.
|
||||
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:
|
|||
$ conda create -n pelican-blog python=3.5 jupyter notebook
|
||||
$ source activate pelican-blog
|
||||
$ pip install pelican Markdown ghp-import
|
||||
$ mkdir plugins
|
||||
$ git submodule add git://github.com/danielfrg/pelican-ipynb.git plugins/ipynb
|
||||
$ git submodule add https://github.com/getpelican/pelican-plugins.git plugins/pelican-plugins
|
||||
```
|
||||
|
||||
Copy the notebook content to the right location (this script also modifies some links for the HTML):
|
||||
|
|
|
@ -33,6 +33,11 @@ PAGE_DEST_DIR = abspath_from_here('content', 'pages')
|
|||
|
||||
|
||||
def copy_notebooks():
|
||||
if not os.path.exists(NB_DEST_DIR):
|
||||
os.makedirs(NB_DEST_DIR)
|
||||
if not os.path.exists(PAGE_DEST_DIR):
|
||||
os.makedirs(PAGE_DEST_DIR)
|
||||
|
||||
nblist = sorted(nb for nb in os.listdir(NB_SOURCE_DIR)
|
||||
if nb.endswith('.ipynb'))
|
||||
name_map = {nb: nb.rsplit('.', 1)[0].lower() + '.html'
|
||||
|
@ -57,11 +62,17 @@ def copy_notebooks():
|
|||
as_version=4)
|
||||
|
||||
if nb == 'Index.ipynb':
|
||||
# content[0] is the title
|
||||
# content[1] is the cover image
|
||||
# content[2] is the license
|
||||
cells = '1:'
|
||||
template = 'page'
|
||||
title = 'Python Data Science Handbook'
|
||||
content.cells[2].source = INTRO_TEXT
|
||||
else:
|
||||
# content[0] is the book information
|
||||
# content[1] is the navigation bar
|
||||
# content[2] is the title
|
||||
cells = '2:'
|
||||
template = 'booksection'
|
||||
title = content.cells[2].source
|
||||
|
@ -70,7 +81,7 @@ def copy_notebooks():
|
|||
title = title.lstrip('#').strip()
|
||||
|
||||
# put nav below title
|
||||
content.cells[0], content.cells[1], content.cells[2] = content.cells[2], content.cells[0], content.cells[1]
|
||||
content.cells.insert(0, content.cells.pop(2))
|
||||
|
||||
# Replace internal URLs and figure links in notebook
|
||||
for cell in content.cells:
|
||||
|
@ -81,7 +92,10 @@ def copy_notebooks():
|
|||
for figname, newfigname in figure_map.items():
|
||||
if figname in cell.source:
|
||||
cell.source = cell.source.replace(figname, newfigname)
|
||||
|
||||
if cell.source.startswith("<!--NAVIGATION-->"):
|
||||
# Undo replacement of notebook link in the colab badge
|
||||
cell.source = nb.join(cell.source.rsplit(name_map[nb], 1))
|
||||
|
||||
nbformat.write(content, os.path.join(NB_DEST_DIR, nb))
|
||||
|
||||
pagefile = os.path.join(PAGE_DEST_DIR, base + '.md')
|
||||
|
@ -95,5 +109,3 @@ def copy_notebooks():
|
|||
|
||||
if __name__ == '__main__':
|
||||
copy_notebooks()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue