From `src`, use `ln -s ../../dir src/dir` to make it appear that your
markdown files are in the directory, even if they are in a separate
+## Building
+
+`make all` builds all the HTML from the Markdown.
+`./index.sh` builds the index based on content from build directory.
+
# Common Errors
## "pandoc: build/public/note1: withFile: does not exist (No such file or directory)"
arguments are assigned to the positional parameters*. The assignment to $0 sets
the name of the shell, which is used in warning and error messages.
+# Regarding Map in Bash
+
+Map would be nice because then you don't have to loop inside definitions
+But looping doesn't play nice with spaces.
+I was pleasantly suprised it worked. Maybe there's a way around the
+space issue, but today isn't the day for that.
+
+``` bash
+map() {
+ for item in $2; do
+ # shellcheck disable=SC2005
+ echo "$("$1" "$item")"
+ done
+}
+```
+
+## BUG: Map breaks on spaces
+Context `map "make_li" "$1"`.
+
+When `$1` contains a space, it breaks there. *e.g.* when it contains
+`<a href=...`, the `make_li` function creates `<li><a</li>\n<li>href=...</li>`
+and so on. To be clear, this is not the fault of `make_li`.
+This is due to `$1` begin a space-delimited list and `map` breaking
+on spaces. Also, to be fair, that's just the way shells work by default.
+There's probably a clever way to manipulate lists as strings, but I don't know
+what the idiomatic shell way of doing it is.
+
+## Cut Fiasco
+`cut ... $1` reads the file itself.
+`echo $1 | cut ...` reads the string in `$1`.
+
# Conclusion
After tidying it all up, this command builds my entire stack of HTML and the links work!
--- /dev/null
+#!/bin/bash
+
+#############
+# CONSTANTS #
+#############
+BUILD_DIR="build"
+
+#############
+# FUNCTIONS #
+#############
+
+get_title() {
+ grep -oP '(?<=<title>).*?(?=</title>)' "$1"
+}
+ # DESC: Gets the text between the <title> tags of an HTML file.
+ # $1: Path to HTML file
+
+make_a() {
+ local path
+ path="$(echo "$1" | cut -d '/' -f2- )"
+ printf "<a href=\"%s\">%s</a>\n" "$path" "$(get_title "$1")"
+}
+ # DESC: Writes an HTML anchor based on a built HTML file
+ # $1: Path to HTML file
+ # NOTE: Cut build/ from the path b/c the path needs to be relative
+ # and the the file we are creating will go into the build dir.
+
+make_li(){
+ printf "<li>%s</li>\n" "$1"
+}
+
+make_ul() {
+ echo "<ul>"
+ for item in $1; do
+ make_li "$(make_a "$item")"
+ done
+ echo "</ul>"
+}
+ # DESC: Adds <ul> tags around a list of links.
+ # $1: A list of items that have <li>
+
+make_boilerplate(){
+ printf \
+"<!DOCTYPE html>
+<html>
+ <head>
+ <meta content=\"text/html; charset=utf-8\" http-equiv=\"content-type\">
+ <title>Pages in Build</title>
+ <meta content=\"width=device-width, initial-scale=1\" name=\"viewport\">
+ <link href='../_static/css/normalize.css' rel='stylesheet' type='text/css'>
+ <link href='../_static/css/space-sakura.css' id=\"sakura-css\" rel='stylesheet' type='text/css'>
+ </head>
+ <body>
+ <header>
+ <h1>Pages in Build</h1>
+ %s
+ </header>
+ </body>
+</html>" "$1"
+}
+ # DESC: Defines the template and injects the body.
+ # $1: The body of the HTML to add.
+ # NOTE: The CSS for index is one level higher b/c I'm dumping into
+ # the build directory rather than one of its subdirectories.
+
+
+########
+# MAIN #
+########
+FILES="$(find "$BUILD_DIR" -type 'f')"
+make_boilerplate "$(make_ul "$FILES")"