Add meta-tags to blog posts

This commit is contained in:
Konstantin Nazarov 2023-08-17 23:59:22 +01:00
parent 4bfafac774
commit 5e5d9a597b
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22
4 changed files with 51 additions and 39 deletions

View file

@ -27,7 +27,7 @@ $(ODIR)/posts/%/index.html: content/posts/%/note.md
cat "$<" | ./bin/mdpage.sh > "$@"
$(ODIR)/posts/index.html: $(POSTS_SRC)
./bin/toc.sh content/posts "/posts" | awk -f ./bin/markdown.awk | ./bin/page.sh Posts > "$@"
./bin/toc.sh content/posts "/posts" | awk -f ./bin/markdown.awk | ./bin/page.sh Posts "" > "$@"
$(ODIR)/rss.xml: $(POSTS_SRC)
./bin/rss.sh content/posts "https://knazarov.com" "/posts" > "$@"

View file

@ -3,37 +3,40 @@
set -e
render() {
NOTITLE="$1"
LASTLINE=""
TITLE=""
NOTITLE="$1"
LASTLINE=""
TITLE=""
while read -r line ; do
if [[ "$line" =~ ^Subject:\ .*$ ]]; then
TITLE="${line#* }"
fi
if [[ ! "$line" =~ ^[^\ ]*:\ .*$ ]]; then
LASTLINE="$line"
break
fi
done
while read -r line ; do
if [[ "$line" =~ ^Subject:\ .*$ ]]; then
TITLE="${line#* }"
fi
if [[ "$line" =~ ^X-Date:\ .*$ ]]; then
DATE="${line#* }"
fi
if [[ ! "$line" =~ ^[^\ ]*:\ .*$ ]]; then
LASTLINE="$line"
break
fi
done
{
[ "$NOTITLE" == "0" ] && echo "# $TITLE";
echo "$LASTLINE";
cat
} | awk -f ./bin/markdown.awk | ./bin/page.sh "$TITLE"
{
[ "$NOTITLE" == "0" ] && echo "# $TITLE";
echo "$LASTLINE";
cat
} | awk -f ./bin/markdown.awk | ./bin/page.sh "$TITLE" "$DATE"
}
NOTITLE=0
if [ "$1" == "--notitle" ]; then
NOTITLE=1
NOTITLE=1
fi
if [ -t 0 ]; then
echo "Missing Markdown body"
exit 1
echo "Missing Markdown body"
exit 1
fi
render "$NOTITLE"

View file

@ -2,22 +2,31 @@
expand() {
TITLE="$1"
DATE="$2"
cat <<-"EOF"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
EOF
if [ "$DATE" != "" ]; then
echo " <meta property=\"og:type\" content=\"article\">"
echo " <meta property=\"og:title\" content=\"$TITLE\">"
echo " <meta property=\"article:published_time\" content=\"$DATE\"/>"
fi
cat <<-"EOF"
<link rel="stylesheet" type="text/css" href="/style.css">
<title>
EOF
EOF
echo " $TITLE"
echo " $TITLE"
cat <<-"EOF"
cat <<-"EOF"
</title>
<link rel="alternate" type="application/rss+xml"
title="RSS Feed for knazarov.com" href="/rss.xml" />
<link rel="alternate" type="application/rss+xml"
title="RSS Feed for knazarov.com" href="/rss.xml" />
</head>
<body>
<div id="header">
@ -31,29 +40,29 @@ expand() {
<a href="/contact">contact</a>
<a href="/rss.xml"><img src="/rss.png" style="height: 15px; width: auto; vertical-align:middle;"></img></a>
</div>
<div id="content">
<div id="content">
EOF
cat
cat <<-"EOF"
</div>
cat
cat <<-"EOF"
</div>
</body>
</html>
EOF
EOF
}
if [ -z "$1" ]; then
echo "Missing page title"
exit 1
echo "Missing page title"
exit 1
fi
if [ -z "$2" ] && [ -t 0 ]; then
echo "Missing page body"
exit 1
echo "Missing page body"
exit 1
fi
if [ ! -t 0 ]; then
expand "$1"
exit 0
expand "$1" "$2"
exit 0
fi
expand "$1" < "$2"
expand "$1" "$2" < "$3"

View file

@ -1,6 +1,6 @@
X-Date: 2023-08-17T23:00:00Z
X-Note-Id: cc2f05b8-6a95-452a-875b-887fde269c35
Subject: Enjoing internet with prefers-reduced-motion
Subject: Enjoying internet with prefers-reduced-motion
X-Slug: enjoying_internet_with_prefers_reduced_motion
I didn't know this before, but you can actually set a special toggle in your operating system