From c772716e98e11181d301deadeca52856ac18f085 Mon Sep 17 00:00:00 2001 From: Feuerfuchs Date: Mon, 18 May 2020 18:51:19 +0200 Subject: Improved Gemini support --- assets/main.js | 2 +- assets/style.css | 2 +- css/main.scss | 26 ++++++++++++++++---------- internal/port/gemini.go | 36 ++++++++++++++++++++++++++++++++++-- internal/port/gopher.go | 16 ++++++++++------ internal/port/main.go | 6 ++++++ internal/port/tpl/gemini.html | 11 ++++++++--- internal/port/tpl/gopher.html | 2 +- internal/port/tpl/startpage.html | 2 +- js/main.ts | 19 ++++++++----------- 10 files changed, 86 insertions(+), 36 deletions(-) diff --git a/assets/main.js b/assets/main.js index 1fa4dcf..a658224 100644 --- a/assets/main.js +++ b/assets/main.js @@ -1 +1 @@ -"use strict";var KeyValueStore=function(){function e(e){this.data=e;for(var t=0,n=Object.keys(e);t=n.valueRange.length?l=0:l<0&&(l=n.valueRange.length-1),a=n.value=n.valueRange[l]}else{if("number"!=typeof a)throw new Error("Can't cycle \""+e+'"');a+=t,n.value=a}return n.callbacks&&n.callbacks.forEach((function(e){e(a)})),a},e.prototype.addCallback=function(e,t){var n=this.data[e];n.callbacks||(n.callbacks=[]),n.callbacks.push(t)},e}();function ensureSetting(e,t){var n=localStorage.getItem(e);return null===n&&(n=t,localStorage.setItem(e,n)),n}var settings=new KeyValueStore({wordWrap:{value:"1"===ensureSetting("word-wrap","1"),callbacks:[function(e){localStorage.setItem("word-wrap",e?"1":"0")}],valueRange:[!1,!0]},monospaceFont:{value:"1"===ensureSetting("monospace-font","1"),callbacks:[function(e){localStorage.setItem("monospace-font",e?"1":"0")}],valueRange:[!1,!0]},imagePreviews:{value:"1"===ensureSetting("image-previews","1"),callbacks:[function(e){localStorage.setItem("image-previews",e?"1":"0")}],valueRange:[!1,!0]},clickablePlainLinks:{value:"1"===ensureSetting("clickable-plain-links","1"),callbacks:[function(e){localStorage.setItem("clickable-plain-links",e?"1":"0")}],valueRange:[!1,!0]}});function generateImageThumbnails(){for(var e=document.querySelectorAll(".link--IMG, .link--GIF"),t=e.length,n=function(){var n=e[t],a=n.href.replace(/^(.*?)\/I/,"$1/T"),l=document.createTextNode("\n"),i=document.createElement("span");i.classList.add("type-annotation"),i.textContent=" -> ";var s=document.createElement("img");s.src=a,s.addEventListener("load",(function(e){s.classList.remove("faded")}));var r=document.createElement("a");r.classList.add("img-preview"),r.href=n.href,r.addEventListener("click",(function(e){return e.preventDefault(),s.classList.add("faded"),s.classList.contains("expanded")?(s.classList.remove("expanded"),s.src=a):(s.classList.add("expanded"),s.src=r.href),!1})),r.append(s),n.parentNode.insertBefore(r,n.nextSibling),n.parentNode.insertBefore(i,r),n.parentNode.insertBefore(l,i)};t--;)n()}function removeImageThumbnails(){for(var e=document.querySelectorAll(".link--IMG, .link--GIF"),t=e.length;t--;)for(var n=e[t],a=3;a--&&n.nextSibling;)n.nextSibling.remove()}function generateMarkupForPlainLinks(){if(document.body.classList.contains("is-plain")){var e=document.getElementsByClassName("content")[0];e.innerHTML=e.innerHTML.replace(/\b[a-z]*:\/\/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,}\b[-a-zA-Z0-9@:%_\+.,~#?&//=]*/g,(function(e){var t=e;return 0===t.indexOf("gopher://")?t=t.replace(/^gopher:\/\/(.*)$/,location.origin+"/gopher/$1"):0===t.indexOf("gemini://")&&(t=t.replace(/^gemini:\/\/(.*)$/,location.origin+"/gemini/$1")),''+e+""})),e.innerHTML=e.innerHTML.replace(/\bmailto:[-a-zA-Z0-9@:%._\+~#=]+@(?:[-a-zA-Z0-9@:%._\+~#=]+\.)+[a-z]{2,}\b/g,(function(e){return''+e+""}))}}function removeMarkupForPlainLinks(){if(document.body.classList.contains("is-plain"))for(var e=document.getElementsByClassName("content")[0],t=e.getElementsByTagName("a"),n=t.length;n--;){var a=t[n],l=document.createTextNode(a.textContent);e.replaceChild(l,a)}}!function(){for(var e=document.getElementsByClassName("link--QRY"),t=e.length;t--;)e[t].addEventListener("click",(function(e){e.preventDefault();var t=prompt("Please enter required input: ","");return null!==t&&""!==t&&(window.location.href=e.target.href+"?"+t),!1}))}(),function(){for(var e=document.getElementsByClassName("location__prefix"),t=e.length;t--;)e[t].addEventListener("click",(function(e){e.preventDefault();var t=prompt("Please enter new location (gopher://... or gemini://...):","");return null!==t&&""!==t.trim()&&(t=0===(t=t.trim()).indexOf("gopher://")?"gopher/"+t.substring(9):0===t.indexOf("gemini://")?"gemini/"+t.substring(9):"gopher/"+t,window.location.href=window.location.origin+"/"+t),!1}))}(),function(){var e=document.getElementsByClassName("wrap")[0],t=e.getElementsByClassName("content")[0],n=document.getElementsByClassName("setting--image-previews")[0].getElementsByClassName("setting__value")[0],a=function(e,t){void 0===t&&(t=!1),e?generateImageThumbnails():t||removeImageThumbnails(),n.textContent=e?"[yes]":"[no]"};n.addEventListener("click",(function(e){return e.preventDefault(),settings.cycleValue("imagePreviews"),!1})),a(settings.getValue("imagePreviews"),!0),settings.addCallback("imagePreviews",a);var l=document.getElementsByClassName("setting--monospace-font")[0].getElementsByClassName("setting__value")[0],i=function(e){e?t.classList.add("content--prefer-monospace"):t.classList.remove("content--prefer-monospace"),l.textContent=e?"[yes]":"[no]"};l.addEventListener("click",(function(e){return e.preventDefault(),settings.cycleValue("monospaceFont"),!1})),i(settings.getValue("monospaceFont")),settings.addCallback("monospaceFont",i);var s=document.getElementsByClassName("setting--word-wrap")[0].getElementsByClassName("setting__value")[0],r=function(t){t?e.classList.add("wrap--word-wrap"):e.classList.remove("wrap--word-wrap"),s.textContent=t?"[yes]":"[no]"};s.addEventListener("click",(function(e){return e.preventDefault(),settings.cycleValue("wordWrap"),!1})),r(settings.getValue("wordWrap")),settings.addCallback("wordWrap",r);var o=document.getElementsByClassName("setting--clickable-plain-links")[0].getElementsByClassName("setting__value")[0],c=function(e){e?generateMarkupForPlainLinks():removeMarkupForPlainLinks(),o.textContent=e?"[yes]":"[no]"};o.addEventListener("click",(function(e){return e.preventDefault(),settings.cycleValue("clickablePlainLinks"),!1})),c(settings.getValue("clickablePlainLinks")),settings.addCallback("clickablePlainLinks",c)}(),function(){for(var e=document.getElementsByClassName("modal"),t=e.length,n=function(){var n=e[t],a=n.getElementsByClassName("modal__content")[0],l=n.getElementsByClassName("modal__close-btn")[0];document.addEventListener("click",(function(e){n.classList.contains("modal--visible")&&(e.target===a||a.contains(e.target)||(n.classList.remove("modal--visible"),e.preventDefault(),e.stopPropagation()))}),!0),document.addEventListener("keydown",(function(e){n.classList.contains("modal--visible")&&27===e.keyCode&&n.classList.remove("modal--visible")})),l.addEventListener("click",(function(e){return e.preventDefault(),n.classList.remove("modal--visible"),!1}))};t--;)n();var a=document.getElementsByClassName("settings-btn")[0],l=document.getElementsByClassName("modal--settings")[0];a.addEventListener("click",(function(e){return e.preventDefault(),l.classList.add("modal--visible"),!1}))}(); \ No newline at end of file +"use strict";var KeyValueStore=function(){function e(e){this.data=e;for(var t=0,n=Object.keys(e);t=n.valueRange.length?l=0:l<0&&(l=n.valueRange.length-1),a=n.value=n.valueRange[l]}else{if("number"!=typeof a)throw new Error("Can't cycle \""+e+'"');a+=t,n.value=a}return n.callbacks&&n.callbacks.forEach((function(e){e(a)})),a},e.prototype.addCallback=function(e,t){var n=this.data[e];n.callbacks||(n.callbacks=[]),n.callbacks.push(t)},e}();function ensureSetting(e,t){var n=localStorage.getItem(e);return null===n&&(n=t,localStorage.setItem(e,n)),n}var settings=new KeyValueStore({wordWrap:{value:"1"===ensureSetting("word-wrap","1"),callbacks:[function(e){localStorage.setItem("word-wrap",e?"1":"0")}],valueRange:[!1,!0]},monospaceFont:{value:"1"===ensureSetting("monospace-font","1"),callbacks:[function(e){localStorage.setItem("monospace-font",e?"1":"0")}],valueRange:[!1,!0]},imagePreviews:{value:"1"===ensureSetting("image-previews","1"),callbacks:[function(e){localStorage.setItem("image-previews",e?"1":"0")}],valueRange:[!1,!0]},clickablePlainLinks:{value:"1"===ensureSetting("clickable-plain-links","1"),callbacks:[function(e){localStorage.setItem("clickable-plain-links",e?"1":"0")}],valueRange:[!1,!0]}});function generateImageThumbnails(){for(var e=document.querySelectorAll(".link--IMG, .link--GIF"),t=e.length,n=function(){var n=e[t],a=n.href.replace(/^(.*?)\/I/,"$1/T"),l=document.createElement("div");l.classList.add("section");var s=document.createElement("span");s.classList.add("section__type"),s.textContent=" -> ";var i=document.createElement("img");i.src=a,i.addEventListener("load",(function(e){i.classList.remove("faded")}));var r=document.createElement("a");r.classList.add("section__content"),r.classList.add("img-preview"),r.href=n.href,r.addEventListener("click",(function(e){return e.preventDefault(),i.classList.add("faded"),i.classList.contains("expanded")?(i.classList.remove("expanded"),i.src=a):(i.classList.add("expanded"),i.src=r.href),!1})),r.append(i),l.append(s),l.append(r),n.parentNode.parentNode.insertBefore(l,n.parentNode.nextSibling)};t--;)n()}function removeImageThumbnails(){for(var e=document.querySelectorAll(".link--IMG, .link--GIF"),t=e.length;t--;)e[t].parentNode.nextSibling.remove()}function generateMarkupForPlainLinks(){if(document.body.classList.contains("is-plain")){var e=document.getElementsByClassName("content")[0];e.innerHTML=e.innerHTML.replace(/\b[a-z]*:\/\/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,}\b[-a-zA-Z0-9@:%_\+.,~#?&//=]*/g,(function(e){var t=e;return 0===t.indexOf("gopher://")?t=t.replace(/^gopher:\/\/(.*)$/,location.origin+"/gopher/$1"):0===t.indexOf("gemini://")&&(t=t.replace(/^gemini:\/\/(.*)$/,location.origin+"/gemini/$1")),''+e+""})),e.innerHTML=e.innerHTML.replace(/\bmailto:[-a-zA-Z0-9@:%._\+~#=]+@(?:[-a-zA-Z0-9@:%._\+~#=]+\.)+[a-z]{2,}\b/g,(function(e){return''+e+""}))}}function removeMarkupForPlainLinks(){if(document.body.classList.contains("is-plain"))for(var e=document.getElementsByClassName("content")[0],t=e.getElementsByTagName("a"),n=t.length;n--;){var a=t[n],l=document.createTextNode(a.textContent);e.replaceChild(l,a)}}!function(){for(var e=document.getElementsByClassName("link--QRY"),t=e.length;t--;)e[t].addEventListener("click",(function(e){e.preventDefault();var t=prompt("Please enter required input: ","");return null!==t&&""!==t&&(window.location.href=e.target.href+"?"+t),!1}))}(),function(){for(var e=document.getElementsByClassName("location__prefix"),t=e.length;t--;)e[t].addEventListener("click",(function(e){e.preventDefault();var t=prompt("Please enter new location (gopher://... or gemini://...):","");return null!==t&&""!==t.trim()&&(t=0===(t=t.trim()).indexOf("gopher://")?"gopher/"+t.substring(9):0===t.indexOf("gemini://")?"gemini/"+t.substring(9):"gopher/"+t,window.location.href=window.location.origin+"/"+t),!1}))}(),function(){var e=document.getElementsByClassName("wrap")[0],t=e.getElementsByClassName("content")[0],n=document.getElementsByClassName("setting--image-previews")[0].getElementsByClassName("setting__value")[0],a=function(e,t){void 0===t&&(t=!1),e?generateImageThumbnails():t||removeImageThumbnails(),n.textContent=e?"[yes]":"[no]"};n.addEventListener("click",(function(e){return e.preventDefault(),settings.cycleValue("imagePreviews"),!1})),a(settings.getValue("imagePreviews"),!0),settings.addCallback("imagePreviews",a);var l=document.getElementsByClassName("setting--monospace-font")[0].getElementsByClassName("setting__value")[0],s=function(e){e?t.classList.add("content--prefer-monospace"):t.classList.remove("content--prefer-monospace"),l.textContent=e?"[yes]":"[no]"};l.addEventListener("click",(function(e){return e.preventDefault(),settings.cycleValue("monospaceFont"),!1})),s(settings.getValue("monospaceFont")),settings.addCallback("monospaceFont",s);var i=document.getElementsByClassName("setting--word-wrap")[0].getElementsByClassName("setting__value")[0],r=function(t){t?e.classList.add("wrap--word-wrap"):e.classList.remove("wrap--word-wrap"),i.textContent=t?"[yes]":"[no]"};i.addEventListener("click",(function(e){return e.preventDefault(),settings.cycleValue("wordWrap"),!1})),r(settings.getValue("wordWrap")),settings.addCallback("wordWrap",r);var o=document.getElementsByClassName("setting--clickable-plain-links")[0].getElementsByClassName("setting__value")[0],c=function(e){e?generateMarkupForPlainLinks():removeMarkupForPlainLinks(),o.textContent=e?"[yes]":"[no]"};o.addEventListener("click",(function(e){return e.preventDefault(),settings.cycleValue("clickablePlainLinks"),!1})),c(settings.getValue("clickablePlainLinks")),settings.addCallback("clickablePlainLinks",c)}(),function(){for(var e=document.getElementsByClassName("modal"),t=e.length,n=function(){var n=e[t],a=n.getElementsByClassName("modal__content")[0],l=n.getElementsByClassName("modal__close-btn")[0];document.addEventListener("click",(function(e){n.classList.contains("modal--visible")&&(e.target===a||a.contains(e.target)||(n.classList.remove("modal--visible"),e.preventDefault(),e.stopPropagation()))}),!0),document.addEventListener("keydown",(function(e){n.classList.contains("modal--visible")&&27===e.keyCode&&n.classList.remove("modal--visible")})),l.addEventListener("click",(function(e){return e.preventDefault(),n.classList.remove("modal--visible"),!1}))};t--;)n();var a=document.getElementsByClassName("settings-btn")[0],l=document.getElementsByClassName("modal--settings")[0];a.addEventListener("click",(function(e){return e.preventDefault(),l.classList.add("modal--visible"),!1}))}(); \ No newline at end of file diff --git a/assets/style.css b/assets/style.css index e662925..a03e8b3 100644 --- a/assets/style.css +++ b/assets/style.css @@ -1 +1 @@ -body{margin:0;padding:0;background-color:#14171a;color:#cad1d8;font-family:"Iosevka Term SS03","IBM Plex Mono","Fira Code","Fira Mono","Roboto Mono","Droid Sans Mono",Monaco,Consolas,Courier,monospace;font-size:1em;line-height:1.5}pre{margin:0;font:inherit;font-family:"Iosevka Term SS03","IBM Plex Mono","Fira Code","Fira Mono","Roboto Mono","Droid Sans Mono",Monaco,Consolas,Courier,monospace;white-space:pre-wrap}h1,h2,h3,h4,h5,h6{font:inherit;font-weight:bold;color:#fff;margin:0}p{margin:0}ul,ol{margin:0;padding:0;list-style-type:none}ul li{padding-left:4ch}ul li::before{display:inline-block;width:2ch;padding-left:2ch;margin-left:-4ch;content:'–'}button{background:none;border:0;padding:0;color:#fff;font:inherit;text-decoration:underline;cursor:pointer}button:focus{outline:1px dotted currentColor}img{display:inline-block;vertical-align:top;max-width:8em;margin:.1em 0}img::selection{background-color:rgba(239,198,138,0.35)}img.expanded{max-width:40em;max-width:80ch}img.faded{opacity:.5}strong{font-weight:normal}::selection{color:#000;background-color:rgba(239,198,138,0.996)}:link{color:#fff}:visited{color:#cad1d8}:link:hover,:visited:hover{color:#fff}.header-base{display:flex;flex-direction:row;align-items:center;justify-content:space-between;border-bottom:1px solid #353a3f}.header{padding:.9em 1em;color:#929ba3}.location{flex:0 1 auto;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;text-overflow:ellipsis '|';margin-right:.5em}.location__prefix{margin-right:.3em;color:#929ba3;cursor:pointer}@media (hover: hover){.location__prefix:hover{color:#fff}}.location__prefix--mobile{display:none}.location__slash{margin:0 .3em}.location__uripart{color:#fff}.location__uripart+.location__slash+.location__uripart{color:#cad1d8}.location__uripart:link:hover,.location__uripart:visited:hover{color:#fff}.actions{flex:0 0 auto}.actions :visited{color:#fff}.action{display:inline}.action+.action::before{content:' | '}.wrap{padding:2em 1em;text-align:center}.wrap--word-wrap{max-width:45em;max-width:90ch;margin:0 auto}.content{box-sizing:border-box;display:inline-block;min-width:0;max-width:100%;margin:0;padding:0;text-align:left;font:inherit;font-family:"Open Sans","Fira Sans","Roboto","Droid Sans",sans-serif}.content--monospace,.content--prefer-monospace{font-family:"Iosevka Term SS03","IBM Plex Mono","Fira Code","Fira Mono","Roboto Mono","Droid Sans Mono",Monaco,Consolas,Courier,monospace}.section{display:flex;align-items:baseline;flex-direction:row;justify-content:flex-start;min-height:1.5em;padding-left:3em;padding-left:5ch}.section__type{flex:0 0 auto;margin-left:-3em;margin-left:-5ch;padding-right:1.25em;padding-right:2ch;width:1.75em;width:3ch;color:#929ba3;font-family:"Iosevka Term SS03","IBM Plex Mono","Fira Code","Fira Mono","Roboto Mono","Droid Sans Mono",Monaco,Consolas,Courier,monospace;text-align:right;user-select:none}.section__content{min-width:0;word-wrap:break-word}.modal{position:fixed;top:0;left:0;z-index:100;display:none;width:100%;height:100%;box-sizing:border-box;padding:2em;background-color:rgba(0,0,0,0.75)}.modal--visible{display:block}.modal__content{max-width:30em;padding:1.5em 1.8em;margin:0 auto;background-color:#14171a;box-shadow:0 .3em 2em #000;text-align:left}.modal__head{padding-bottom:.75em;margin-bottom:1.5em}.modal__title{padding-right:1em;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;text-transform:uppercase}.setting{display:flex;flex-direction:row;align-items:baseline;justify-content:space-between}.setting::after{order:2;flex:1 1 auto;display:block;height:0;margin:0 .5em;border-bottom:2px dotted #353a3f;content:''}.setting__label{order:1}.setting__value{order:3}@media screen and (max-width: 800px){body{font-size:1em}.modal{padding:1em}.modal__content{padding:1em 1.3em}}@media screen and (max-width: 500px){.location__prefix{display:none}.location__prefix--mobile{display:inline}.action{display:block}.action+.action::before{content:''}}@media screen and (max-width: 280px){.location__prefix--mobile{display:none}} +body{margin:0;padding:0;background-color:#14171a;color:#cad1d8;font-family:"Iosevka Term SS03","IBM Plex Mono","Fira Code","Fira Mono","Roboto Mono","Droid Sans Mono",Monaco,Consolas,Courier,monospace;font-size:1.0625em;line-height:1.5}pre{margin:0;font:inherit;font-family:"Iosevka Term SS03","IBM Plex Mono","Fira Code","Fira Mono","Roboto Mono","Droid Sans Mono",Monaco,Consolas,Courier,monospace;white-space:pre-wrap}h1,h2,h3,h4,h5,h6{font:inherit;font-weight:bold;color:#fff;margin:0}p{margin:0}ul,ol{margin:0;padding:0;list-style-type:none}ul li{padding-left:2.5em}ul li::before{display:inline-block;width:1.5em;padding-left:1em;margin-left:-2.5em;content:'–'}button{background:none;border:0;padding:0;color:#fff;font:inherit;text-decoration:underline;cursor:pointer}button:focus{outline:1px dotted currentColor}img{display:inline-block;vertical-align:top;max-width:8em;margin:.1em 0}img::selection{background-color:rgba(239,198,138,0.35)}img.expanded{max-width:40em;max-width:80ch}img.faded{opacity:.5}strong{font-weight:normal}::selection{color:#000;background-color:rgba(239,198,138,0.996)}:link{color:#fff}:visited{color:#cad1d8}:link:hover,:visited:hover{color:#fff}.header-base{display:flex;flex-direction:row;align-items:center;justify-content:space-between;border-bottom:1px solid #353a3f}.header{padding:.9em 1em;color:#929ba3}.location{flex:0 1 auto;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;text-overflow:ellipsis '|';margin-right:.5em}.location__prefix{margin-right:.3em;color:#929ba3;cursor:pointer}@media (hover: hover){.location__prefix:hover{color:#fff}}.location__prefix--mobile{display:none}.location__slash{margin:0 .3em}.location__uripart{color:#fff}.location__uripart+.location__slash+.location__uripart{color:#cad1d8}.location__uripart:link:hover,.location__uripart:visited:hover{color:#fff}.actions{flex:0 0 auto}.actions :visited{color:#fff}.action{display:inline}.action+.action::before{content:' | '}.wrap{padding:2em 1em;text-align:center}.wrap--word-wrap{max-width:45em;max-width:90ch;margin:0 auto}.content{box-sizing:border-box;display:inline-block;min-width:0;max-width:100%;margin:0;padding:0;text-align:left;font:inherit;font-family:"Open Sans","Fira Sans","Roboto","Droid Sans",sans-serif}.content--monospace,.content--prefer-monospace{font-family:"Iosevka Term SS03","IBM Plex Mono","Fira Code","Fira Mono","Roboto Mono","Droid Sans Mono",Monaco,Consolas,Courier,monospace}.section{display:flex;align-items:baseline;flex-direction:row;justify-content:flex-start;min-height:1.5em;padding-left:3em;padding-left:5ch}.section__type{flex:0 0 auto;margin-left:-3em;margin-left:-5ch;width:3em;width:5ch;color:#929ba3;font-family:"Iosevka Term SS03","IBM Plex Mono","Fira Code","Fira Mono","Roboto Mono","Droid Sans Mono",Monaco,Consolas,Courier,monospace;user-select:none;white-space:pre}.section__content{min-width:0;word-wrap:break-word}.is-plain .section{padding-left:0}.is-plain .section__type{display:none}.modal{position:fixed;top:0;left:0;z-index:100;display:none;width:100%;height:100%;box-sizing:border-box;padding:2em;background-color:rgba(0,0,0,0.75)}.modal--visible{display:block}.modal__content{max-width:30em;padding:1.5em 1.8em;margin:0 auto;background-color:#14171a;box-shadow:0 .3em 2em #000;text-align:left}.modal__head{padding-bottom:.75em;margin-bottom:1.5em}.modal__title{padding-right:1em;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;text-transform:uppercase}.setting{display:flex;flex-direction:row;align-items:baseline;justify-content:space-between}.setting::after{order:2;flex:1 1 auto;display:block;height:0;margin:0 .5em;border-bottom:2px dotted #353a3f;content:''}.setting__label{order:1}.setting__value{order:3}@media screen and (max-width: 800px){body{font-size:1em}.modal{padding:1em}.modal__content{padding:1em 1.3em}}@media screen and (max-width: 500px){.location__prefix{display:none}.location__prefix--mobile{display:inline}.action{display:block}.action+.action::before{content:''}}@media screen and (max-width: 280px){.location__prefix--mobile{display:none}} diff --git a/css/main.scss b/css/main.scss index 27a62ec..b768a87 100644 --- a/css/main.scss +++ b/css/main.scss @@ -28,7 +28,7 @@ body { // ); color: $text; font-family: $font-monospace; - font-size: 1em; //1 / 16 * 17em; + font-size: 1 / 16 * 17em; line-height: 1.5; } @@ -58,13 +58,13 @@ ul, ol { ul { li { - padding-left: 4ch; + padding-left: 2.5em; &::before { display: inline-block; - width: 2ch; - padding-left: 2ch; - margin-left: -4ch; + width: 1.5em; + padding-left: 1em; + margin-left: -2.5em; content: '–'; } } @@ -259,20 +259,26 @@ strong { flex: 0 0 auto; margin-left: -3em; margin-left: -5ch; - padding-right: 1.25em; - padding-right: 2ch; - width: 1.75em; - width: 3ch; + width: 3em; + width: 5ch; color: $text-minus; font-family: $font-monospace; - text-align: right; user-select: none; + white-space: pre; } &__content { min-width: 0; word-wrap: break-word; } + + .is-plain & { + padding-left: 0; + + &__type { + display: none; + } + } } // diff --git a/internal/port/gemini.go b/internal/port/gemini.go index 740fccd..f67ca05 100644 --- a/internal/port/gemini.go +++ b/internal/port/gemini.go @@ -29,8 +29,9 @@ type GeminiTemplateVariables struct { } type GeminiNavItem struct { - Label string - URL string + Label string + URL string + Current bool } type GeminiSection struct { @@ -40,6 +41,32 @@ type GeminiSection struct { Items []string } +func urlToGeminiNav(url string) (items []GeminiNavItem) { + partialURL := "/gemini" + parts := strings.Split(url, "/") + + if len(parts) != 0 && parts[len(parts)-1] == "" { + parts = parts[:len(parts)-1] + } + + for i, part := range parts { + partialURL = partialURL + "/" + part + + current := false + if i == len(parts)-1 || (len(parts) == 2 && i == 0) { + current = true + } + + items = append(items, GeminiNavItem{ + Label: part, + URL: partialURL, + Current: current, + }) + } + + return +} + func resolveURL(uri string, baseURL *url.URL) (resolvedURL string) { if strings.HasPrefix(uri, "//") { resolvedURL = "/gemini/" + strings.TrimPrefix(uri, "//") @@ -137,6 +164,7 @@ func GeminiHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass Type: libgemini.RAW_TEXT.String(), Text: fmt.Sprintf("Error: %s", err), }}, + Nav: urlToGeminiNav(hostport), IsPlain: true, }); e != nil { log.Println("Template error: " + e.Error()) @@ -167,6 +195,7 @@ func GeminiHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass Type: libgemini.RAW_TEXT.String(), Text: fmt.Sprintf("Error: %s", err), }}, + Nav: urlToGeminiNav(fmt.Sprintf("%s/%s", hostport, uri)), IsPlain: true, }); e != nil { log.Println("Template error: " + e.Error()) @@ -190,6 +219,7 @@ func GeminiHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass Type: libgemini.RAW_TEXT.String(), Text: fmt.Sprintf("Error: %s", err), }}, + Nav: urlToGeminiNav(fmt.Sprintf("%s/%s", hostport, uri)), IsPlain: true, }); e != nil { log.Println("Template error: " + e.Error()) @@ -211,6 +241,7 @@ func GeminiHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass Type: libgemini.RAW_TEXT.String(), Text: fmt.Sprintf("Error %d: %s", res.Header.Status, res.Header.Meta), }}, + Nav: urlToGeminiNav(fmt.Sprintf("%s/%s", hostport, uri)), IsPlain: true, }); err != nil { log.Println("Template error: " + err.Error()) @@ -252,6 +283,7 @@ func GeminiHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass URL: fmt.Sprintf("%s/%s", hostport, uri), Assets: assetList, Sections: sections, + Nav: urlToGeminiNav(fmt.Sprintf("%s/%s", hostport, uri)), IsPlain: isPlain, }); err != nil { log.Println("Template error: " + err.Error()) diff --git a/internal/port/gopher.go b/internal/port/gopher.go index d2283c6..cb5e60c 100644 --- a/internal/port/gopher.go +++ b/internal/port/gopher.go @@ -49,10 +49,14 @@ func trimLeftChars(s string, n int) string { return s[:0] } -func urlToNav(url string) (items []GopherNavItem) { +func urlToGopherNav(url string) (items []GopherNavItem) { partialURL := "/gopher" parts := strings.Split(url, "/") + if len(parts) != 0 && parts[len(parts)-1] == "" { + parts = parts[:len(parts)-1] + } + for i, part := range parts { if i == 1 { partialURL = partialURL + "/1" @@ -151,7 +155,7 @@ func renderGopherDirectory(w http.ResponseWriter, tpl *template.Template, assetL URL: fmt.Sprintf("%s/%s", hostport, uri), Assets: assetList, Lines: out, - Nav: urlToNav(fmt.Sprintf("%s/%s", hostport, uri)), + Nav: urlToGopherNav(fmt.Sprintf("%s/%s", hostport, uri)), }) } @@ -194,7 +198,7 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass Lines: []GopherItem{{ Text: fmt.Sprintf("Error: %s", err), }}, - Nav: urlToNav(hostport), + Nav: urlToGopherNav(hostport), IsPlain: true, }); e != nil { log.Println("Template error: " + e.Error()) @@ -224,7 +228,7 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass Lines: []GopherItem{{ Text: fmt.Sprintf("Error: %s", err), }}, - Nav: urlToNav(fmt.Sprintf("%s/%s", hostport, uri)), + Nav: urlToGopherNav(fmt.Sprintf("%s/%s", hostport, uri)), IsPlain: true, }); e != nil { log.Println("Template error: " + e.Error()) @@ -246,7 +250,7 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass Lines: []GopherItem{{ Text: buf.String(), }}, - Nav: urlToNav(fmt.Sprintf("%s/%s", hostport, uri)), + Nav: urlToGopherNav(fmt.Sprintf("%s/%s", hostport, uri)), IsPlain: true, }); err != nil { log.Println("Template error: " + err.Error()) @@ -271,7 +275,7 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass Lines: []GopherItem{{ Text: fmt.Sprintf("Error: %s", err), }}, - Nav: urlToNav(fmt.Sprintf("%s/%s", hostport, uri)), + Nav: urlToGopherNav(fmt.Sprintf("%s/%s", hostport, uri)), IsPlain: false, }); e != nil { log.Println("Template error: " + e.Error()) diff --git a/internal/port/main.go b/internal/port/main.go index 763057b..fe85ba4 100644 --- a/internal/port/main.go +++ b/internal/port/main.go @@ -237,9 +237,15 @@ func ListenAndServe(bind, startpagefile string, robotsfile string, robotsdebug b "hasPrefix": func(s string, prefix string) bool { return strings.HasPrefix(s, prefix) }, + "hasSuffix": func(s string, suffix string) bool { + return strings.HasSuffix(s, suffix) + }, "title": func(s string) string { return strings.Title(s) }, + "string": func(s interface{}) string { + return fmt.Sprint(s) + }, } // diff --git a/internal/port/tpl/gemini.html b/internal/port/tpl/gemini.html index df50d50..8d20da1 100644 --- a/internal/port/tpl/gemini.html +++ b/internal/port/tpl/gemini.html @@ -35,11 +35,16 @@ {{- else if eq .Type "REFLOW_TEXT" -}}

{{- .Text -}}

{{- else if eq .Type "LINK" -}} - + {{- $linkCls := "link" -}} + {{- $url := string .URL -}} + {{- if or (hasSuffix $url ".jpg") (hasSuffix $url ".jpeg") (hasSuffix $url ".png") (hasSuffix $url ".gif") -}} + {{- $linkCls = "link--IMG" -}} + {{- end -}} + {{- else if eq .Type "HEADING_1" -}} -
#

{{- .Text -}}

+
#

{{- .Text -}}

{{- else if eq .Type "HEADING_2" -}} -
##

{{- .Text -}}

+
##

{{- .Text -}}

{{- else if eq .Type "HEADING_3" -}}
###

{{- .Text -}}

{{- else if eq .Type "LIST" -}} diff --git a/internal/port/tpl/gopher.html b/internal/port/tpl/gopher.html index 5436123..6eb607c 100644 --- a/internal/port/tpl/gopher.html +++ b/internal/port/tpl/gopher.html @@ -35,7 +35,7 @@ {{- $page := . -}} {{- range .Lines -}} {{- if .Link -}} -
{{- .Type -}}{{- .Text -}}
+
{{- .Type -}}{{- .Text -}}
{{- else -}}
{{- .Text -}}
{{- end -}} diff --git a/internal/port/tpl/startpage.html b/internal/port/tpl/startpage.html index cfe519d..772ac90 100644 --- a/internal/port/tpl/startpage.html +++ b/internal/port/tpl/startpage.html @@ -18,7 +18,7 @@
-
+			
         {{- .Content -}}
 			
diff --git a/js/main.ts b/js/main.ts index 031e959..0c1d3de 100644 --- a/js/main.ts +++ b/js/main.ts @@ -246,10 +246,11 @@ function generateImageThumbnails() { const linkImgEl = linkImgEls[i] as HTMLAnchorElement; const thumbnailUrl = linkImgEl.href.replace(/^(.*?)\/I/, '$1/T'); - const lineBreakEl = document.createTextNode('\n'); + const sectionEl = document.createElement('div'); + sectionEl.classList.add('section'); const typeAnnotEl = document.createElement('span'); - typeAnnotEl.classList.add('type-annotation'); + typeAnnotEl.classList.add('section__type'); typeAnnotEl.textContent = ' -> '; const thumbnailEl = document.createElement('img'); @@ -259,6 +260,7 @@ function generateImageThumbnails() { }); const thumbnailAnchorEl = document.createElement('a'); + thumbnailAnchorEl.classList.add('section__content'); thumbnailAnchorEl.classList.add('img-preview'); thumbnailAnchorEl.href = linkImgEl.href; thumbnailAnchorEl.addEventListener('click', e => { @@ -278,9 +280,9 @@ function generateImageThumbnails() { }); thumbnailAnchorEl.append(thumbnailEl); - linkImgEl.parentNode!.insertBefore(thumbnailAnchorEl, linkImgEl.nextSibling); - linkImgEl.parentNode!.insertBefore(typeAnnotEl, thumbnailAnchorEl); - linkImgEl.parentNode!.insertBefore(lineBreakEl, typeAnnotEl); + sectionEl.append(typeAnnotEl); + sectionEl.append(thumbnailAnchorEl); + linkImgEl.parentNode!.parentNode!.insertBefore(sectionEl, linkImgEl.parentNode!.nextSibling); } } @@ -288,12 +290,7 @@ function removeImageThumbnails() { const linkImgEls = document.querySelectorAll('.link--IMG, .link--GIF'); let i = linkImgEls.length; while (i--) { - const linkImgEl = linkImgEls[i]; - let j = 3; - - while (j-- && linkImgEl.nextSibling) { - linkImgEl.nextSibling.remove(); - } + linkImgEls[i].parentNode!.nextSibling!.remove(); } } -- cgit v1.2.3-70-g09d2