diff --git a/.admin/bin/formatting.sh b/.admin/bin/formatting.sh index 2812358..d1d16f2 100755 --- a/.admin/bin/formatting.sh +++ b/.admin/bin/formatting.sh @@ -57,7 +57,6 @@ function path_setup() { fi } - function shell_script_fmt() { echo -e "${CYAN}Formatting shell scripts...${NC}" shfmt -i 2 -l -w ../bootstrap.sh @@ -76,15 +75,15 @@ function convert_rst_to_md() { fi } -function format_markdown(){ +function format_markdown() { FILES=*.md for f in $FILES; do filename="${f%.*}" echo "Removing spaces from ${filename}.md" - cat ${filename}.md | tr -s ' ' > /tmp/tmp_file + cat ${filename}.md | tr -s ' ' >/tmp/tmp_file mv /tmp/tmp_file ${filename}.md echo "Running markdown lint on ${filename}.md" - mdl ${filename}.md + mdl ${filename}.md done } @@ -94,4 +93,4 @@ function main() { format_markdown } -main "$@" \ No newline at end of file +main "$@" diff --git a/.admin/bin/generate_book.sh b/.admin/bin/generate_book.sh index a10b7ef..328c08d 100755 --- a/.admin/bin/generate_book.sh +++ b/.admin/bin/generate_book.sh @@ -27,66 +27,81 @@ NC='\033[0m' # No Color # --- Some config Variables ---------------------------------------- CATEGORIES=("APPETIZERS" "BREAKFAST" "COOKWARE" "DESSERTS" "DRINKS" "ENTREES" "SAUCES" "SIDES" "SNACKS") +LOGGING_DIR="/tmp/cookbook/log" MY_DATE=$(date '+%Y-%m-%d-%H') -RAW_OUTPUT="generate_cookbook_${MY_DATE}.txt" # log file name -TEX_OUTPUT="cookbook/hacker_cookbook.tex" - -function path_setup() { - # path madness - CURRENT_DIR="${PWD}" - #echo -e "${LGREEN}Current dir: ${LCYAN}${CURRENT_DIR}${NC}" | tee -a "${RAW_OUTPUT}" - PROG_DIR="$0" - - SCRIPT_DIR=$(echo $PROG_DIR | sed 's|\(.*\)/.*|\1|') - #echo -e "${LGREEN}Found script dir: ${LCYAN}${SCRIPT_DIR}${NC}" | tee -a "${RAW_OUTPUT}" - SUB_DIR=$(echo $SCRIPT_DIR | rev | cut -d'/' -f2- | rev) - #echo "Sub dir: $SUB_DIR" - if [ "$SUB_DIR" != "bin" ]; then - LOGGING_DIR="$CURRENT_DIR/$SUB_DIR/logs" - DATA_DIR="$CURRENT_DIR/$SUB_DIR/data" - else - LOGGING_DIR="$CURRENT_DIR/logs" - DATA_DIR="$CURRENT_DIR/data" +MY_PWD="${PWD}" +RAW_OUTPUT="${LOGGING_DIR}/generate_cookbook_${MY_DATE}.txt" # log file name +TEX_DIR="/tmp/cookbook" +TEX_OUTPUT="${TEX_DIR}/hacker_cookbook.tex" + +function directory_setup() { + + # ##### LaTeX ##### + if [ ! -d "${TEX_DIR}" ]; then + #echo -e "${LRED}Creating LaTeX dir: ${LCYAN}${TEX_DIR}${NC}" + mkdir -p ${TEX_DIR} fi - if [ -d "${LOGGING_DIR}" ]; then - RAW_OUTPUT="${LOGGING_DIR}/${RAW_OUTPUT}" - echo -e "\n${LCYAN}------------------ Starting Backup Tool ------------------${NC}" | tee -a "${RAW_OUTPUT}" - echo -e "${LGREEN}Found log dir: ${LCYAN}${LOGGING_DIR}${NC}" | tee -a "${RAW_OUTPUT}" - echo -e "${LGREEN}Log file path is: ${LCYAN}${RAW_OUTPUT}${NC}" | tee -a "${RAW_OUTPUT}" - echo -e "${LGREEN}LaTeX file path is: ${LCYAN}${TEX_OUTPUT}${NC}" | tee -a "${RAW_OUTPUT}" - else - echo -e "${LRED}Did not find log dir: ${LCYAN}${RAW_OUTPUT}${NC}" - LOGGING_DIR="." - RAW_OUTPUT="${LOGGING_DIR}/${RAW_OUTPUT}" + # ##### Logging ##### + if [ ! -d "${LOGGING_DIR}" ]; then + #echo -e "${LRED}Creating log dir: ${LCYAN}${LOGGING_DIR}${NC}" + mkdir -p ${LOGGING_DIR} fi + + # output the results + echo -e "\n${LCYAN}------------------ Building Cookbook ------------------${NC}" | tee -a "${RAW_OUTPUT}" + echo -e "${LGREEN}Log file path is: ${LCYAN}${RAW_OUTPUT}${NC}" | tee -a "${RAW_OUTPUT}" + echo -e "${LGREEN}LaTeX directory is: ${LCYAN}${TEX_DIR}${NC}" | tee -a "${RAW_OUTPUT}" } +# The frontmatter includes ToC, colophon, etc. function frontmatter() { - cat ${CURRENT_DIR}/cookbook/frontmatter/header.tex \ - ${CURRENT_DIR}/cookbook/frontmatter/frontmatter.tex | tee -a "${TEX_OUTPUT}" + echo -e "${LGREEN}Adding frontmatter...${NC}" | tee -a "${RAW_OUTPUT}" + cp .admin/tex/preamble.tex ${TEX_DIR} + cat .admin/tex/frontmatter/header.tex \ + .admin/tex/frontmatter/frontmatter.tex | tee -a "${TEX_OUTPUT}" + echo -e "\n" | tee -a "${TEX_OUTPUT}" } +# the recipes function mainmatter() { - cat ${CURRENT_DIR}/cookbook/mainmatter/mainmatter.tex | tee -a "${TEX_OUTPUT}" + COUNTER=0 + echo -e "${LGREEN}Adding mainmatter...${NC}" | tee -a "${RAW_OUTPUT}" + cat .admin/tex/mainmatter/mainmatter.tex | tee -a "${TEX_OUTPUT}" + for i in ${CATEGORIES[@]}; do - THESE_FILES=$(ls ../${i}/*.md) + cp -Rp ${i} ${TEX_DIR} + + # start with the section header + # convert section headers to tex files + + THESE_FILES=$(ls ${TEX_DIR}/${i}/*.md) for j in $THESE_FILES; do - echo "\markdownInput{../${j}}" + sed -i -e "s/images\//${i}\/images\//g" ${j} + echo "\markdownInput{${j}}" | tee -a "${TEX_OUTPUT}" + ((COUNTER+=1)) # increment recipe count done done } function backmatter() { - cat ${CURRENT_DIR}/cookbook/backmatter/backmatter.tex \ - ${CURRENT_DIR}/cookbook/backmatter/end.tex | tee -a "${TEX_OUTPUT}" + echo -e "${LGREEN}Adding backmatter...${NC}" | tee -a "${RAW_OUTPUT}" + cat .admin/tex/backmatter/backmatter.tex \ + .admin/tex/backmatter/end.tex | tee -a "${TEX_OUTPUT}" } function main() { - path_setup + directory_setup + + # remove any stale output file + if [ -f "${TEX_OUTPUT}" ]; then rm ${TEX_OUTPUT} && touch ${TEX_OUTPUT}; fi + frontmatter mainmatter backmatter + + cp ${TEX_OUTPUT} ${MY_PWD}/.admin/tex + cd ${TEX_DIR} && latexmk -pdf -file-line-error -interaction=nonstopmode -synctex=1 -shell-escape hacker_cookbook } main "$@" diff --git a/.admin/cookbook/hacker_cookbook.tex b/.admin/cookbook/hacker_cookbook.tex deleted file mode 100644 index 4edead4..0000000 --- a/.admin/cookbook/hacker_cookbook.tex +++ /dev/null @@ -1,54 +0,0 @@ -% !TeX encoding = UTF-8 -% !TeX root = hacker_cookbook.tex -% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape] - -\include{preamble} - -\markdownInput{../../} -% !TeX encoding = UTF-8 -% !TeX root = hacker_cookbook.tex -% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape] - -\include{preamble} -\begin{document}% frontmatter: half title, title page, colophon (copyright page), epigraph, toc, preface, acknowledgements -\frontmatter{} -\tableofcontents -\listoffigures -\listoftables\mainmatter{} -% backmatter: appendix, bibliography, index, postface -\backmatter{} -\printindex -\nocite{*} -%%% front cover, spline, back cover -% front_cover -\end{document} -% !TeX encoding = UTF-8 -% !TeX root = hacker_cookbook.tex -% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape] - -\include{preamble} -\begin{document}% frontmatter: half title, title page, colophon (copyright page), epigraph, toc, preface, acknowledgements -\frontmatter{} -\tableofcontents -\listoffigures -\listoftables\mainmatter{} -% !TeX encoding = UTF-8 -% !TeX root = hacker_cookbook.tex -% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape] - -\include{preamble} -\begin{document}% frontmatter: half title, title page, colophon (copyright page), epigraph, toc, preface, acknowledgements -\frontmatter{} -\tableofcontents -\listoffigures -\listoftables\mainmatter{} -% !TeX encoding = UTF-8 -% !TeX root = hacker_cookbook.tex -% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape] - -\include{preamble} -\begin{document}% frontmatter: half title, title page, colophon (copyright page), epigraph, toc, preface, acknowledgements -\frontmatter{} -\tableofcontents -\listoffigures -\listoftables\mainmatter{} diff --git a/.admin/cookbook/Makefile.am b/.admin/tex/Makefile.am similarity index 74% rename from .admin/cookbook/Makefile.am rename to .admin/tex/Makefile.am index e7bc0cc..bc764cd 100644 --- a/.admin/cookbook/Makefile.am +++ b/.admin/tex/Makefile.am @@ -5,7 +5,7 @@ clean: rm -rf _build *.egg-info @find . -name '*.pyc' | xargs rm -rf @find . -name '__pycache__' | xargs rm -rf - @for trash in *.aux *.bbl *.blg *.lof *.log *.lot *.out *.pdf *.synctex.gz *.toc ; do \ + @for trash in *.aux *.bbl *.blg *.err *.fdb_latexmk *.fls *.idx *.lof *.log *.lot *.lua *.out *.pdf *.synctex.gz *.toc Makefile Makefile.in _markdown_hacker_cookbook; do \ if [ -f "$$trash" ]; then rm -rf $$trash ; fi ; \ done diff --git a/.admin/cookbook/backmatter/backmatter.tex b/.admin/tex/backmatter/backmatter.tex similarity index 100% rename from .admin/cookbook/backmatter/backmatter.tex rename to .admin/tex/backmatter/backmatter.tex diff --git a/.admin/cookbook/backmatter/end.tex b/.admin/tex/backmatter/end.tex similarity index 100% rename from .admin/cookbook/backmatter/end.tex rename to .admin/tex/backmatter/end.tex diff --git a/.admin/cookbook/frontmatter/frontmatter.tex b/.admin/tex/frontmatter/frontmatter.tex similarity index 100% rename from .admin/cookbook/frontmatter/frontmatter.tex rename to .admin/tex/frontmatter/frontmatter.tex diff --git a/.admin/cookbook/frontmatter/header.tex b/.admin/tex/frontmatter/header.tex similarity index 100% rename from .admin/cookbook/frontmatter/header.tex rename to .admin/tex/frontmatter/header.tex diff --git a/.admin/cookbook/mainmatter/mainmatter.tex b/.admin/tex/mainmatter/mainmatter.tex similarity index 100% rename from .admin/cookbook/mainmatter/mainmatter.tex rename to .admin/tex/mainmatter/mainmatter.tex diff --git a/.admin/cookbook/preamble.tex b/.admin/tex/preamble.tex similarity index 100% rename from .admin/cookbook/preamble.tex rename to .admin/tex/preamble.tex diff --git a/.gitignore b/.gitignore index 688c6da..5406c25 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.swp *.pdf _build/ +hacker_cookbook.tex **/logs/* **/_markdown_hacker_cookbook/* diff --git a/APPETIZERS/_section.md b/APPETIZERS/section.tex similarity index 100% rename from APPETIZERS/_section.md rename to APPETIZERS/section.tex diff --git a/CREDITS.md b/CREDITS.md index 6a3e603..e4aedb7 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -1,5 +1,8 @@ -Credits -======= +# Credits + +- [This link shows who worked on this project](https://github.com/DEAD10C5/1337-Noms-The-Hacker-Cookbook/graphs/contributors) + +These folks have added their recipes to the project: - [@iHeartMalware](https://twitter.com/iheartmalware) - Organizing the project