diff options
author | Rodrigo Arias Mallo <rodarima@gmail.com> | 2024-04-04 20:44:42 +0200 |
---|---|---|
committer | Rodrigo Arias Mallo <rodarima@gmail.com> | 2024-04-04 20:44:42 +0200 |
commit | ee5d1609bfc22b44750a1160d2727c34fa8934ed (patch) | |
tree | 5428652db73b58a2176286511ab27902efe7ba5c /spartan.filter.dpi | |
parent | 49b26cca36ba04ec4e92329589003383c8c439b6 (diff) |
Use first heading as title in Gemini documentsuse-first-heading-as-title
Diffstat (limited to 'spartan.filter.dpi')
-rwxr-xr-x | spartan.filter.dpi | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/spartan.filter.dpi b/spartan.filter.dpi index 27128b1..586b71d 100755 --- a/spartan.filter.dpi +++ b/spartan.filter.dpi @@ -83,17 +83,26 @@ serve_page() { printf "<cmd='start_send_page' url='' '>\n" if [ "$ftype" == "text/gemini" ]; then + # Use first line as title if it is a top level header + IFS=" \n\r" read -r -u 9 first_line + title= + case "$first_line" in + "# "*) title="${first_line#"# "}";; + *) title="${noproto}";; + esac + printf "Content-type: text/html\r\n\r\n" echo "<!DOCTYPE html>" echo "<html>" echo "<head>" - echo "<title>${noproto}</title>" + echo "<title>${title}</title>" echo "<style>" cat "$dir/style.css" echo "</style>" echo "</head>" echo "<body>" - <&9 cat | tr -d '\r' | fix_links | markdown -f +fencedcode + (printf "%s\n" "$first_line"; <&9 cat) \ + | tr -d '\r' | fix_links | markdown -f +fencedcode echo "</body>" echo "</html>" else |