diff --git a/doc/source/_static/random.js b/doc/source/_static/random.js new file mode 100644 index 00000000..4141665a --- /dev/null +++ b/doc/source/_static/random.js @@ -0,0 +1,13 @@ + + function insert_gallery() { + var images = ['http://scikits-image.org/docs/dev/_images/plot_otsu.png', 'http://scikits-image.org/docs/dev/_images/plot_canny.png', 'http://scikits-image.org/docs/dev/_images/plot_medial_transform.png', 'http://scikits-image.org/docs/dev/_images/plot_skeleton.png', 'http://scikits-image.org/docs/dev/_images/plot_glcm.png', 'http://scikits-image.org/docs/dev/_images/plot_lena_tv_denoise.png', 'http://scikits-image.org/docs/dev/_images/plot_equalize.png', 'http://scikits-image.org/docs/dev/_images/plot_watershed.png', 'http://scikits-image.org/docs/dev/_images/plot_convex_hull.png', 'http://scikits-image.org/docs/dev/_images/plot_contours.png', 'http://scikits-image.org/docs/dev/_images/plot_hough_transform.png', 'http://scikits-image.org/docs/dev/_images/plot_radon_transform.png']; + var links = ['http://scikits-image.org/docs/dev/auto_examples/plot_plot_otsu.html', 'http://scikits-image.org/docs/dev/auto_examples/plot_plot_canny.html', 'http://scikits-image.org/docs/dev/auto_examples/plot_plot_medial_transform.html', 'http://scikits-image.org/docs/dev/auto_examples/plot_plot_skeleton.html', 'http://scikits-image.org/docs/dev/auto_examples/plot_plot_glcm.html', 'http://scikits-image.org/docs/dev/auto_examples/plot_plot_lena_tv_denoise.html', 'http://scikits-image.org/docs/dev/auto_examples/plot_plot_equalize.html', 'http://scikits-image.org/docs/dev/auto_examples/plot_plot_watershed.html', 'http://scikits-image.org/docs/dev/auto_examples/plot_plot_convex_hull.html', 'http://scikits-image.org/docs/dev/auto_examples/plot_plot_contours.html', 'http://scikits-image.org/docs/dev/auto_examples/plot_plot_hough_transform.html', 'http://scikits-image.org/docs/dev/auto_examples/plot_plot_radon_transform.html']; + + ix = Math.floor(Math.random() * images.length); + document.write( +'
'.replace('IMG', images[ix]).replace('URL', links[ix]) + ); + + console.log(''.replace('IMG', images[ix]).replace('URL', links[ix])); + }; + diff --git a/doc/source/random_gallery.py b/doc/source/random_gallery.py new file mode 100644 index 00000000..e4625536 --- /dev/null +++ b/doc/source/random_gallery.py @@ -0,0 +1,51 @@ +# Generate a javascript snippet that links to a random gallery example + +import os +import glob + +base = os.path.abspath(os.path.dirname(__file__)) +example_dir = os.path.join(base, 'auto_examples') +js_fn = os.path.join(base, '_static/random.js') + +javascript = '''\ + + function insert_gallery() { + var images = {{IMAGES}}; + var links = {{LINKS}}; + + ix = Math.floor(Math.random() * images.length); + document.write( +'{{GALLERY_DIV}}'.replace('IMG', images[ix]).replace('URL', links[ix]) + ); + + console.log('{{GALLERY_DIV}}'.replace('IMG', images[ix]).replace('URL', links[ix])); + }; + +''' + +gallery_div = '''\ +\ +''' + +examples = glob.glob(os.path.join(example_dir, 'plot_*.py')) + +images, links = [], [] +image_url = 'http://scikits-image.org/docs/dev/_images/%s.png' +link_url = 'http://scikits-image.org/docs/dev/auto_examples/plot_%s.html' + +for e in examples: + e = os.path.basename(e) + e = e[:-len('.py')] + + images.append(image_url % e) + links.append(link_url % e) + +javascript = javascript.replace('{{IMAGES}}', str(images)) +javascript = javascript.replace('{{LINKS}}', str(links)) +javascript = javascript.replace('{{GALLERY_DIV}}', ''.join(gallery_div.split('\n'))) + +f = open(js_fn, 'w') +f.write(javascript) +f.close()