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

master
knotteye 3 years ago
parent 2dd0c6467d
commit 88f93a1395
  1. 1
      .gitignore
  2. 10
      Makefile
  3. 2
      README.md
  4. 8
      src/blogtool.cr
  5. 3
      testsite/base.html
  6. 8
      testsite/dist/test.html

1
.gitignore vendored

@ -2,3 +2,4 @@ blogtool
lib
shard.lock
testsite/dist
.deps

@ -6,7 +6,7 @@ all: release
.PHONY: clean
clean:
rm -f blogtool
rm -f blogtool .deps
.PHONY: run
run:
@ -16,12 +16,12 @@ 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:

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

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

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

@ -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>
Loading…
Cancel
Save