<commit_before>import {getQueryStringParams} from '../lib/URLHelper';
import {getBlogPost} from '../lib/BlogSeeker';
import * as Showdown from 'showdown';

export default async function init() {
    let postContainer = <HTMLDivElement> document.getElementById('post-container');
    let markdownConverter = new Showdown.Converter();

    let queryStringParams = getQueryStringParams();

    if (!queryStringParams.has('post')) {
        setErrorMessage("Oops!  There was a problem getting your post.  Please refresh the page and try, try again.", postContainer)
        return;
    }

    let rawPostContent = await getBlogPost(<string> queryStringParams.get('post'));

    if (!rawPostContent || rawPostContent.length === 0) {
        setErrorMessage("Oops!  There was a problem getting your post.  Please refresh the page and try, try again.", postContainer)
        return;
    }

    postContainer.innerHTML = markdownConverter.makeHtml(rawPostContent);
}

function setErrorMessage(message: string, errorElement: HTMLDivElement) {
    errorElement.innerHTML = message;
}<commit_msg>Automagically generate a title from the post filename.<commit_after>import {getQueryStringParams} from '../lib/URLHelper';
import {getBlogPost} from '../lib/BlogSeeker';
import * as Showdown from 'showdown';

export default async function init() {
    let postContainer = <HTMLDivElement> document.getElementById('post-container');
    let title = <HTMLTitleElement> document.getElementsByTagName('title')[0];
    let markdownConverter = new Showdown.Converter();

    let queryStringParams = getQueryStringParams();

    if (!queryStringParams.has('post')) {
        setErrorMessage("Oops!  There was a problem getting your post.  Please refresh the page and try, try again.", postContainer)
        return;
    }

    let rawPostContent = await getBlogPost(<string> queryStringParams.get('post'));

    if (!rawPostContent || rawPostContent.length === 0) {
        setErrorMessage("Oops!  There was a problem getting your post.  Please refresh the page and try, try again.", postContainer)
        return;
    }

    title.text = parseTitle(<string> queryStringParams.get('post'));
    postContainer.innerHTML = markdownConverter.makeHtml(rawPostContent);
}

function setErrorMessage(message: string, errorElement: HTMLDivElement) {
    errorElement.innerHTML = message;
}

function parseTitle(postFileName: string): string {
    const SKIP_DATE_INDEX = 1;
    let parsedFileName = postFileName.split('-');
    let lastWord = parsedFileName[parsedFileName.length - 1].split('.')[0];

    let returnString = "";

    for (let i = SKIP_DATE_INDEX; i < parsedFileName.length - 1; i++) {
        returnString += `${capitalizeFirstLetter(parsedFileName[i])} `;
    }

    returnString += `${capitalizeFirstLetter(lastWord)}`;

    return returnString;
}

function capitalizeFirstLetter(word: string): string {
    let capitalizedFirstLetter = word.charAt(0).toUpperCase();
    let restOfTheString = word.slice(1);

    return `${capitalizedFirstLetter}${restOfTheString}`
}
{'fraction_non_alphanumeric': 0.11518324607329843, 'fraction_numerical': 0.0029450261780104713, 'mean_word_length': 4.353765323992994, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 9, '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': '5279006', 'n_tokens_mistral': 856, 'n_tokens_neox': 821, 'n_words': 226}