import re
from datetime import datetime


def clean_title_input(title, draft=False):
    """Convert a string into a valide Jekyll filename.

    Remove non-word characters, replace spaces and underscores with dashes,
    and add a date stamp if the file is marked as a Post, not a Draft.

    Args:
        title (string): A string based title
        draft (bool): A boolean indicating that the file is a draft

    Returns:
        string: a cleaned title for saving a new Jekyll post file

    """
    title_clean = title.lower()
    title_clean = re.sub(r'[^\w -]', '', title_clean)
    title_clean = re.sub(r' |_', '-', title_clean)

    today = datetime.today()
    title_date = today.strftime('%Y-%m-%d')

    return title_date + '-' + title_clean if not draft else title_clean