<commit_before>"""Bark

Usage:
    bark new <name>
    bark make [<settings>]

Options:
    -h --help Show this screen.
    --version Show version.
"""
__author__ = '<NAME>'
__version__ = '1.1'

from docopt import docopt
import json
import errno
import shutil
import misaka as ms
from datetime import datetime
import sys
import os
from slugify import slugify
from dateutil import parser
import frontmatter as ft
from jinja2 import Environment, FileSystemLoader, Template, DictLoader


def walk_files(start):
    for root, dirs, files in os.walk(start):
        for f in files:
            yield os.path.join(root, f)


def walk_directories(start):
    for root, dirs, files in os.walk(start):
        for d in dirs:
            yield os.path.join(root, d)


def mkdirp(path):
    """
    Replicate mkdir -p functionality.
    """
    try:
        os.makedirs(path)
    except OSError as e:
        if e.errno == errno.EEXIST and os.path.isdir(path):
            pass
        else:
            raise


BASE_BASE = """
<!DOCTYPE html>
<html lang="en">
<head>
        <meta charset="UTF-8">
        <title>{{ settings.site_name }}</title>
        <style type="text/css">
            body {
                font: 14px/1.5em sans-serif;
            }
        </style>
</head>
<body>
        <h1><a href="{{ settings.site_url }}">{{ settings.site_name }}</a></h1>
        <small>by {{ settings.site_author }}</small>
        <article>
                {% block content %}
                {% endblock %}
        </article>
</body>
</html>"""

BASE_INDEX = """
{% extends "base.html" %}

{% block content %}
<ul>
        {% for post in posts -%}
        <li><a href="{{ settings.site_url }}/{{ post.url }}">{{ post.title }}</a></li>
        {% endfor %}
</ul>
{% endblock %}"""

BASE_POST = """
{% extends "base.html" %}

{% block content %}
<h3>{{ post.title }}</h3>
<small>By {{ post.author }} at {{ post.date }}</small>

{{ post.rendered }}
{% endblock %}"""

BASE_TEMPLATES = {
    'base.html': BASE_BASE,
    'index.html': BASE_INDEX,
    'post.html': BASE_POST
}


class Post(object):
    def __init__(self, filename, settings):
        self.filename = filename
        self.matter = ft.load(self.filename).to_dict()
        self.title = self.matter.get('title', 'Unremarkable Post')
        self.author = self.matter.get('author', 'Anonymous')
        self.category = self.matter.get('category', None)
        self.slug = self.matter.get('slug', slugify(self.title))
        if not self.category:
            self.url = '.'.join([self.slug, 'html'])
        else:
            self.url = '/'.join([self.category, '.'.join([self.slug, 'html'])])
        if 'date' in self.matter:
            d = parser.parse(self.matter['date'])
            self.date = d.strftime('%Y-%m-%d %H:%M')
        else:
            self.date = self.get_create_time(filename)
        self.raw = self.matter.get('content', '')
        self.html = ms.html(ms.SmartyPants().postprocess(self.raw))
        self.rendered = Template(self.html).render(post=self, settings=settings)

    def get_create_time(self, filename):
        created = datetime.fromtimestamp(os.stat(filename).st_ctime)
        return created.strftime('%Y-%m-%d %H:%M')


class Settings(object):
    def __init__(self, settings):
        self.templates = settings.get('templates', None)
        self.static = settings.get('static', 'static')
        self.content = settings.get('content', 'content')
        self.output = settings.get('output', 'output')
        self.site_name = settings.get('site_name', 'My Blog')
        self.site_author = settings.get('site_author', 'Anonymous')
        self.site_url = settings.get('site_url', '/')
        self.misc = settings.get('misc', {})


class Engine(object):
    def __init__(self, settings):
        self.settings = Settings(settings)
        self.files = []
        self.posts = []
        self.categories = set()
        self.jinja = Environment()
        if self.settings.templates:
            self.jinja.loader = FileSystemLoader(self.settings.templates)
        else:<commit_msg>remove default for site_url, replace with None<commit_after>"""Bark

Usage:
    bark new <name>
    bark make [<settings>]

Options:
    -h --help Show this screen.
    --version Show version.
"""
__author__ = '<NAME>'
__version__ = '1.1'

