<commit_before>#!/bin/bash - 
#===============================================================================
#
#        USAGE: ./gen_pdf.sh 
# 
#   DESCRIPTION: Build PDF pages from MD recursively
# 
#       OPTIONS: ---
#  REQUIREMENTS: find, sed, xargs, pandoc
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: <NAME> (ResponSyS), <EMAIL>
#  ORGANIZATION: 
#       CREATED: 09/30/2017 10:45
#      REVISION:  ---
#===============================================================================

# TODO: --no-interactive option to deactive xargs '-p' flag
# TODO: customize the template
# `toc: true` et `lang: fr` in YAML header of MD works perfectly but:
# TODO: customize position of TOC in template

set -o nounset -o errexit

PROGRAM_NAME="gen_pdf.sh"
#BASEDIR="$HOME/Devel/Src/Web/responsyss.github.io/"
BASEDIR="."

F_TEMPL="template.pdf.pandoc"
F_TEXTES_DIR="${BASEDIR}/textes"
SEARCH_PATH=""

XARGS_FLAGS="-P4 -p"
# is log erased each time? if yes it's retarded to set it
#PANDOC_FLAGS="-f markdown --template ${BASEDIR}/${F_TEMPL} --fail-if-warnings --log=$PROGRAM_NAME.log"
PANDOC_FLAGS="-f markdown --template ${BASEDIR}/${F_TEMPL} --fail-if-warnings"

ERR_NO_CMD=127
ERR_WRONG_WORKING_DIR=101
ERR_NO_FILE=40

# $1 = message (string)
m_say() {
	echo "$PROGRAM_NAME: $1"
}
# $1 = error message (string), $2 = return code (int)
fn_err() {
	m_say "$1" >&2
	exit $2
}
# $1 = command to test (string)
fn_needCmd() {
	if ! command -v "$1" > /dev/null 2>&1
		then fn_err "need '$1' (command not found)" $ERR_NO_CMD
	fi
}
# $1 = file to test (string)
fn_needFile() {
	if ! test -e "$1" > /dev/null 2>&1
		then fn_err "need '$1' (file or directory not found)" $ERR_NO_FILE
	fi
}

fn_help() {
	cat 1>&2 << EOF
USAGE
    ./$PROGRAM_NAME [all|PATH]

OPTIONS
    all         recursively convert all MD files to PDF in ${BASEDIR}/${F_TEXTES_DIR}/ (default)
    {PATH}      recursively convert all MD files to PDF in PATH

EXAMPLE<commit_msg>correction help gen_pdf.sh<commit_after>#!/bin/bash - 
#===============================================================================
#
#        USAGE: ./gen_pdf.sh 
# 
#   DESCRIPTION: Build PDF pages from MD recursively
# 
#       OPTIONS: ---
#  REQUIREMENTS: find, sed, xargs, pandoc
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: <NAME> (ResponSyS), <EMAIL>
#  ORGANIZATION: 
#       CREATED: 09/30/2017 10:45
#      REVISION:  ---
#===============================================================================

# TODO: --no-interactive option to deactive xargs '-p' flag
# TODO: customize the template
# `toc: true` et `lang: fr` in YAML header of MD works perfectly but:
# TODO: customize position of TOC in template

set -o nounset -o errexit

PROGRAM_NAME="gen_pdf.sh"
#BASEDIR="$HOME/Devel/Src/Web/responsyss.github.io/"
BASEDIR="."

F_TEMPL="template.pdf.pandoc"
F_TEXTES_DIR="${BASEDIR}/textes"
SEARCH_PATH=""

XARGS_FLAGS="-P4 -p"
# is log erased each time? if yes it's retarded to set it
#PANDOC_FLAGS="-f markdown --template ${BASEDIR}/${F_TEMPL} --fail-if-warnings --log=$PROGRAM_NAME.log"
PANDOC_FLAGS="-f markdown --template ${BASEDIR}/${F_TEMPL} --fail-if-warnings"

ERR_NO_CMD=127
ERR_WRONG_WORKING_DIR=101
ERR_NO_FILE=40

# $1 = message (string)
m_say() {
	echo "$PROGRAM_NAME: $1"
}
# $1 = error message (string), $2 = return code (int)
fn_err() {
	m_say "$1" >&2
	exit $2
}
# $1 = command to test (string)
fn_needCmd() {
	if ! command -v "$1" > /dev/null 2>&1
		then fn_err "need '$1' (command not found)" $ERR_NO_CMD
	fi
}
# $1 = file to test (string)
fn_needFile() {
	if ! test -e "$1" > /dev/null 2>&1
		then fn_err "need '$1' (file or directory not found)" $ERR_NO_FILE
	fi
}

fn_help() {
	cat 1>&2 << EOF
USAGE
    ./$PROGRAM_NAME [all|PATH]

OPTIONS
    all         recursively convert all MD files to PDF in ${F_TEXTES_DIR}/ (default)
    {PATH}      recursively convert all MD files to PDF in PATH

EXAMPLE
{'fraction_non_alphanumeric': 0.22464139344262296, 'fraction_numerical': 0.020491803278688523, 'mean_word_length': 3.6991576413959084, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, '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': '4364523', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1420, 'n_words': 387}