<commit_before>import os
import glob
from nbconvert.exporters import markdown

SITE_DIR = '.'
IMAGE_DIR = os.path.join(SITE_DIR, 'images')


def extract_thumbnail_and_title(nb_path):
    title = 'No title'
    image = 'images/placeholder.png'
    exporter = markdown.MarkdownExporter()
    output, resources = exporter.from_filename(nb_path)
    for line in output.splitlines():
        line = line.strip()
        if line.startswith('#'):
            title = line.strip('#').strip()
            break

    images = sorted(resources['outputs'])
    if images:
        img_file = images[-1]
        thumb_name = os.path.join(
            IMAGE_DIR,
            os.path.splitext(os.path.basename(nb_path))[0] +
            os.path.splitext(img_file)[-1]
            )

        with open(os.path.join('code_gallery', thumb_name), 'wb') as thumb:
            thumb.write(resources['outputs'][img_file])
            print(thumb_name)

        image = os.path.relpath(thumb_name, SITE_DIR)
    return title, image


if __name__ == '__main__':
    base_url = '{{ site.url }}{{ site.baseurl }}/'
    box = '<div><figcaption>{caption}</figcaption><a href="{base_url}/notebooks/{fname}"><img src="{img}"></a></div>\n'.format  # noqa
    front_matter = """\
---
title: Code Gallery
layout: single
---

"""
<commit_msg>Make figure title part of the notebook link.<commit_after>import os
import glob
from nbconvert.exporters import markdown

SITE_DIR = '.'
IMAGE_DIR = os.path.join(SITE_DIR, 'images')


def extract_thumbnail_and_title(nb_path):
    title = 'No title'
    image = 'images/placeholder.png'
    exporter = markdown.MarkdownExporter()
    output, resources = exporter.from_filename(nb_path)
    for line in output.splitlines():
        line = line.strip()
        if line.startswith('#'):
            title = line.strip('#').strip()
            break

    images = sorted(resources['outputs'])
    if images:
        img_file = images[-1]
        thumb_name = os.path.join(
            IMAGE_DIR,
            os.path.splitext(os.path.basename(nb_path))[0] +
            os.path.splitext(img_file)[-1]
            )

        with open(os.path.join('code_gallery', thumb_name), 'wb') as thumb:
            thumb.write(resources['outputs'][img_file])
            print(thumb_name)

        image = os.path.relpath(thumb_name, SITE_DIR)
    return title, image


if __name__ == '__main__':
    base_url = '{{ site.url }}{{ site.baseurl }}/'
    box = '<div><a href="{base_url}/notebooks/{fname}"><figcaption>{caption}</figcaption><img src="{img}"></a></div>\n'.format  # noqa
    front_matter = """\
---
title: Code Gallery
layout: single
---

"""

{'fraction_non_alphanumeric': 0.15311909262759923, 'fraction_numerical': 0.002268431001890359, 'mean_word_length': 2.7638691322901847, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '622004', 'n_tokens_mistral': 880, 'n_tokens_neox': 857, 'n_words': 161}