summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Douillet <vincent@vdouillet.fr>2022-05-27 17:41:24 +0200
committerVincent Douillet <vincent@vdouillet.fr>2022-05-27 17:52:13 +0200
commit8e3ebb113d8b0b0ab34eebb97c3a8a3ac38a92f8 (patch)
tree0312d19a0fed6344de65a3a206cc083f66cec9b8
parent5490f1fd18fcc445f0c48a1ed830678e0f69ac0f (diff)
generate article list automatically
-rwxr-xr-xmakesite.pl52
-rw-r--r--static/index.md2
-rw-r--r--template/header.html1
-rw-r--r--template/index.html12
4 files changed, 39 insertions, 28 deletions
diff --git a/makesite.pl b/makesite.pl
index 6980da8..2b6c7e1 100755
--- a/makesite.pl
+++ b/makesite.pl
@@ -7,7 +7,10 @@ use File::Slurp;
use Text::Markdown "markdown";
sub page {
- my ($pageFile, $pageTitle, $pageType, $pageContent) = @_;
+ my ($pageFile, $pageTitle, $pageContent, $pageType, $id) = @_;
+ unless(defined $pageType) {
+ $pageType = "body"; # default page type
+ }
open my $outHandle, ">>", "output/$pageFile";
# Write header and insert page title
open my $inHandle, "<", "template/header.html";
@@ -17,7 +20,12 @@ sub page {
}
close $inHandle;
# Write content and footer
- print $outHandle "<$pageType>";
+ if(defined $id) {
+ print $outHandle "<$pageType id=\"$id\">";
+ }
+ else {
+ print $outHandle "<$pageType>";
+ }
print $outHandle $pageContent;
print $outHandle "</$pageType>";
cat "template/footer.html", $outHandle;
@@ -27,33 +35,45 @@ sub page {
`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;
+my $aboutContent = read_file "static/about.md";
+$aboutContent = markdown $aboutContent;
+page "about.html", "About", $aboutContent;
# Build articles
+my @articleList;
while(<*.md>) {
- print "Processing $_\n";
+ my $articleFile = $_;
+ print "Processing $articleFile\n";
# Extract article title from the title in MD article
- open my $articleHandle, "<", $_;
+ open my $articleHandle, "<", $articleFile;
my $headLine = <$articleHandle>;
- $headLine = substr $headLine, 2;
+ $headLine = substr $headLine, 2, -1;
close $articleHandle;
# Extract output file name: MD file name without the date
- my $pageFile = substr $_, 9, -3;
+ my $pageFile = substr $articleFile, 9, -3;
$pageFile .= ".html";
# Build article
- my $articleContent = read_file $_;
+ my $articleContent = read_file $articleFile;
$articleContent = markdown $articleContent;
- page $pageFile, $headLine, "article", $articleContent;
+ page $pageFile, $headLine, $articleContent, "article";
+
+ # Add article to index
+ my $year = substr $articleFile, 0, 4;
+ my $month = substr $articleFile, 4, 2;
+ my $day = substr $articleFile, 6, 2;
+ push @articleList, "* [$month-$day-$year $headLine]($pageFile \"$headLine\")\n";
+}
+
+# Build index with article list in reverse (most recent first)
+print "Building index\n";
+my $indexContent = read_file "static/index.md";
+foreach(reverse @articleList) {
+ $indexContent .= $_;
}
+$indexContent = markdown $indexContent;
+page "index.html", "blog.vdouillet.fr", $indexContent, "body", "index-body";
diff --git a/static/index.md b/static/index.md
new file mode 100644
index 0000000..9bf570a
--- /dev/null
+++ b/static/index.md
@@ -0,0 +1,2 @@
+Hello and welcome, my name is Vincent and you've landed on the small space where I ramble mainly about IT and occasionally other topics. You can check my articles below, my [git repos](git.vdouillet.fr) or the [about](/about.html) page.
+
diff --git a/template/header.html b/template/header.html
index 8a88647..e7e9c50 100644
--- a/template/header.html
+++ b/template/header.html
@@ -16,6 +16,7 @@
padding:0 .62em;
font:1.2em/1.62 sans-serif;
}
+ body#index-body ul {list-style-type:none;padding-left:0}
h1,h2,h3{line-height:1.2}
footer{text-align:center}
pre,blockquote{overflow-x:auto}
diff --git a/template/index.html b/template/index.html
deleted file mode 100644
index ebc3182..0000000
--- a/template/index.html
+++ /dev/null
@@ -1,12 +0,0 @@
-<header>
- <p>Hello and welcome, my name is Vincent and you've landed on the small space where I ramble mainly about IT and occasionally other topics. You can check my articles below, my <a href="//git.vdouillet.fr" title="git.vdouillet.fr">git repos</a> or the <a href="/about.html" title="about">about</a> page.</p>
-</header>
-<ul style="list-style-type:none;padding-left:0">
- <li><a href="which-gpu-for-a-1999-pc.html" title="Which GPU for a 1999 PC?">05-16-2022 Which GPU for a 1999 PC?</a></li>
- <li><a href="/remote-desktop-vnc-openbsd.html" title="Remote X11 desktop with x11vnc on OpenBSD">04-08-2022 Remote X11 desktop with x11vnc on OpenBSD</a></li>
- <li><a href="/advent-of-code-2021.html" title="Advent of Code 2021">01-05-2022 Advent of Code 2021</a></li>
- <li><a href="/lightweight-mail-client.html" title="On the status of lightweight GUI mail clients">11-03-2021 On the status of lightweight GUI mail clients</a></li>
- <li><a href="/browsing-gems.html" title="Browsing gems">10-11-2021 Browsing gems</a></li>
- <li><a href="/raspberry-pi-white-noise-machine.html" title="Raspberry Pi white noise machine">09-29-2021 Raspberry Pi white noise machine</a></li>
- <li><a href="/openbsd-simple-git-server.html" title="Simple git server on OpenBSD">09-11-2021 Simple git server on OpenBSD</a></li>
-</ul>