From 8223b7eaa6ffcb801dbdb34312e460b1de76ee5f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Sat, 20 Mar 2021 12:28:43 +0100 Subject: [PATCH] display page title --- index.cgi | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/index.cgi b/index.cgi index 3db279a..2797910 100755 --- a/index.cgi +++ b/index.cgi @@ -8,10 +8,10 @@ _DATA="${_DATA:-.}" . "$_EXEC"/cgilite/file.sh . "$_EXEC"/session_lock.sh -git init "$_DATA" >/dev/null +git init "$_DATA" >/dev/null & yield_page(){ - page="$1" + title="${1:-WebTXT}" page="$2" printf '%s\r\n' 'Content-Type: text/html; charset=utf-8' \ "Content-Security-Policy: script-src 'none'" \ '' @@ -20,24 +20,34 @@ yield_page(){ [meta name="viewport" content="width=device-width"] [link rel="stylesheet" type="text/css" href="common.css"] [link rel="stylesheet" type="text/css" href="webnote.css"] - [title Webnote] + [title %s] ] [body class="%s" - ' "$page" + ' "$title" "$page" cat printf '] ]' } |"$_EXEC/cgilite/html-sh.sed" -u } +pagename() { + local name page="${1##*/}" + name="$(sed -nE "/[a-zA-Z0-9].[^\r ]/{s;\r$;;; p; q;};" "$_DATA/$page")" + [ "$name" ] && printf %s "$name" \ + || printf %s "$page" +} + +recent="$(COOKIE pages)" + case ${PATH_INFO##*/} in favicon.ico) printf '%s\r\n' 'Content-Length: 0' '';; common.css) FILE "$_EXEC/cgilite/common.css";; webnote.css) FILE "$_EXEC/webnote.css";; '') yield_page <<-EOF [form .new action=new [button type=submit New Note] - $(if [ "$(COOKIE pages)" ]; then + $(if [ "$recent" ]; then printf '[h2 Recent Pages][ul .recent' - for page in $(COOKIE pages); do - [ -f "$_DATA/$(printf %s "$page" |checkid)" ] && printf '[li [a href="./%s" . %s]]' "$page" "$page" + for page in $recent; do + [ -f "$_DATA/$(printf %s "$page" |checkid)" ] \ + && printf '[li [a href="./%s" . %s]]' "$page" "$(pagename "$page" |HTML)" done printf ']' fi) @@ -64,7 +74,7 @@ fi [ $REQUEST_METHOD = POST ] && case $(POST action) in edit) if temp=$(SLOCK "$doc"); then - yield_page <<-EOF + yield_page "$(pagename "$doc" |HTML)" <<-EOF [form method=POST [input type=hidden name=session_key value="$SESSION_KEY"] [button type=submit name=action value=cancel Cancel] @@ -73,7 +83,7 @@ fi ] EOF else - yield_page <<-EOF + yield_page "$(pagename "$doc" |HTML) - Error" <<-EOF [p .error .locked Someone else is already editing this Dokument. Wait a few minutes and try again. [a href="$PATH_INFO" Nothing else I can do.]] EOF fi @@ -87,10 +97,10 @@ fi if temp=$(CHECK_SLOCK "$doc"); then RELEASE_SLOCK "$doc" POST document >"${doc}" - git -C "$_DATA" commit -m "update note ${doc##*/} \"$(sed '1{s;\r;;; q;}' "$doc")\"" "${doc##*/}" >/dev/null + git -C "$_DATA" commit -m "update note ${doc##*/} \"$(pagename "$doc")\"" "${doc##*/}" >/dev/null REDIRECT "$PATH_INFO" else - yield_page <<-EOF + yield_page "$(pagename "$doc" |HTML) - Error" <<-EOF [p .error .stolen Your edit took too long and someone else is now editing this file. [a href="$PATH_INFO" Dang, I must be quicker next time!]] [p Copy your Content for reference:] [div .text . $(POST document |HTML)] @@ -100,10 +110,10 @@ fi ;; esac -COOKIE pages |tr \ \\n |grep -qF "${doc##*/}" \ -|| SET_COOKIE +$((90 * 86400)) pages="$(COOKIE pages && printf ' %s' "${doc##*/}" || printf '%s' "${doc##*/}")" Path="${PATH_INFO%/*}/" +printf %s "$recent" |grep -qwF "${doc##*/}" \ +|| SET_COOKIE +$((90 * 86400)) pages="${recent}${recent+ }${doc##*/}" Path="${PATH_INFO%/*}/" -yield_page <<-EOF +yield_page "$(pagename "$doc" |HTML)" <<-EOF [form method=POST [input type=hidden name=session_key value="$SESSION_KEY"] [button type=submit name=action value=edit Edit] -- 2.39.2