from docopt import docopt
import json
import errno
import shutil
import misaka as ms
from datetime import datetime
import sys
import os
from slugify import slugify
from dateutil import parser
import frontmatter as ft
from jinja2 import Environment, FileSystemLoader, Template, DictLoader


def walk_files(start):
    for root, dirs, files in os.walk(start):
        for f in files:
            yield os.path.join(root, f)


def walk_directories(start):
    for root, dirs, files in os.walk(start):
        for d in dirs:
            yield os.path.join(root, d)


def mkdirp(path):
    """
    Replicate mkdir -p functionality.
    """
    try:
        os.makedirs(path)
    except OSError as e:
        if e.errno == errno.EEXIST and os.path.isdir(path):
            pass
        else:
            raise


BASE_BASE = """
<!DOCTYPE html>
<html lang="en">
<head>
        <meta charset="UTF-8">
        <title>{{ settings.site_name }}</title>
        <style type="text/css">
            body {
                font: 14px/1.5em sans-serif;
            }
        </style>
</head>
<body>
        <h1>{% if settings.site_url %}<a href="{{ settings.site_url }}">{{ settings.site_name }}</a>{% else %}{{ settings.site_name }}</h1>
        <small>by {{ settings.site_author }}</small>
        <article>
                {% block content %}
                {% endblock %}
        </article>
</body>
</html>"""

BASE_INDEX = """
{% extends "base.html" %}

{% block content %}
<ul>
        {% for post in posts -%}
        <li><a href="{% if settings.site_url %}{{ settings.site_url }}/{% endif %}{{ post.url }}">{{ post.title }}</a></li>
        {% endfor %}
</ul>
{% endblock %}"""

BASE_POST = """
{% extends "base.html" %}

{% block content %}
<h3>{{ post.title }}</h3>
<small>By {{ post.author }} at {{ post.date }}</small>

{{ post.rendered }}
{% endblock %}"""

BASE_TEMPLATES = {
    'base.html': BASE_BASE,
    'index.html': BASE_INDEX,
    'post.html': BASE_POST
}


class Post(object):
    def __init__(self, filename, settings):
        self.filename = filename
        self.matter = ft.load(self.filename).to_dict()
        self.title = self.matter.get('title', 'Unremarkable Post')
        self.author = self.matter.get('author', 'Anonymous')
        self.category = self.matter.get('category', None)
        self.slug = self.matter.get('slug', slugify(self.title))
        self.url = '.'.join([self.slug, 'html'])
        if self.category:
            self.url = '/'.join([self.category, self.url])
        if 'date' in self.matter:
            d = parser.parse(self.matter['date'])
            self.date = d.strftime('%Y-%m-%d %H:%M')
        else:
            self.date = self.get_create_time(filename)
        self.raw = self.matter.get('content', '')
        self.html = ms.html(ms.SmartyPants().postprocess(self.raw))
        self.rendered = Template(self.html).render(post=self, settings=settings)

    def get_create_time(self, filename):
        created = datetime.fromtimestamp(os.stat(filename).st_ctime)
        return created.strftime('%Y-%m-%d %H:%M')


class Settings(object):
    def __init__(self, settings):
        self.templates = settings.get('templates', None)
        self.static = settings.get('static', 'static')
        self.content = settings.get('content', 'content')
        self.output = settings.get('output', 'output')
        self.site_name = settings.get('site_name', 'My Blog')
        self.site_author = settings.get('site_author', 'Anonymous')
        self.site_url = settings.get('site_url', None)
        self.misc = settings.get('misc', {})


class Engine(object):
    def __init__(self, settings):
        self.settings = Settings(settings)
        self.files = []
        self.posts = []
        self.categories = set()
        self.jinja = Environment()
        if self.settings.templates:
            self.jinja.loader = FileSystemLoader(self.settings.templates)
        else:
{'fraction_non_alphanumeric': 0.15946077240709255, 'fraction_numerical': 0.002914743745445713, 'mean_word_length': 2.5072402044293014, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 69, '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': '1815881', 'n_tokens_mistral': 2709, 'n_tokens_neox': 2579, 'n_words': 602}