aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flake.nix2
-rw-r--r--src/Makefile18
-rw-r--r--src/example.md16
-rwxr-xr-xsrc/gen/gen_index.sh11
-rwxr-xr-xsrc/make_index.md.sh19
5 files changed, 36 insertions, 30 deletions
diff --git a/flake.nix b/flake.nix
index 2eb2de1..ca9af0d 100644
--- a/flake.nix
+++ b/flake.nix
@@ -31,9 +31,9 @@
devShells.${system}.default = pkgs.mkShell {
buildInputs = with pkgs; [
pandoc
- ripgrep
http-server
shellcheck
+ checkmake
gnumake
];
};
diff --git a/src/Makefile b/src/Makefile
index c60678a..7c7af1f 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,28 +1,26 @@
-BUILD_DIR = _build
+BUILD_DIR ?= build
-MARKDOWNFILES != find md/ -type f -name "*.md"
+MARKDOWNFILES = $(wildcard md/*.md)
HTMLTARGETS = $(MARKDOWNFILES:md/%.md=$(BUILD_DIR)/stories/%.html)
-$(BUILD_DIR)/stories/%.html: md/%.md
+$(BUILD_DIR)/stories $(BUILD_DIR):
+ mkdir -p $@
+
+$(BUILD_DIR)/stories/%.html: md/%.md | $(BUILD_DIR)/stories
pandoc "$<" \
--standalone \
--embed-resources \
--template template.html \
-o "$@"
-$(BUILD_DIR)/index.html: make_index.md.sh
+$(BUILD_DIR)/index.html: gen/gen_index.sh | $(BUILD_DIR)
bash $< | pandoc \
--standalone \
--embed-resources \
--template template.html \
-o "$@"
-make_dirs:
- mkdir -p $(BUILD_DIR)/stories
-
all: make_dirs $(HTMLTARGETS) $(BUILD_DIR)/index.html
-clean:
- rm -rf $(BUILD_DIR)
+.PHONY: make_dirs all
-.PHONY: clean make_dirs all up
diff --git a/src/example.md b/src/example.md
new file mode 100644
index 0000000..667cdc0
--- /dev/null
+++ b/src/example.md
@@ -0,0 +1,16 @@
+---
+title: this is the title
+---
+
+some
+
+text
+
+asdf
+asdf
+asd
+fas
+df
+sadf
+sad
+f
diff --git a/src/gen/gen_index.sh b/src/gen/gen_index.sh
new file mode 100755
index 0000000..516f594
--- /dev/null
+++ b/src/gen/gen_index.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+file="---\ntitle: All Stories\n---\n"
+
+for i in md/*.md; do
+ title=$(sed -nE 's/^title: "?(.*)("?)$/\1/p' "$i")
+ no_ext=$(basename "$i" .md)
+ file+="\n- [$title](/stories/${no_ext}.html)"
+done
+
+echo -e "$file"
diff --git a/src/make_index.md.sh b/src/make_index.md.sh
deleted file mode 100755
index 544b90c..0000000
--- a/src/make_index.md.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/usr/bin/env bash
-
-links="---
-title: All Stories
----
-
-"
-
-for i in md/*.md; do
- title=$(grep '^title:' $i | tr -d '"' | sed -E 's/^title: (.*)$/\1/')
-
- no_ext=$(basename "${i%.*}")
- link="- [$title](/stories/${no_ext}.html)
-"
-
- links+="$link"
-done
-
-echo "$links"