From 88f93a13953c907456d410f2f3a7e62bd1c720d3 Mon Sep 17 00:00:00 2001 From: knotteye Date: Sat, 6 Mar 2021 14:13:05 -0600 Subject: [PATCH] Replace a string in the template so that we can add a footer --- .gitignore | 3 ++- Makefile | 12 ++++++------ README.md | 2 +- src/blogtool.cr | 8 +++++--- testsite/base.html | 3 +++ testsite/dist/test.html | 8 -------- 6 files changed, 17 insertions(+), 19 deletions(-) delete mode 100644 testsite/dist/test.html diff --git a/.gitignore b/.gitignore index bbb65f1..6b0b02b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ blogtool lib shard.lock -testsite/dist \ No newline at end of file +testsite/dist +.deps \ No newline at end of file diff --git a/Makefile b/Makefile index 68d03ff..7e65dd7 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ all: release .PHONY: clean clean: - rm -f blogtool + rm -f blogtool .deps .PHONY: run run: @@ -16,15 +16,15 @@ release: dependencies crystal build --release --no-debug src/blogtool.cr dependencies: - shards install - -debug: + [ -e .deps ] || shards install + touch .deps +debug: dependencies crystal build src/blogtool.cr -test: debug +test: cd testsite && ../blogtool install: install blogtool $(PREFIX)/bin/ mkdir -p /etc/blogtool - install testsite/base.html /etc/blogtool/ \ No newline at end of file + install testsite/base.html /etc/blogtool/ diff --git a/README.md b/README.md index de63e36..d531349 100644 --- a/README.md +++ b/README.md @@ -27,4 +27,4 @@ dist |-> about.html ``` -You can build blogtool by running `make && sudo make install`. Invoke blogtool by running `blogtool` in the project directory. There are no options. You can copy /etc/blogtool/base.html to the project root and make changes to overwrite the template. \ No newline at end of file +You can build blogtool by running `make && sudo make install`. Invoke blogtool by running `blogtool` in the project directory. There are no options. You can copy /etc/blogtool/base.html to the project root and make changes to overwrite the template, as long as the string "## CONTENT\n" is in the template somewhere, as that will be replaced with the article or about page. \ No newline at end of file diff --git a/src/blogtool.cr b/src/blogtool.cr index dce5a06..78416ff 100644 --- a/src/blogtool.cr +++ b/src/blogtool.cr @@ -41,16 +41,18 @@ def render_file(filename : String | Path) end index = Base +content = "" Dir.entries("articles").select{ |i| i != "." && i != ".." }.each do |article| if article[article.size-3, article.size] == ".md" File.write Path.new("dist", article[0,article.size-3]+".html"), render_file("articles/"+article) - index += "

"+article[0,article.size-3].gsub("-", " ")+"

\n" + content += "

"+article[0,article.size-3].gsub("-", " ")+"

\n" else File.write Path.new("dist", article+".html"), render_file("articles/"+article) - index += "

"+article.gsub("-", " ")+"

\n" + content += "

"+article.gsub("-", " ")+"

\n" end end -File.write Path["dist/index.html"], index+"" +index.gsub("## CONTENT\n") { content } +File.write Path["dist/index.html"], index Dir.entries("assets").select{ |i| i != "." && i != ".." }.each do |asset| File.copy Path.new("assets", asset), Path.new("dist", "static", asset) diff --git a/testsite/base.html b/testsite/base.html index b14a440..46d6c0b 100644 --- a/testsite/base.html +++ b/testsite/base.html @@ -1,4 +1,7 @@ + + + \ No newline at end of file diff --git a/testsite/dist/test.html b/testsite/dist/test.html deleted file mode 100644 index a53710d..0000000 --- a/testsite/dist/test.html +++ /dev/null @@ -1,8 +0,0 @@ - - - - -

yeet

-

this is a test

-

weeeooo

- \ No newline at end of file