aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--base.template.html (renamed from base.ejs)5
-rwxr-xr-xgenerate70
-rw-r--r--index.template.html (renamed from index.ejs)8
-rw-r--r--school.template.html (renamed from school.ejs)0
-rw-r--r--utils/fractal_tree/index.template.html (renamed from utils/fractal_tree/index.ejs)2
-rw-r--r--utils/langton_ant/index.template.html (renamed from utils/langton_ant/index.ejs)1
-rw-r--r--utils/minesweeper/index.template.html (renamed from utils/minesweeper/index.ejs)2
-rw-r--r--utils/rot13/index.template.html (renamed from utils/rot13/index.ejs)2
-rw-r--r--utils/sierpinski_triangle/index.template.html (renamed from utils/sierpinski_triangle/index.ejs)2
10 files changed, 56 insertions, 38 deletions
diff --git a/.gitignore b/.gitignore
index 2e0badf..1c393b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
*.bak
node_modules
build
+*.html
+!*.template.html
diff --git a/base.ejs b/base.template.html
index 4ddd460..43638bf 100644
--- a/base.ejs
+++ b/base.template.html
@@ -8,13 +8,12 @@
<meta name="author" content="Charles Cabergs"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
- <link rel="stylesheet" type="text/css" href="style.css"/>
- <link rel="icon" type="image/png" href="favicon.png" />
+ <!-- HEAD -->
</head>
<body>
<div id="page-wrapper">
- <%- include(pageFilename, {}) %>
+ <!-- BODY -->
</div>
</body>
</html>
diff --git a/generate b/generate
index 725d38e..d13dac6 100755
--- a/generate
+++ b/generate
@@ -1,42 +1,72 @@
#!/bin/sh
-# Put your posts in a blog_src directory
-# Depends on pandoc for markdown to html convertion
+base_template () {
+ body_file=$(mktemp)
+ cat > "$body_file"
+ sed '/<!-- BODY -->/r '"$body_file" base.template.html
+}
-blog_dir=blog
+base_template_link () {
+ link_href="$1"
+ case $link_href in
+ *.css)
+ link_rel="stylesheet"
+ link_type="text/css"
+ ;;
+ *.png)
+ link_rel="icon"
+ link_type="image/png"
+ ;;
+ *)
+ echo Invalid link file
+ exit 1
+ ;;
+ esac
+ sed "/<!-- HEAD -->/i\
+ <link rel=\"$link_rel\" type=\"$link_type\" href=\"$link_href\"/>"
+}
-[ ! -d "$blog_dir" ] || [ -z "$(ls $blog_dir)" ] && exit 1
-mkdir -p "$blog_dir"
+# Setup
+blog_path=blog
+mkdir -p "$blog_path"
+base_template < index.template.html |
+ base_template_link 'favicon.png' |
+ base_template_link 'style.css' > index.html
+base_template < school.template.html |
+ base_template_link 'favicon.png' |
+ base_template_link 'style.css' > school.html
-for post_path in "$blog_dir"/*.md
+# Generate blog posts
+for post_path in "$(find "$blog_path" -name '*.md')"
do
- post_dst_path=$(echo "$post_path" | sed 's/\.md/.build.html/')
+ post_dst_path=$(echo "$post_path" | sed 's_.md_.html_')
- # Convert markdown post to html
- tmp_file=$(mktemp)
- pandoc -f markdown -t html < "$post_path" > "$tmp_file"
-
- ejs base.ejs -i "{\"pageFilename\": \"$post_path\" }" > "$post_dst_path"
-
- # Put the blog content in a wrapper template
- # sed "/<!--BLOG-->/ r $tmp_file" < blog.template.html > "$post_dst_path"
+ pandoc -f markdown -t html < "$post_path" |
+ base_template |
+ base_template_link '../favicon.png' |
+ base_template_link '../style.css' > "$post_dst_path"
# Add blog artcle link to the index.html
title=$(grep '^# .*$' -m 1 "$post_path" | cut -c 2-)
[ -z "$title" ] && echo "post $post_path doesn't have a title" && title=$post_path
- sed -i'' "/<!--BLOGINDEX-->/ a\
+ sed -i "/<!-- BLOGINDEX -->/ a\
<li><a href=\"$post_dst_path\">$title</a></li>" index.html
echo "Generated post at $post_dst_path"
done
+# Generate utilities
for util_path in utils/*
do
title=$(basename "$util_path" | tr '_' ' ')
-
- ejs base.ejs -i "{\"pageFilename\": \"$post_path\" }" > "$post_dst_path"
-
- sed -i'' "/<!--UTILSINDEX-->/ a\
+ sed '$ a <script type="text/javascript" src="script.js"></script>' < "$util_path/index.template.html" |
+ base_template |
+ base_template_link '../../favicon.png' |
+ base_template_link '../../style.css' |
+ base_template_link 'style.css' > "$util_path/index.html"
+ sed -i'' "/<!-- UTILSINDEX -->/ a\
<li><a href=\"$util_path\">$title</a></li>" index.html
+
+ echo "Generated utility at $util_path"
done
diff --git a/index.ejs b/index.template.html
index a1afa91..4055ddb 100644
--- a/index.ejs
+++ b/index.template.html
@@ -7,17 +7,13 @@
<h2>Blog articles</h2>
<ul>
- <% posts.forEach(post => { %>
- <li><a href="<%= post.url %>">post.title</a></li>
- <% }) %>
+ <!-- BLOGINDEX -->
</ul>
<h2>Utils</h2>
<ul>
<li><a href="https://chat.cacharle.xyz">chat</a></li>
- <% utils.forEach(util => { %>
- <li><a href="<%= util.url %>">util.title</a></li>
- <% }) %>
+ <!-- UTILSINDEX -->
</ul>
<h2>Links</h2>
diff --git a/school.ejs b/school.template.html
index ca2375d..ca2375d 100644
--- a/school.ejs
+++ b/school.template.html
diff --git a/utils/fractal_tree/index.ejs b/utils/fractal_tree/index.template.html
index 088dd83..265f772 100644
--- a/utils/fractal_tree/index.ejs
+++ b/utils/fractal_tree/index.template.html
@@ -12,5 +12,3 @@
<input id="angle" min="1" max="180" value="45" type="range"/>
</div>
</div>
-
-<script src="script.js" type="text/javascript"></script>
diff --git a/utils/langton_ant/index.ejs b/utils/langton_ant/index.template.html
index 5930ebe..9efb764 100644
--- a/utils/langton_ant/index.ejs
+++ b/utils/langton_ant/index.template.html
@@ -1,4 +1,3 @@
<h1>langton ant</h1>
<table id="table"></table>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
-<script type="text/javascript" src="script.js"></script>
diff --git a/utils/minesweeper/index.ejs b/utils/minesweeper/index.template.html
index fdbb5be..bf1ea4d 100644
--- a/utils/minesweeper/index.ejs
+++ b/utils/minesweeper/index.template.html
@@ -27,5 +27,3 @@
</div>
<table id="minesweeper-table"></table>
-
-<script src="script.js" type="text/javascript"></script>
diff --git a/utils/rot13/index.ejs b/utils/rot13/index.template.html
index 27b3a20..64fffdf 100644
--- a/utils/rot13/index.ejs
+++ b/utils/rot13/index.template.html
@@ -10,5 +10,3 @@
<h3>Output</h3>
<textarea cols=120 rows=10 id="rot13-output"></textarea>
-
-<script src="script.js" type="text/javascript"></script>
diff --git a/utils/sierpinski_triangle/index.ejs b/utils/sierpinski_triangle/index.template.html
index c9b0247..3bad80c 100644
--- a/utils/sierpinski_triangle/index.ejs
+++ b/utils/sierpinski_triangle/index.template.html
@@ -6,5 +6,3 @@
<label>depth</label>
<input id="depth" min="1" max="9" value="7" type="range"/>
</div>
-
-<script src="script.js" type="text/javascript"></script>