Commit 7de06b95 authored by Sabina Köfler's avatar Sabina Köfler
Browse files

Complete script

parent c0695e8c
......@@ -7,7 +7,6 @@ replace_whitespaces() {
done
}
# Create array to store all md files for later
# readarray -d '' array < <(find . -iname "*.md" -o -iname "*.mdown" -o -iname "*.markdown")
create_filearray () {
......@@ -54,11 +53,14 @@ select_latex_engine() {
echo
}
extract_filename() {
construct_filename() {
y="$file" # ./FILENAME.EXTENSION
x="${y%.*}" # ./FILENAME
z="${x##*/}" # FILENAME
# echo "Extracted filename: ${z}"
pdf_filename="${z}.pdf"
pdf_path="./${pdf_dir}/${pdf_filename}"
# bak_pdf_filename="${z}_${file_date}-${file_time}.pdf"
# bak_pdf_path="./${pdf_dir}/${bak_pdf_filename}"
}
create_date_string() {
......@@ -67,16 +69,10 @@ create_date_string() {
file_date="$a" # the first part is the date
ftime="${b%.*}" # the second part is the time (but its too exact, so strip everything after the .)
file_time=${ftime//:} # remove the colons from the time stamp
# echo "Constructed date string: $file_date and time string: $file_time"
echo "Constructed date string: $file_date and time string: $file_time"
}
construct_pdf_path() {
pdf_filename="${z}.pdf"
pdf_path="./${pdf_dir}/${pdf_filename}"
}
construct_bak_pdf_path() {
bak_pdf_filename="${z}_${file_date}-${file_time}.pdf" # create new filename
construct_bak_path() {
bak_pdf_filename="${z}_${file_date}-${file_time}.pdf"
bak_pdf_path="./${pdf_dir}/${bak_pdf_filename}"
}
# END functions #
......@@ -87,6 +83,9 @@ replace_whitespaces
create_filearray
find_markdown
create_outdir_if_not_exists
# exit
select_latex_engine
# # Allow user to add custom LaTeX variables
......@@ -96,31 +95,37 @@ select_latex_engine
# Compile documents
echo -e "\nBeginning conversion...\n"
search="\[\[_TOC_\]\]"
search1="\[\[_TOC_\]\]"
search2="## Inhalt"
# find . -iname "*.md" -o -iname "*.mdown" -o -iname "*.markdown" | while read -r file; do # find -iname finds <pattern> case insensitive
for file in "${files[@]}"; do
# echo "File:" ${file}
extract_filename
construct_pdf_path
construct_bak_pdf_path
# echo "PDF Path: $pdf_path"
echo "File:" ${file}
# construct_filename $file
# remove the line that renders the table of contents in markdown and copy file to /PDFs
if ! grep -q "$search1" $file; then
continue
else
echo -e "Found search string in $file\n Will make a copy"
sed "/$search1/d;/$search2/d" $file > ./$pdf_dir/$file
fi
done
find ./$pdf_dir -iname "*.md" | while read -r file; do
echo -e "\nFound files to convert $file"
construct_filename #$file
if [ -f "$pdf_path" ]; then
# echo "File $file was already converted."
echo -e "File $file was already converted to $pdf_path."
create_date_string
# echo "Bak file name: $bak_pdf_filename"
construct_bak_path
echo "Constructing back up path: $bak_pdf_path"
mv $pdf_path $bak_pdf_path
echo -e "\nExisting file was moved to ${bak_pdf_path}\n"
fi
# remove the line that renders the table of contents in markdown
if ["$search" ]; then # TODO - should files be copied if search string is found?
echo "Nothing to replace"
else
echo "I am replacing"
# sed -i "/$search/d" $file
echo -e "File $file not the same as $pdf_path."
fi
# echo -e "Continuing with new file creation\n"
# pandoc -s --toc --template=my.latex -f gfm "$file" --pdf-engine=$option -o "$pdf_path" # could add --variable font-family:sans-serif $variable
# echo -e "File created\n"
echo -e "Continuing with new file creation\n"
pandoc -s --toc --template=my.latex -f gfm "$file" --pdf-engine=$option -o "$pdf_path" # could add --variable font-family:sans-serif $variable
echo -e "File created\n"
done
echo -e "\nAll files complete!"
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment