summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Douillet <vincent@vdouillet.fr>2022-05-26 18:49:59 +0200
committerVincent Douillet <vincent@vdouillet.fr>2022-05-26 18:49:59 +0200
commit5490f1fd18fcc445f0c48a1ed830678e0f69ac0f (patch)
treeab8b5aac10b5d8f441f73ddad29817ddee4263ad
parentd1f761415a8598b1acc162b4c7665ed8c6ad2c3e (diff)
switch to perl script to make the site
-rw-r--r--Makefile46
-rwxr-xr-xmakesite.pl59
-rw-r--r--static/about.md2
3 files changed, 68 insertions, 39 deletions
diff --git a/Makefile b/Makefile
index 3e4c1e3..c87940d 100644
--- a/Makefile
+++ b/Makefile
@@ -26,51 +26,21 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
-MD=Markdown.pl
-.SUFFIXES: .md .html
-articles!=ls *.md
-articles_html = ${articles:.md=.html}
+PERL5LIB=/home/vincent/perl5/lib/perl5
-site : index about $(articles_html)
+site :
+ @PERL5LIB=$(PERL5LIB) ./makesite.pl
@echo "Copying static resources"
@cp static/favicon.ico output/
@mkdir -p output/static
@cp static/passthrough/* output/static
@echo "done"
-index :
- @echo "Building $@"
- @cat template/header.html > output/$@.html
- @sed -i "s/\$$title/blog\.vdouillet\.fr/g" output/$@.html
- @echo '<body>' >> output/$@.html
- @cat template/index.html >> output/$@.html
- @echo '</body>' >> output/$@.html
- @cat template/footer.html >> output/$@.html
- @gzip -k output/$@.html
-
-about :
- @echo "Building $@"
- @cat template/header.html > output/$@.html
- @sed -i "s/\$$title/About/g" output/$@.html
- @echo '<body>' >> output/$@.html
- @$(MD) static/$@.md >> output/$@.html
- @echo '</body>' >> output/$@.html
- @cat template/footer.html >> output/$@.html
- @gzip -k output/$@.html
-
-# compile each article
-.md.html:
- @echo "Processing $<"
- @cat template/header.html > tmp.html
- @ARTICLE_TITLE=`head -n1 $< | cut -d'#' -f2` ; \
- sed -i "s/\$$title/$$ARTICLE_TITLE/g" tmp.html
- @echo '<article>' >> tmp.html
- @$(MD) $< >> tmp.html
- @cat template/back.html >> tmp.html
- @cat template/footer.html >> tmp.html
- @echo '</article>' >> tmp.html
- @mv tmp.html output/`echo $@ | cut -d'-' -f2- -`
- @gzip -k output/`echo $@ | cut -d'-' -f2- -`
+setup :
+ mkdir -p output
+ PERL5LIB=$(PERL5LIB) perl -MCPAN -e"install File::Cat"
+ PERL5LIB=$(PERL5LIB) perl -MCPAN -e"install File::Slurp"
+ PERL5LIB=$(PERL5LIB) perl -MCPAN -e"install Text::Markdown"
clean :
rm -rf output/*
diff --git a/makesite.pl b/makesite.pl
new file mode 100755
index 0000000..6980da8
--- /dev/null
+++ b/makesite.pl
@@ -0,0 +1,59 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use File::Cat;
+use File::Slurp;
+use Text::Markdown "markdown";
+
+sub page {
+ my ($pageFile, $pageTitle, $pageType, $pageContent) = @_;
+ open my $outHandle, ">>", "output/$pageFile";
+ # Write header and insert page title
+ open my $inHandle, "<", "template/header.html";
+ while(<$inHandle>) {
+ $_ =~ s/\$title/$pageTitle/;
+ print $outHandle $_;
+ }
+ close $inHandle;
+ # Write content and footer
+ print $outHandle "<$pageType>";
+ print $outHandle $pageContent;
+ print $outHandle "</$pageType>";
+ cat "template/footer.html", $outHandle;
+ close $outHandle;
+
+ # Create gzip version
+ `gzip -k output/$pageFile`;
+}
+
+# Build index
+print "Building index\n";
+my $pageContent = read_file "template/index.html";
+page "index.html", "blog.vdouillet.fr", "body", $pageContent;
+
+# Build about
+print "Building about\n";
+$pageContent = read_file "static/about.md";
+$pageContent = markdown $pageContent;
+page "about.html", "About", "body", $pageContent;
+
+# Build articles
+while(<*.md>) {
+ print "Processing $_\n";
+
+ # Extract article title from the title in MD article
+ open my $articleHandle, "<", $_;
+ my $headLine = <$articleHandle>;
+ $headLine = substr $headLine, 2;
+ close $articleHandle;
+
+ # Extract output file name: MD file name without the date
+ my $pageFile = substr $_, 9, -3;
+ $pageFile .= ".html";
+
+ # Build article
+ my $articleContent = read_file $_;
+ $articleContent = markdown $articleContent;
+ page $pageFile, $headLine, "article", $articleContent;
+}
diff --git a/static/about.md b/static/about.md
index 13c94bc..0699d77 100644
--- a/static/about.md
+++ b/static/about.md
@@ -1,3 +1,3 @@
My name is Vincent, I live in France. I like simple things, (old) computers, nature and music. Here I mostly talk about IT stuff but I may sometimes digress. We can get in touch on [Twitter](https://twitter.com/vdouillet12).
-In order to stay in line with the "simple" value stated above, this blog is completely static. It is generated using [a custom Makefile](//git.vdouillet.fr/blog) and is proudly hosted on [OpenBSD Amsterdam](https://openbsd.amsterdam). On here you will find no JavaScript, no cookies, no trackers. The CSS style sheet is very simple because content formatting relies mostly on HTML tags. This enables this blog to auto-magically adapt to your device size and to be compatible with CLI web browsers.
+In order to stay in line with the "simple" value stated above, this blog is completely static. It is generated using [a custom script](//git.vdouillet.fr/blog) and is proudly hosted on [OpenBSD Amsterdam](https://openbsd.amsterdam). On here you will find no JavaScript, no cookies, no trackers. The CSS style sheet is very simple because content formatting relies mostly on HTML tags. This enables this blog to auto-magically adapt to your device size and to be compatible with CLI web browsers.