|
18 | 18 | from matplotlib import image
|
19 | 19 |
|
20 | 20 | DOC_SRC = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 21 | +DEFAULT_IMG_LOC = os.path.join( |
| 22 | + os.path.dirname(DOC_SRC), "logos", "PyMC3.png" |
| 23 | + ) |
21 | 24 | TABLE_OF_CONTENTS_FILENAME = "table_of_contents_{}.js"
|
22 | 25 |
|
23 | 26 | INDEX_TEMPLATE = """
|
@@ -76,9 +79,7 @@ def __init__(self, filename, target_dir):
|
76 | 79 | with open(filename, "r") as fid:
|
77 | 80 | self.json_source = json.load(fid)
|
78 | 81 | self.pagetitle = self.extract_title()
|
79 |
| - self.default_image_loc = os.path.join( |
80 |
| - os.path.dirname(DOC_SRC), "logos", "PyMC3.png" |
81 |
| - ) |
| 82 | + self.default_image_loc = DEFAULT_IMG_LOC |
82 | 83 |
|
83 | 84 | # Only actually run it if the output RST file doesn't
|
84 | 85 | # exist or it was modified less recently than the example
|
@@ -156,17 +157,30 @@ def build_gallery(srcdir, gallery):
|
156 | 157 |
|
157 | 158 | if not os.path.exists(source_dir):
|
158 | 159 | os.makedirs(source_dir)
|
| 160 | + |
| 161 | + # Create default image |
| 162 | + png_path = os.path.join(os.path.join(target_dir, "_images"), "default.png") |
| 163 | + shutil.copy(DEFAULT_IMG_LOC, png_path) |
| 164 | + create_thumbnail(png_path) |
159 | 165 |
|
160 | 166 | # Write individual example files
|
161 | 167 | data = {}
|
162 | 168 | for basename in sorted(tocjs.contents):
|
163 |
| - filename = os.path.join(source_dir, basename + ".ipynb") |
164 |
| - ex = NotebookGenerator(filename, target_dir) |
165 |
| - data[ex.stripped_name] = { |
166 |
| - "title": ex.pagetitle, |
167 |
| - "url": os.path.join(os.sep, gallery, ex.output_html), |
168 |
| - "thumb": os.path.basename(ex.png_path), |
169 |
| - } |
| 169 | + if basename.find(".rst") < 1: |
| 170 | + filename = os.path.join(source_dir, basename + ".ipynb") |
| 171 | + ex = NotebookGenerator(filename, target_dir) |
| 172 | + data[ex.stripped_name] = { |
| 173 | + "title": ex.pagetitle, |
| 174 | + "url": os.path.join(os.sep, gallery, ex.output_html), |
| 175 | + "thumb": os.path.basename(ex.png_path), |
| 176 | + } |
| 177 | + else: |
| 178 | + filename = basename.split(".")[0] |
| 179 | + data[basename] = { |
| 180 | + "title": " ".join(filename.split("_")), |
| 181 | + "url": os.path.join(os.sep, gallery, "../"+filename+".html"), |
| 182 | + "thumb": png_path, |
| 183 | + } |
170 | 184 |
|
171 | 185 | js_file = os.path.join(image_dir, "gallery_{}_contents.js".format(gallery))
|
172 | 186 | with open(table_of_contents_file, "r") as toc:
|
|
0 commit comments