Skip to content

Commit

Permalink
book generation (#120)
Browse files Browse the repository at this point in the history
* reorganize the file structure

* testing new section headers

* cleanup images in markdown

* test doc generation

* test doc generation

* test doc generation
  • Loading branch information
devsecfranklin authored May 22, 2024
1 parent dacad2e commit 1b9ec5e
Show file tree
Hide file tree
Showing 122 changed files with 409 additions and 334 deletions.
10 changes: 5 additions & 5 deletions admin/CONTRIBUTING.md → .admin/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ eclectic mix of dishes from around the hacker community. Tell us about
your favorite recipe or something you like to make with your own unique
twist. Feel free to include a recommendation for booze pairing.

General questions should be directed to:
General questions should be directed to the maintainers:

* [\@iheartmalware](https://twitter.com/iheartmalware)
* [\@thedevilsvoice](https://twitter.com/thedevilsvoice).
* [\@thedevilsvoice](https://twitter.com/thedevilsvoice)

We can\'t promise that all submissions will be included in the final
printed book. We do plan to leave this repo up indefinitely. We intend
to give any proceeds to a charitable cause of our choosing.
* We can\'t promise that all submissions will be included in the final printed book.
* We do plan to leave this repo up indefinitely.
* We intend to give any proceeds to a charitable cause of our choosing.

## Submissions

Expand Down
3 changes: 2 additions & 1 deletion admin/Makefile.am → .admin/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ clean:
rm -rf _build *.egg-info
@find . -name '*.pyc' | xargs rm -rf
@find . -name '__pycache__' | xargs rm -rf
@for trash in aclocal.m4 autom4te.cache config config.log config.status configure configure~ libtool Makefile Makefile.in docker/cloudbot/Makefile docker/cloudbot/Makefile.in; do \
@for trash in aclocal.m4 autom4te.cache config config.log config.status configure configure~ \
libtool Makefile Makefile.in docker/Makefile docker/Makefile.in; do \
if [ -f $$trash ] || [ -d $$trash ]; then \
echo "Removing $$trash" ;\
rm -rf $$trash ;\
Expand Down
15 changes: 15 additions & 0 deletions .admin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# admin

Various maintenance tools.

## :blue_book: Generate the Book :orange_book:

You can generate a PDF of this book.

- Set up the dev environment [as explained in the docs](docs/nix.md)

## Make utility

### make docker

Build a Docker container with the application.
15 changes: 15 additions & 0 deletions .admin/SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Security Policy

* Using [Mend Renovate](https://github.com/marketplace/renovate) to scan for dependency issues.

## Supported Versions

All versions of this project are currently being supported with security updates.

| Version | Supported |
| ------- | ------------------ |
| 0.1 | :white_check_mark: |

## Reporting a Vulnerability

Use [the "issues" tab in this repo](https://github.com/EAD10C5/1337-Noms-The-Hacker-Cookbook/issues) to report security issues.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 4 additions & 5 deletions admin/bin/formatting.sh → .admin/bin/formatting.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand All @@ -94,4 +93,4 @@ function main() {
format_markdown
}

main "$@"
main "$@"
152 changes: 152 additions & 0 deletions .admin/bin/generate_book.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/usr/bin/env bash
#
# SPDX-FileCopyrightText: 2023 DE:AD:10:C5 <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later

set -euo pipefail
#IFS=$'\n\t'

#Black 0;30 Dark Gray 1;30
#Red 0;31 Light Red 1;31
#Green 0;32 Light Green 1;32
#Brown/Orange 0;33 Yellow 1;33
#Blue 0;34 Light Blue 1;34
#Purple 0;35 Light Purple 1;35
#Cyan 0;36 Light Cyan 1;36
#Light Gray 0;37 White 1;37

RED='\033[0;31m'
LRED='\033[1;31m'
LGREEN='\033[1;32m'
CYAN='\033[0;36m'
LCYAN='\033[1;36m'
LPURP='\033[1;35m'
YELLOW='\033[1;33m'
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')
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

# ##### 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() {
echo -e "${LGREEN}Adding frontmatter...${NC}" | tee -a "${RAW_OUTPUT}"

# Copy TeX files to tmp build dir
cp -Rp .admin/tex/frontmatter ${TEX_DIR}
cp .admin/tex/preamble.tex ${TEX_DIR}
cp -Rp .admin/images ${TEX_DIR}

# build the front pages
cat .admin/tex/frontmatter/header.tex | tee -a "${TEX_OUTPUT}"
echo -e "\n" | tee -a "${TEX_OUTPUT}"
cat .admin/tex/frontmatter/frontmatter.tex | tee -a "${TEX_OUTPUT}"
echo -e "\n" | tee -a "${TEX_OUTPUT}"
}

# the recipes
function mainmatter() {
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
echo -e "${LGREEN}Copying folder: ${LCYAN}${i}${NC}" | tee -a "${RAW_OUTPUT}"
cp -Rp ${i} ${TEX_DIR}

# start with the section header
if [ -f "${TEX_DIR}/${i}/section.tex" ]; then
echo -e "${LGREEN}Found section header: ${LCYAN}${TEX_DIR}/${i}/section.tex${NC}" | tee -a "${RAW_OUTPUT}"
NEW_DIR=$(echo "${TEX_DIR}/${i}/images/" | sed 's@/@\\/@g')
echo -e "${LGREEN}Update image path in section header to: ${LCYAN}${NEW_DIR}${NC}" | tee -a "${RAW_OUTPUT}"
sed -i -e "s/images\//${NEW_DIR}/g" ${TEX_DIR}/${i}/section.tex
cat ${TEX_DIR}/${i}/section.tex | tee -a "${TEX_OUTPUT}"
fi

THESE_FILES=$(ls ${TEX_DIR}/${i}/*.md)
for j in $THESE_FILES; do
sed -i -e "s/images\//${NEW_DIR}/g" ${j} # fix image directory
sed -i 's|^#|##|' ${j} # fix the markdown heading level
echo -e "${LGREEN}Adding recipe: ${LCYAN}${j}${NC}" | tee -a "${RAW_OUTPUT}"
echo "\pagebreak" | tee -a "${TEX_OUTPUT}" # new page for every recipe
echo "\markdownInput{${j}}" | tee -a "${TEX_OUTPUT}"
((COUNTER += 1)) # increment recipe count
done
done
}

function backmatter() {
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 cleanup() {
echo "Cleaning up..." | tee -a "${RAW_OUTPUT}"

# copy final file to original dir
if [ -f "${TEX_DIR}/hacker_cookbook.pdf" ]; then
echo -e "${LGREEN}Copying PDF to project dir: ${LCYAN}$${TEX_DIR}/hacker_cookbook.pdf${NC}" | tee -a "${RAW_OUTPUT}"
cp ${TEX_DIR}/hacker_cookbook.pdf ${MY_PWD}
else
echo -e "${LRED}PPDF generation failed.${NC}"
fi

# Blow away the temp working dir
if [ -d "${TEX_DIR}" ]; then
echo -e "${LGREEN}Erase tmp build dir: ${LCYAN}${TEX_DIR}${NC}" | tee -a "${RAW_OUTPUT}"
rm -rf ${TEX_DIR}
fi
}

function main() {

# Check to see if script is being run from correct relative path
if [ ! -f ".admin/bin/generate_book.sh" && ! -d ".admin/tex" ]; then
echo -e "${LRED}Please run this tool from top level of repo clone${NC}"
exit 1
fi

directory_setup

# remove any stale output file
if [ -f "${TEX_OUTPUT}" ]; then rm ${TEX_OUTPUT} && touch ${TEX_OUTPUT}; fi

frontmatter
mainmatter
echo -e "${LGREEN}Processed ${COUNTER} recipes total.${NC}" | tee -a "${RAW_OUTPUT}"
backmatter

cp ${TEX_OUTPUT} ${MY_PWD}/.admin/tex
cd ${TEX_DIR} && latexmk -pdf -file-line-error -interaction=nonstopmode -synctex=1 -shell-escape hacker_cookbook

cleanup
}

main "$@"
File renamed without changes.
2 changes: 1 addition & 1 deletion admin/configure.ac → .admin/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ AC_PROG_DVIBOOK

AC_CONFIG_FILES([
Makefile
cookbook/Makefile
tex/Makefile
]) # files to generate, one per line

AC_OUTPUT
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion admin/cookbook/Makefile.am → .admin/tex/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% backmatter: appendix, bibliography, index, postface
\backmatter{}
\printindex
\nocite{*}
%\printindex
%\nocite{*}
File renamed without changes.
12 changes: 12 additions & 0 deletions .admin/tex/frontmatter/frontmatter.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
% frontmatter: half title, title page, colophon (copyright page), epigraph, toc, preface, acknowledgements
\frontmatter{}

\include{frontmatter/maketitle}
%\include{frontmatter/colophon}
%\include{frontmatter/epigraph}
%\include{frontmatter/preface}

% Generate these sections
\tableofcontents
%\listoffigures
%\listoftables
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
% !TeX document-id = {8b67b01d-8418-4209-9cf6-487e17368a27}
% !TeX encoding = UTF-8
% !TeX root = hacker_cookbook.tex
% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]

\include{preamble}
\begin{document}
\begin{document}
17 changes: 17 additions & 0 deletions .admin/tex/frontmatter/maketitle.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
\pagenumbering{Roman} %%% to avoid page 1 conflict with actual page 1
\begin{titlepage}
\centering
\vspace{0mm}
\includegraphics[scale=2.1]{images/hacked.jpg}
\vspace*{40mm} %%% * is used to give space from top
\begin{flushright}
\textbf{\Huge {1337-Noms-The-Hacker-Cookbook}}\\
\vspace{5mm}
\Large \textsf{@thedevilsvoice \&\& @iheartmalware}\\
%\Large \textsf{Created on : May 16, 2016}
\vspace*{0mm}
%\Large \textsf{Last updated : \today}
\end{flushright}
\clearpage
\vspace*{\fill}
\end{titlepage}
File renamed without changes.
7 changes: 5 additions & 2 deletions admin/cookbook/preamble.tex → .admin/tex/preamble.tex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
%%% FONTS %%%
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}


\usepackage[english]{babel}


%\usepackage{tgpagella} % set the document font to TeX Gyre Pagella
\usepackage{tgbonum} % set the document font to TeX Gyre Bonum
\usepackage{fontawesome5} % The Creative Commons icons
Expand All @@ -40,8 +44,7 @@
%%% SPACING %%%
\setcounter{secnumdepth}{3} % add number to subsubsection
\setcounter{tocdepth}{2} % Table of content upto 2=subsection, 3=subsubsection
\usepackage[notlot,nottoc,notlof]{} % reduce spaces for ToC, figs and tables % used like so "\addtocontents{toc}{\vskip -1
.2cm}"
\usepackage[notlot,nottoc,notlof]{} % reduce spaces for ToC, figs and tables % used like so "\addtocontents{toc}{\vskip -1.2cm}"
\linespread{1.25}

\usepackage{enumerate} % itemize package
Expand Down
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
.DS_Store
*.swp
*.pdf
_build/
admin/logs/
hacker_cookbook.tex
**/logs/*
**/_markdown_hacker_cookbook/*

AUTHORS
COPYING
Expand Down
5 changes: 0 additions & 5 deletions APPETIZERS/_section.md

This file was deleted.

8 changes: 8 additions & 0 deletions APPETIZERS/section.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
\pagebreak
\chapter{Appetizers}

This is a collection of appetizers for the hackers cookbook

\centering
% ![canape]()
\includegraphics[scale=0.1]{images/appetizer-canape-canapes-cheese-41967.jpg}
5 changes: 0 additions & 5 deletions BREAKFAST/_section.md

This file was deleted.

Loading

0 comments on commit 1b9ec5e

Please sign in to comment.