implemented search queries, some speedup, caching
authorpaul <paul@plutz.net>
Sun, 3 Dec 2017 17:00:17 +0000 (17:00 +0000)
committerpaul <paul@plutz.net>
Sun, 3 Dec 2017 17:00:17 +0000 (17:00 +0000)
svn path=/trunk/; revision=11

bookmarks.css
index.cgi

index db96bd8..f905773 100644 (file)
@@ -148,6 +148,7 @@ html, body {
   width: 16em;
   display: inline-block;
   margin: .5em 1em;
+  white-space: nowrap;
 }
 
 .bookmark > a.modify {
@@ -169,12 +170,11 @@ html, body {
 .bookmark:hover { left: -1em; padding-left: 1em; }
 .bookmark:hover > a.bmove { display: inline-block; }
 .bookmark > a.bmove:before { color: #888; font-size: medium; }
-.bookmark > a.bmove:nth-of-type(3) { position: absolute; left: 0; }
-.bookmark > a.bmove:nth-of-type(3):before { content: '\25c0'; }
-.bookmark > a.bmove:nth-of-type(4):before { content: '\25b6'; }
+.bookmark > a.bmove:nth-last-of-type(2) { position: absolute; left: 0; }
+.bookmark > a.bmove:nth-last-of-type(2):before { content: '\25c0'; }
+.bookmark > a.bmove:nth-last-of-type(1):before { content: '\25b6'; }
 
-.bookmark > a.link { margin-left: 0;}
-.bookmark > a.link >  img {
+.bookmark img {
   height: 1.25em;
   vertical-align: text-bottom;
   margin: 0 .5ex;
index 12caed1..98e6719 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -198,7 +198,7 @@ case "$(GET action)" in
     file="${BDB}/${fid}.bm"
     bid="$(timeid)"
     if [ -n "$name" -a -f "${file}" ]; then
-      printf '%s\t%s\t%s\n' "$bid" "$(HTML "$name")" "$(HTML "$url")" >>"${file}"
+      printf '%s\t%s\t%s\n' "$bid" "$(HTML "$name")" "$url" >>"${file}"
     fi
     getFavicon "$url" "$bid"
     REDIRECT "${SCRIPT_NAME}#${fid}"
@@ -209,8 +209,7 @@ case "$(GET action)" in
     url="$(POST url |head -n1)"
     file="$(grep -lm1 "^${bid}" "${BDB}"/????????????.bm |head -n1)"
     if [ -n "$name" -a -n "$url" -a "$(POST control)" = confirm -a -w "$file" ]; then
-      bm="$(printf '%s\t%s\t%s' "$bid" "$(HTML "$name")" "$(HTML "$url")" |sed -r 's;[\&\;];\\&;g;')"
-      sed -ri "s;^${bid}\t.*$;${bm};" "$file"
+      sed -rni "/^${bid}\t/!p; /^${bid}\t/i${bid}\t$(HTML "$name")\t${url}" "$file"
     fi
     getFavicon "$url" "$bid"
     REDIRECT "${SCRIPT_NAME}#${fid}"
@@ -247,6 +246,19 @@ case "$(GET action)" in
     fi
     REDIRECT "${SCRIPT_NAME}#${fid}"
     ;;
+  query)
+    fid="$(POST fid |checkid)"
+    bid="$(POST bid |checkid)"
+    file="${BDB}/${fid}.bm"
+    query="$(URL "$(POST query)")"
+
+
+    url="$(grep -m1 "^${bid}" "$file" |cut -f3-)"
+    urlpfx="${url%\{@\}*}"
+    urlsfx="${url#*\{@\}}"
+
+    REDIRECT "${urlpfx}${query}${urlsfx}"
+    ;;
 esac
 
 bookmarkmod(){
@@ -267,7 +279,7 @@ bookmarkmod(){
          <label>Name:</label>
          <input type="text" name="name" value="${name}")" placeholder="Name" />
          <label>URL:</label>
-         <input type="text" name="url"  value="${url}")" placeholder="URL" />
+         <input type="text" name="url"  value="$(HTML "${url}")")" placeholder="URL" />
          <button type="submit" name="control" value="confirm">OK</button>
          <button type="submit" name="control" value="cancel">Cancel</button>
        </form>
@@ -300,14 +312,27 @@ show_bookmarks(){
 
   tail -n+2 "${BDB}/${fid}.bm" \
   | while read bid name url; do
-    cat <<-EOF
+    if [ "${url%\{@\}*}" = "${url}" ]; then
+      cat <<-EOF
        <div class="bookmark">
          <a class="modify" href="${SCRIPT_NAME}?bmodify=${bid}">Modify</a>
-         <a class="link" href="${url}")"><img src="${BDB}/favicons/${bid}.ico"/>${name}</a>
+         <a class="link" target="_blank" href="$(HTML "${url}")")"><img src="${BDB}/favicons/${bid}.ico"/>${name}</a>
          <a class="bmove" href="${SCRIPT_NAME}?action=bmup&fid=${fid}&bid=${bid}">move left</a>
          <a class="bmove" href="${SCRIPT_NAME}?action=bmdn&fid=${fid}&bid=${bid}">move right</a>
        </div>
        EOF
+    else
+      cat <<-EOF
+       <form class="bookmark" target="_blank" method="POST" action="${SCRIPT_NAME}?action=query">
+         <a class="modify" href="${SCRIPT_NAME}?bmodify=${bid}">Modify</a>
+         <input type="hidden" name="fid" value="$fid" />
+         <input type="hidden" name="bid" value="$bid" />
+         <img src="${BDB}/favicons/${bid}.ico"/><input name="query" placeholder="$name"/>
+         <a class="bmove" href="${SCRIPT_NAME}?action=bmup&fid=${fid}&bid=${bid}">move left</a>
+         <a class="bmove" href="${SCRIPT_NAME}?action=bmdn&fid=${fid}&bid=${bid}">move right</a>
+       </form>
+       EOF
+    fi
   done
 }
 
@@ -375,7 +400,12 @@ foldermod(){
 show_folders(){
   list_folders \
   | while read fid fname order; do
-    cat <<-EOF
+    file="${BDB}/${fid}.bm"
+    cache="${BDB}/${fid}.cache"
+    if [ "${cache}" -nt "${file}" ]; then
+      cat "$cache"
+    else
+      tee "$cache" <<-EOF
        <section class="folder" id="${fid}">
          <h1>${fname}</h1>
          <a class="modify" href="${SCRIPT_NAME}?fmodify=${fid}">Modify</a>
@@ -388,6 +418,7 @@ show_folders(){
           </form>
        </section>
        EOF
+    fi
   done
 }