blog

git clone https://git.ce9e.org/blog.git

commit
9701875c8b23d48775c2967b946748773bb859e4
parent
f730fcd7ae46f7e5e6f3bdd43f474b592f83eb54
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2024-03-26 00:45
add getyml util

Diffstat

M feed-atom.sh 10 +++++++---
M feed-json.sh 10 +++++++---
M posts.sh 6 +++++-

3 files changed, 19 insertions, 7 deletions


diff --git a/feed-atom.sh b/feed-atom.sh

@@ -2,6 +2,10 @@
    2     2 
    3     3 base_url='https://blog.ce9e.org/'
    4     4 
   -1     5 getyml() {
   -1     6 	grep "^$1:" "$2" | head -n 1 | sed "s/$1"': //;s/^"\(.*\)"$/\1/'
   -1     7 }
   -1     8 
    5     9 escape() {
    6    10 	sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g'
    7    11 }
@@ -28,11 +32,11 @@ ls _content/posts | tac | $select | while read -r l; do
   28    32 	html="_content/posts/$l/index.html"
   29    33 	url="${base_url}posts/$l/"
   30    34 	echo '	<entry>'
   31    -1 	echo "		<title>$(grep '^title:' "$yml" | head -n 1 | sed 's/title: //;s/^"\(.*\)"$/\1/' | escape)</title>"
   -1    35 	echo "		<title>$(getyml 'title' "$yml" | escape)</title>"
   32    36 	echo "		<link href=\"$url\" />"
   33    37 	echo "		<id>$url</id>"
   34    -1 	echo "		<updated>$(grep '^date:' "$yml" | head -n 1 | sed 's/date: //' | escape)T00:00:00Z</updated>"
   35    -1 	echo "		<summary>$(grep '^description:' "$yml" | head -n 1 | sed 's/description: //;s/^"\(.*\)"$/\1/' | escape)</summary>"
   -1    38 	echo "		<updated>$(getyml 'date' "$yml" | escape)T00:00:00Z</updated>"
   -1    39 	echo "		<summary>$(getyml 'description' "$yml" | escape)</summary>"
   36    40 	echo '		<content type="html">'
   37    41 	cat "$html" | escape
   38    42 	echo '		</content>'

diff --git a/feed-json.sh b/feed-json.sh

@@ -2,6 +2,10 @@
    2     2 
    3     3 base_url='https://blog.ce9e.org/'
    4     4 
   -1     5 getyml() {
   -1     6 	grep "^$1:" "$2" | head -n 1 | sed "s/$1"': //;s/^"\(.*\)"$/\1/'
   -1     7 }
   -1     8 
    5     9 escape() {
    6    10 	sed 's/\\/\\\\\\\\/g;s/"/\\"/g'
    7    11 }
@@ -35,11 +39,11 @@ ls _content/posts | tac | $select | while read -r l; do
   35    39 	yml="_content/posts/$l/index.md"
   36    40 	html="_content/posts/$l/index.html"
   37    41 	url="${base_url}posts/$l/"
   38    -1 	value 2 'title' "$(grep '^title:' "$yml" | head -n 1 | sed 's/title: //;s/^"\(.*\)"$/\1/' | escape)"
   -1    42 	value 2 'title' "$(getyml 'title' "$yml" | escape)"
   39    43 	value 2 'url' "$url"
   40    44 	value 2 'id' "$url"
   41    -1 	value 2 'summary' "$(grep '^description:' "$yml" | head -n 1 | sed 's/description: //;s/^"\(.*\)"$/\1/' | escape)"
   42    -1 	value 2 'date_published' "$(grep '^date:' "$yml" | head -n 1 | sed 's/date: //' | escape)"
   -1    45 	value 2 'summary' "$(getyml 'description' "$yml" | escape)"
   -1    46 	value 2 'date_published' "$(getyml 'date' "$yml" | escape)"
   43    47 	echo "		\"content_html\": \"$(cat "$html" | escape | sed 's/$/\\\\n/' | tr -d '\n')\""
   44    48 done
   45    49 echo '	}]'

diff --git a/posts.sh b/posts.sh

@@ -1,6 +1,10 @@
    1     1 #!/bin/sh
    2     2 
   -1     3 getyml() {
   -1     4 	grep "^$1:" "$2" | head -n 1 | sed "s/$1"': //;s/^"\(.*\)"$/\1/'
   -1     5 }
   -1     6 
    3     7 ls _content/posts | tac | while read -r l; do
    4     8 	yml="_content/posts/$l/index.md"
    5    -1 	echo "- [$(grep '^title:' "$yml" | head -n 1 | sed 's/title: //;s/^"\(.*\)"$/\1/')](/posts/$l/)"
   -1     9 	echo "- [$(getyml 'title' "$yml")](/posts/$l/)"
    6    10 done