Replace a string in the template so that we can add a footer

master
knotteye 2021-03-06 14:13:05 -06:00
parent 2dd0c6467d
commit 88f93a1395
6 changed files with 17 additions and 19 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
blogtool
lib
shard.lock
testsite/dist
testsite/dist
.deps

View File

@ -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/
install testsite/base.html /etc/blogtool/

View File

@ -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.
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.

View File

@ -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 += "<h3><a href=\"/"+article[0,article.size-3]+".html\"/>"+article[0,article.size-3].gsub("-", " ")+"</a></h3>\n"
content += "<h3><a href=\"/"+article[0,article.size-3]+".html\">"+article[0,article.size-3].gsub("-", " ")+"</a></h3>\n"
else
File.write Path.new("dist", article+".html"), render_file("articles/"+article)
index += "<h3><a href=\"/"+article+".html\"/>"+article.gsub("-", " ")+"</a></h3>\n"
content += "<h3><a href=\"/"+article+".html\">"+article.gsub("-", " ")+"</a></h3>\n"
end
end
File.write Path["dist/index.html"], index+"</body></html>"
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)

View File

@ -1,4 +1,7 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>

View File

@ -1,8 +0,0 @@
<html>
<head>
</head>
<body>
<h2>yeet</h2>
<p><strong>this is</strong> a <em>test</em></p>
<p><a href="http://google.com">weeeooo</a></p>
</body></html>