Skip to content

Commit

Permalink
Merge pull request #3 from wkentaro/generate-img-table-only-doc-exists
Browse files Browse the repository at this point in the history
Generate image table for only doc which exists
  • Loading branch information
k-okada committed Dec 3, 2015
2 parents 90069be + af83c8a commit 7889e2f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion doc/add_img_tables_to_index.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Script to add image table with link to document
to index file of sphinx documentation.
Usage::
# in conf.py for sphinx doc
exclude_patterns = ['_build', 'venv']
import add_img_tables_to_index
add_img_tables_to_index.main(exclude_patterns)
"""

import hashlib
import os
import sys
import hashlib


__copyright__ = '2015, JSK Lab'
__author__ = 'Kentaro Wada <www.kentaro.wada@gmail.com>'
__version__ = '0.1'


def rst_image_table_data(url_prefix, img_files):
Expand All @@ -13,6 +28,10 @@ def rst_image_table_data(url_prefix, img_files):
blocks = []
for i, img_file in enumerate(img_files):
title, _ = os.path.splitext(img_file)
doc_candidates = [os.path.join(url_prefix, title + ext)
for ext in ['.rst', '.md']]
if not any(map(os.path.exists, doc_candidates)):
continue
img_file = os.path.join(url_prefix, 'images', img_file)
label_name = hashlib.sha1(title).hexdigest()[:8]
labels.append('''\
Expand Down

0 comments on commit 7889e2f

Please sign in to comment.