Browse Source

author pagination support

raven 7 months ago
parent
commit
f29b9ac93a
3 changed files with 124 additions and 1 deletions
  1. 1 1
      i/template/copy_page.sh
  2. 2 0
      run_server.sh
  3. 121 0
      src/index.sh.pagination

+ 1 - 1
i/template/copy_page.sh

@@ -50,7 +50,7 @@ p.fit {
 <div role="main" id="main" class="holy-main markdown-body px-4 bg-white">
 <!-- /$cgi_search${ae_array[$i]} -->
 <div class="center">
-<h1><a href="/index/#$(echo "$author" | bash $url_slug )">$author</a> / $title</h1>$( [[ -n "$subtitle" ]] && echo -ne "\n<h2>$subtitle</h2>")
+<h1><a href="/author-index/#$(echo "$author" | bash $url_slug )">$author</a> / $title</h1>$( [[ -n "$subtitle" ]] && echo -ne "\n<h2>$subtitle</h2>")
 </div>
 <p>
 <span class="prev">

+ 2 - 0
run_server.sh

@@ -83,7 +83,9 @@ ln -s $pdf_dir/* public/free && echo "/var/pdf/ symbolic link created"
 tor.html > public/tor.html && echo "tor.html created"
 print_standalone > public/print.html && echo "print.html created"
 mkdir public/index && echo "index page creating.."
+mkdir public/author-index && echo "pagination index page creating.."
 nohup bash src/index.sh > public/index/index.html &
+nohup bash src/index.sh.pagination > public/author-index/index.html &
 find public/ -type f -exec chmod 0644 {} \; &> /dev/null && echo "files permissions setted"
 find public/ -type d -exec chmod 0755 {} \; &> /dev/null && echo "directory permissions setted"
 }

+ 121 - 0
src/index.sh.pagination

@@ -0,0 +1,121 @@
+#!/bin/bash
+#START
+res1=$(date +%s.%N)
+
+cd "$(dirname "$0")"
+cd ../bin/;
+. config.sh; #import
+cd - &> /dev/null
+
+db_file="../var/books.db";
+
+index_chars=$(sqlite3 $db_file "SELECT author FROM books" | cut -c 1 | LC_ALL=tr_TR.UTF-8 tr '[:lower:]' '[:upper:]' | sort -u | tr '\n' ' ')
+
+function author_table() {
+sqlite3 $db_file "SELECT title,url FROM books WHERE author IS '$1'" > /tmp/.table.txt
+while IFS="|" read -r title url
+do
+cat <<EOT
+<li class="book"><a href="/copy/$url/">$title</a></li>
+EOT
+done < /tmp/.table.txt
+}
+
+function start_index() {
+sqlite3 $db_file "SELECT author FROM books WHERE author LIKE '$1%'" > /tmp/.list.txt
+sort /tmp/.list.txt | uniq -ci > /tmp/.listed.txt
+while IFS=" " read -r count author
+do
+bid=$(cat /tmp/.id_count)
+cat <<EOT
+<div id="$bid" class="fit-screen">
+<span id="$(echo "$author" | bash $url_slug )">
+<hr>
+<span class="prev">
+	<a href="#$(($bid - 1))">önceki</a>
+</span>
+<span class="next">
+	<a href="#$(($bid + 1))">sonraki</a>
+</span>
+<hr>
+<h1>$author&nbsp;&nbsp;<span class="Counter Counter--gray">$count</span></h1>
+<ul>
+$(author_table "$author")
+</ul>
+</span>
+</div>
+EOT
+ echo "$((  $(cat /tmp/.id_count) + 1 ))" > /tmp/.id_count
+done < /tmp/.listed.txt
+}
+
+
+function start_loop() {
+echo "0" > /tmp/.id_count
+for x in $index_chars;
+do
+cat <<EOT
+<div id="l-$x">
+$(start_index $x)
+</div>
+<br>
+EOT
+done;
+}
+
+cat <<EOT
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1" />
+<!--force_base_href-->
+<title>Kapsamlı İndex</title>
+$style
+<style>
+body {
+  color:black;
+  background-color:white;
+}
+.fit-screen {
+  min-height: 100vh;
+}
+.next {
+  float:right;
+}
+.prev {
+  text-align:left;
+}
+li.book {
+  list-style-type:square;
+}
+</style>
+</head>
+<body class="bg-gray">
+<div id="holy" class="container-lg bg-white h-100">
+    <div id="header" class="px-1 bg-white">
+        <nav class="UnderlineNav UnderlineNav--right px-2">
+        <a class="UnderlineNav-actions muted-link h2" href="/index.html">
+    $site_title</a>
+       </nav>
+   </div>
+<br>
+<div role="main" id="main" class="holy-main markdown-body px-4 bg-white">
+<ul>
+$(start_loop)
+</ul>
+EOT
+
+res2=$(date +%s.%N)
+dt=$(echo "$res2 - $res1" | bc)
+dd=$(echo "$dt/86400" | bc)
+dt2=$(echo "$dt-86400*$dd" | bc)
+dh=$(echo "$dt2/3600" | bc)
+dt3=$(echo "$dt2-3600*$dh" | bc)
+dm=$(echo "$dt3/60" | bc)
+ds=$(echo "$dt3-60*$dm" | bc)
+
+echo "<hr>"
+LC_NUMERIC=C printf 'Page build by bash script in about %02.4f seconds\n' $ds
+
+echo -ne "<br><br></div>\n</div>\n</body>\n</html>"