From e58fabd89f9708aaeb10e52f731759712034833f Mon Sep 17 00:00:00 2001 From: Feuerfuchs Date: Mon, 18 May 2020 18:02:20 +0200 Subject: WIP: Refactoring --- Makefile | 8 +-- assets/iosevka-aile-regular.woff | Bin 187604 -> 0 bytes assets/iosevka-aile-regular.woff2 | Bin 130736 -> 0 bytes assets/iosevka-fixed-ss03-bold.woff | Bin 0 -> 214840 bytes assets/iosevka-fixed-ss03-bold.woff2 | Bin 0 -> 146024 bytes assets/iosevka-fixed-ss03-regular.woff | Bin 0 -> 215424 bytes assets/iosevka-fixed-ss03-regular.woff2 | Bin 0 -> 145296 bytes assets/iosevka-term-ss03-regular.woff | Bin 155916 -> 0 bytes assets/iosevka-term-ss03-regular.woff2 | Bin 111644 -> 0 bytes assets/main.js | 2 +- assets/style.css | 2 +- css/main.scss | 86 ++++++++++++++++++++++++-------- fonts/iosevka-aile-regular.ttf | Bin 497504 -> 0 bytes fonts/iosevka-term-ss03-bold.ttf | Bin 0 -> 704092 bytes fonts/iosevka-term-ss03-regular.ttf | Bin 410836 -> 699144 bytes internal/port/gemini.go | 38 ++++++++------ internal/port/main.go | 56 ++++++++++----------- internal/port/tpl/_fonts.html | 12 ++--- internal/port/tpl/_header.html | 48 ------------------ internal/port/tpl/_modals.html | 2 +- internal/port/tpl/gemini.html | 62 +++++++++++++++-------- internal/port/tpl/gopher.html | 19 ++----- js/main.ts | 4 +- pkg/libgemini/libgemini.go | 64 +++++++++++++----------- 24 files changed, 214 insertions(+), 189 deletions(-) delete mode 100644 assets/iosevka-aile-regular.woff delete mode 100644 assets/iosevka-aile-regular.woff2 create mode 100644 assets/iosevka-fixed-ss03-bold.woff create mode 100644 assets/iosevka-fixed-ss03-bold.woff2 create mode 100644 assets/iosevka-fixed-ss03-regular.woff create mode 100644 assets/iosevka-fixed-ss03-regular.woff2 delete mode 100644 assets/iosevka-term-ss03-regular.woff delete mode 100644 assets/iosevka-term-ss03-regular.woff2 delete mode 100644 fonts/iosevka-aile-regular.ttf create mode 100644 fonts/iosevka-term-ss03-bold.ttf delete mode 100644 internal/port/tpl/_header.html diff --git a/Makefile b/Makefile index 58ac412..a537070 100644 --- a/Makefile +++ b/Makefile @@ -8,10 +8,10 @@ dev: build build: clean sassc -t compressed css/main.scss assets/style.css tsc --strict --module none --outFile /dev/stdout js/* | terser --compress --mangle -o assets/main.js -- - #pyftsubset fonts/iosevka-term-ss03-regular.ttf "*" --name-IDs+=0,4,6 --flavor='woff' --with-zopfli --output-file='assets/iosevka-term-ss03-regular.woff' - #pyftsubset fonts/iosevka-term-ss03-regular.ttf "*" --name-IDs+=0,4,6 --flavor='woff2' --output-file='assets/iosevka-term-ss03-regular.woff2' - #pyftsubset fonts/iosevka-aile-regular.ttf "*" --name-IDs+=0,4,6 --flavor='woff' --with-zopfli --output-file='assets/iosevka-aile-regular.woff' - #pyftsubset fonts/iosevka-aile-regular.ttf "*" --name-IDs+=0,4,6 --flavor='woff2' --output-file='assets/iosevka-aile-regular.woff2' + #pyftsubset fonts/iosevka-fixed-ss03-regular.ttf "*" --name-IDs+=0,4,6 --flavor='woff' --with-zopfli --output-file='assets/iosevka-fixed-ss03-regular.woff' + #pyftsubset fonts/iosevka-fixed-ss03-regular.ttf "*" --name-IDs+=0,4,6 --flavor='woff2' --output-file='assets/iosevka-fixed-ss03-regular.woff2' + #pyftsubset fonts/iosevka-fixed-ss03-bold.ttf "*" --name-IDs+=0,4,6 --flavor='woff' --with-zopfli --output-file='assets/iosevka-fixed-ss03-bold.woff' + #pyftsubset fonts/iosevka-fixed-ss03-bold.ttf "*" --name-IDs+=0,4,6 --flavor='woff2' --output-file='assets/iosevka-fixed-ss03-bold.woff2' go build -o ./port.bin ./cmd/port profile: diff --git a/assets/iosevka-aile-regular.woff b/assets/iosevka-aile-regular.woff deleted file mode 100644 index 97b42ea..0000000 Binary files a/assets/iosevka-aile-regular.woff and /dev/null differ diff --git a/assets/iosevka-aile-regular.woff2 b/assets/iosevka-aile-regular.woff2 deleted file mode 100644 index fea3967..0000000 Binary files a/assets/iosevka-aile-regular.woff2 and /dev/null differ diff --git a/assets/iosevka-fixed-ss03-bold.woff b/assets/iosevka-fixed-ss03-bold.woff new file mode 100644 index 0000000..0ae2733 Binary files /dev/null and b/assets/iosevka-fixed-ss03-bold.woff differ diff --git a/assets/iosevka-fixed-ss03-bold.woff2 b/assets/iosevka-fixed-ss03-bold.woff2 new file mode 100644 index 0000000..317ee3c Binary files /dev/null and b/assets/iosevka-fixed-ss03-bold.woff2 differ diff --git a/assets/iosevka-fixed-ss03-regular.woff b/assets/iosevka-fixed-ss03-regular.woff new file mode 100644 index 0000000..6168a4a Binary files /dev/null and b/assets/iosevka-fixed-ss03-regular.woff differ diff --git a/assets/iosevka-fixed-ss03-regular.woff2 b/assets/iosevka-fixed-ss03-regular.woff2 new file mode 100644 index 0000000..27f81cb Binary files /dev/null and b/assets/iosevka-fixed-ss03-regular.woff2 differ diff --git a/assets/iosevka-term-ss03-regular.woff b/assets/iosevka-term-ss03-regular.woff deleted file mode 100644 index eb2568a..0000000 Binary files a/assets/iosevka-term-ss03-regular.woff and /dev/null differ diff --git a/assets/iosevka-term-ss03-regular.woff2 b/assets/iosevka-term-ss03-regular.woff2 deleted file mode 100644 index 957b020..0000000 Binary files a/assets/iosevka-term-ss03-regular.woff2 and /dev/null differ diff --git a/assets/main.js b/assets/main.js index eee70d7..1fa4dcf 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--has-monospace-font"):t.classList.remove("content--has-monospace-font"),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.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 diff --git a/assets/style.css b/assets/style.css index 70f53a7..e662925 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:1.0625em;line-height:1.5}h1,h2,h3,h4,h5,h6{font:inherit;color:#fff;margin:0}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:50em;max-width:100ch;margin:0 auto}.wrap--word-wrap .content{white-space:pre-wrap;word-wrap:break-word}.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:"Iosevka Aile","Fira Sans","Roboto","Droid Sans",sans-serif}.content--has-type-annotations{padding-left:3em;padding-left:5ch}.content--has-monospace-font{font-family:"Iosevka Term SS03","IBM Plex Mono","Fira Code","Fira Mono","Roboto Mono","Droid Sans Mono",Monaco,Consolas,Courier,monospace}.type-annotation{margin-left:-3em;margin-left:-5ch;color:#929ba3;white-space:pre;font-family:"Iosevka Term SS03","IBM Plex Mono","Fira Code","Fira Mono","Roboto Mono","Droid Sans Mono",Monaco,Consolas,Courier,monospace}.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: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}} diff --git a/css/main.scss b/css/main.scss index 42b0b28..27a62ec 100644 --- a/css/main.scss +++ b/css/main.scss @@ -11,7 +11,7 @@ $sel-background: rgba($accent, .996); $sel-text: #000; $font-monospace: 'Iosevka Term SS03', 'IBM Plex Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', 'Droid Sans Mono', Monaco, Consolas, Courier, monospace; -$font-proportional: 'Iosevka Aile', 'Fira Sans', 'Roboto', 'Droid Sans', sans-serif; +$font-proportional: 'Open Sans', 'Fira Sans', 'Roboto', 'Droid Sans', sans-serif; // // Basic element styles @@ -28,16 +28,48 @@ body { // ); color: $text; font-family: $font-monospace; - font-size: 1 / 16 * 17em; + font-size: 1em; //1 / 16 * 17em; line-height: 1.5; } +pre { + margin: 0; + font: inherit; + font-family: $font-monospace; + white-space: pre-wrap; +} + h1, h2, h3, h4, h5, h6 { font: inherit; + font-weight: bold; color: $text-plus; margin: 0; } +p { + margin: 0; +} + +ul, ol { + margin: 0; + padding: 0; + list-style-type: none; +} + +ul { + li { + padding-left: 4ch; + + &::before { + display: inline-block; + width: 2ch; + padding-left: 2ch; + margin-left: -4ch; + content: '–'; + } + } +} + button { background: none; border: 0; @@ -191,14 +223,9 @@ strong { text-align: center; &--word-wrap { - max-width: 50em; - max-width: 100ch; + max-width: 45em; + max-width: 90ch; margin: 0 auto; - - .content { - white-space: pre-wrap; - word-wrap: break-word; - } } } @@ -213,22 +240,39 @@ strong { font: inherit; font-family: $font-proportional; - &--has-type-annotations { - padding-left: 3em; - padding-left: 5ch; - } - - &--has-monospace-font { + &--monospace, + &--prefer-monospace { font-family: $font-monospace; } } -.type-annotation { - margin-left: -3em; - margin-left: -5ch; - color: $text-minus; - white-space: pre; - font-family: $font-monospace; +.section { + display: flex; + align-items: baseline; + flex-direction: row; + justify-content: flex-start; + min-height: 1em * 1.5; + padding-left: 3em; + padding-left: 5ch; + + &__type { + flex: 0 0 auto; + margin-left: -3em; + margin-left: -5ch; + padding-right: 1.25em; + padding-right: 2ch; + width: 1.75em; + width: 3ch; + color: $text-minus; + font-family: $font-monospace; + text-align: right; + user-select: none; + } + + &__content { + min-width: 0; + word-wrap: break-word; + } } // diff --git a/fonts/iosevka-aile-regular.ttf b/fonts/iosevka-aile-regular.ttf deleted file mode 100644 index 7cad586..0000000 Binary files a/fonts/iosevka-aile-regular.ttf and /dev/null differ diff --git a/fonts/iosevka-term-ss03-bold.ttf b/fonts/iosevka-term-ss03-bold.ttf new file mode 100644 index 0000000..940a28f Binary files /dev/null and b/fonts/iosevka-term-ss03-bold.ttf differ diff --git a/fonts/iosevka-term-ss03-regular.ttf b/fonts/iosevka-term-ss03-regular.ttf index 0cde79e..052416d 100644 Binary files a/fonts/iosevka-term-ss03-regular.ttf and b/fonts/iosevka-term-ss03-regular.ttf differ diff --git a/internal/port/gemini.go b/internal/port/gemini.go index 0d8292c..740fccd 100644 --- a/internal/port/gemini.go +++ b/internal/port/gemini.go @@ -25,6 +25,7 @@ type GeminiTemplateVariables struct { Assets AssetList Sections []GeminiSection Nav []GeminiNavItem + IsPlain bool } type GeminiNavItem struct { @@ -33,7 +34,7 @@ type GeminiNavItem struct { } type GeminiSection struct { - Type libgemini.GeminiDocSectionType + Type string Text string URL template.URL Items []string @@ -83,19 +84,19 @@ func parseGeminiDocument(body *bytes.Buffer, uri string, hostport string) (secti for _, section := range unpreppedSections { if section.Type != libgemini.LINK { sections = append(sections, GeminiSection{ - Type: section.Type, + Type: section.Type.String(), Text: section.Text, URL: template.URL(section.URL), Items: section.Items, }) + } else { + sections = append(sections, GeminiSection{ + Type: section.Type.String(), + Text: section.Text, + URL: template.URL(resolveURL(section.URL, baseURL)), + Items: section.Items, + }) } - - sections = append(sections, GeminiSection{ - Type: section.Type, - Text: section.Text, - URL: template.URL(resolveURL(section.URL, baseURL)), - Items: section.Items, - }) } return @@ -133,9 +134,10 @@ func GeminiHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass URL: hostport, Assets: assetList, Sections: []GeminiSection{{ - Type: libgemini.RAW_TEXT, + Type: libgemini.RAW_TEXT.String(), Text: fmt.Sprintf("Error: %s", err), }}, + IsPlain: true, }); e != nil { log.Println("Template error: " + e.Error()) log.Println(err.Error()) @@ -162,9 +164,10 @@ func GeminiHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass URL: fmt.Sprintf("%s/%s", hostport, uri), Assets: assetList, Sections: []GeminiSection{{ - Type: libgemini.RAW_TEXT, + Type: libgemini.RAW_TEXT.String(), Text: fmt.Sprintf("Error: %s", err), }}, + IsPlain: true, }); e != nil { log.Println("Template error: " + e.Error()) log.Println(err.Error()) @@ -184,9 +187,10 @@ func GeminiHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass URL: fmt.Sprintf("%s/%s", hostport, uri), Assets: assetList, Sections: []GeminiSection{{ - Type: libgemini.RAW_TEXT, + Type: libgemini.RAW_TEXT.String(), Text: fmt.Sprintf("Error: %s", err), }}, + IsPlain: true, }); e != nil { log.Println("Template error: " + e.Error()) log.Println(err.Error()) @@ -204,16 +208,17 @@ func GeminiHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass URL: fmt.Sprintf("%s/%s", hostport, uri), Assets: assetList, Sections: []GeminiSection{{ - Type: libgemini.RAW_TEXT, + Type: libgemini.RAW_TEXT.String(), Text: fmt.Sprintf("Error %d: %s", res.Header.Status, res.Header.Meta), }}, + IsPlain: true, }); err != nil { log.Println("Template error: " + err.Error()) } return } - if strings.HasPrefix(res.Header.Meta, "text/") { + if strings.HasPrefix(res.Header.Meta, "text/") && !strings.HasPrefix(res.Header.Meta, "text/html") && !strings.HasPrefix(res.Header.Meta, "text/css") { buf := new(bytes.Buffer) _, params, err := mime.ParseMediaType(res.Header.Meta) @@ -230,12 +235,14 @@ func GeminiHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass } var sections []GeminiSection + isPlain := true if strings.HasPrefix(res.Header.Meta, libgemini.MIME_GEMINI) { sections = parseGeminiDocument(buf, uri, hostport) + isPlain = false } else { sections = append(sections, GeminiSection{ - Type: libgemini.RAW_TEXT, + Type: libgemini.RAW_TEXT.String(), Text: buf.String(), }) } @@ -245,6 +252,7 @@ func GeminiHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass URL: fmt.Sprintf("%s/%s", hostport, uri), Assets: assetList, Sections: sections, + IsPlain: isPlain, }); err != nil { log.Println("Template error: " + err.Error()) } diff --git a/internal/port/main.go b/internal/port/main.go index 267df44..763057b 100644 --- a/internal/port/main.go +++ b/internal/port/main.go @@ -18,12 +18,12 @@ import ( ) type AssetList struct { - Style string - JS string - FontW string - FontW2 string - PropFontW string - PropFontW2 string + Style string + JS string + FontRegularW string + FontRegularW2 string + FontBoldW string + FontBoldW2 string } type startTemplateVariables struct { @@ -136,29 +136,29 @@ func ListenAndServe(bind, startpagefile string, robotsfile string, robotsdebug b // // Fonts - fontdataw, err := box.Find("iosevka-term-ss03-regular.woff") + fontRegularWData, err := box.Find("iosevka-fixed-ss03-regular.woff") if err != nil { - fontdataw = []byte{} + fontRegularWData = []byte{} } - fontwAsset := fmt.Sprintf("/iosevka-term-ss03-regular-%x.woff", md5.Sum(fontdataw)) + fontRegularWAsset := fmt.Sprintf("/iosevka-fixed-ss03-regular-%x.woff", md5.Sum(fontRegularWData)) - fontdataw2, err := box.Find("iosevka-term-ss03-regular.woff2") + fontRegularW2Data, err := box.Find("iosevka-fixed-ss03-regular.woff2") if err != nil { - fontdataw2 = []byte{} + fontRegularW2Data = []byte{} } - fontw2Asset := fmt.Sprintf("/iosevka-term-ss03-regular-%x.woff2", md5.Sum(fontdataw2)) + fontRegularW2Asset := fmt.Sprintf("/iosevka-fixed-ss03-regular-%x.woff2", md5.Sum(fontRegularW2Data)) - propfontdataw, err := box.Find("iosevka-aile-regular.woff") + fontBoldWData, err := box.Find("iosevka-fixed-ss03-bold.woff") if err != nil { - propfontdataw = []byte{} + fontBoldWData = []byte{} } - propfontwAsset := fmt.Sprintf("/iosevka-aile-regular-%x.woff", md5.Sum(propfontdataw)) + fontBoldWAsset := fmt.Sprintf("/iosevka-fixed-ss03-bold-%x.woff", md5.Sum(fontBoldWData)) - propfontdataw2, err := box.Find("iosevka-aile-regular.woff2") + fontBoldW2Data, err := box.Find("iosevka-fixed-ss03-bold.woff2") if err != nil { - propfontdataw2 = []byte{} + fontBoldW2Data = []byte{} } - propfontw2Asset := fmt.Sprintf("/iosevka-aile-regular-%x.woff2", md5.Sum(propfontdataw2)) + fontBoldW2Asset := fmt.Sprintf("/iosevka-fixed-ss03-bold-%x.woff2", md5.Sum(fontBoldW2Data)) // // Stylesheet @@ -277,12 +277,12 @@ func ListenAndServe(bind, startpagefile string, robotsfile string, robotsdebug b }) assets := AssetList{ - Style: styleAsset, - JS: jsAsset, - FontW: fontwAsset, - FontW2: fontw2Asset, - PropFontW: propfontwAsset, - PropFontW2: propfontw2Asset, + Style: styleAsset, + JS: jsAsset, + FontRegularW: fontRegularWAsset, + FontRegularW2: fontRegularW2Asset, + FontBoldW: fontBoldWAsset, + FontBoldW2: fontBoldW2Asset, } http.Handle("/", gziphandler.GzipHandler(DefaultHandler(startpageTpl, startpagetext, assets))) @@ -292,10 +292,10 @@ func ListenAndServe(bind, startpagefile string, robotsfile string, robotsdebug b http.Handle("/favicon.ico", gziphandler.GzipHandler(FaviconHandler(favicondata))) http.Handle(styleAsset, gziphandler.GzipHandler(StyleHandler(styledata))) http.Handle(jsAsset, gziphandler.GzipHandler(JavaScriptHandler(jsdata))) - http.HandleFunc(fontwAsset, FontHandler(false, fontdataw)) - http.HandleFunc(fontw2Asset, FontHandler(true, fontdataw2)) - http.HandleFunc(propfontwAsset, FontHandler(false, propfontdataw)) - http.HandleFunc(propfontw2Asset, FontHandler(true, propfontdataw2)) + http.HandleFunc(fontRegularWAsset, FontHandler(false, fontRegularWData)) + http.HandleFunc(fontRegularW2Asset, FontHandler(true, fontRegularW2Data)) + http.HandleFunc(fontBoldWAsset, FontHandler(false, fontBoldWData)) + http.HandleFunc(fontBoldW2Asset, FontHandler(true, fontBoldW2Data)) //http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("assets/")))) return http.ListenAndServe(bind, nil) diff --git a/internal/port/tpl/_fonts.html b/internal/port/tpl/_fonts.html index b56aa22..a947222 100644 --- a/internal/port/tpl/_fonts.html +++ b/internal/port/tpl/_fonts.html @@ -3,14 +3,14 @@ font-family: 'Iosevka Term SS03'; font-style: normal; font-weight: normal; - src: url('{{ .Assets.FontW2 }}') format('woff2'), - url('{{ .Assets.FontW }}') format('woff'); + src: url('{{ .Assets.FontRegularW2 }}') format('woff2'), + url('{{ .Assets.FontRegularW }}') format('woff'); } @font-face { - font-family: 'Iosevka Aile'; + font-family: 'Iosevka Term SS03'; font-style: normal; - font-weight: normal; - src: url('{{ .Assets.PropFontW2 }}') format('woff2'), - url('{{ .Assets.PropFontW }}') format('woff'); + font-weight: bold; + src: url('{{ .Assets.FontBoldW2 }}') format('woff2'), + url('{{ .Assets.FontBoldW }}') format('woff'); } diff --git a/internal/port/tpl/_header.html b/internal/port/tpl/_header.html deleted file mode 100644 index 5bcd254..0000000 --- a/internal/port/tpl/_header.html +++ /dev/null @@ -1,48 +0,0 @@ -
-
- {{ .Protocol }}://:// - - {{- if .URL -}} - {{- $page := . -}} - {{- $href := printf "/%s" .Protocol -}} - {{- $uriParts := split .URL "/" -}} - - {{- $uriLast := $uriParts | last -}} - {{- $uriParts = $uriParts | pop -}} - {{- if eq $uriLast "" -}} - {{- $uriLast = $uriParts | last -}} - {{- $uriParts = $uriParts | pop -}} - {{- end -}} - - {{- range $i, $part := $uriParts -}} - {{- if and (eq $page.Protocol "gopher") (eq $i 1) -}} - {{- $href = printf "%s/1" $href -}} - {{- $part = $part | trimLeftChar -}} - {{- if not (eq $part "") -}} - {{- $href = printf "%s/%s" $href $part -}} - /{{ $part }} - {{- end -}} - {{- else -}} - {{- $href = printf "%s/%s" $href . -}} - {{- if ne $i 0 -}} - / - {{- end -}} - {{ . }} - {{- end -}} - {{- end -}} - {{- if ne (len $uriParts) 0 -}} - / - {{- end -}} - {{- if and (eq $page.Protocol "gopher") (eq (len $uriParts) 1) -}} - {{- $uriLast = $uriLast | trimLeftChar -}} - {{- end -}} - {{ $uriLast }} - {{- end -}} -
-
- {{- if and (not .Lines) (not .Error) (eq .Protocol "gopher") -}} - - {{- end -}} -
-
-
diff --git a/internal/port/tpl/_modals.html b/internal/port/tpl/_modals.html index 3c08d9a..3bbdef2 100644 --- a/internal/port/tpl/_modals.html +++ b/internal/port/tpl/_modals.html @@ -9,7 +9,7 @@
- Monospace font + Gemini: Monospace font
diff --git a/internal/port/tpl/gemini.html b/internal/port/tpl/gemini.html index 08f1b8e..df50d50 100644 --- a/internal/port/tpl/gemini.html +++ b/internal/port/tpl/gemini.html @@ -7,28 +7,50 @@ {{- template "_fonts.html" . -}} - - {{- template "_header.html" . -}} + +
+
+ gemini://:// + {{- range $i, $item := .Nav -}} + {{- if ne $i 0 -}} + / + {{- end -}} + {{- if .Current -}} + {{ .Label }} + {{- else -}} + {{ .Label }} + {{- end -}} + {{- end -}} +
+
+
+
+
-
-				{{- if .Lines -}}
-					{{- $content := "" -}}
-					{{- range .Lines -}}
-						{{- if ne $content "" -}}
-							{{- $content = printf "%s\n" $content -}}
-						{{- end -}}
-						{{- if .Link -}}
-							{{- $content = printf "%s%s" $content (printf "%s  %s" .Type .Type .Link (.Text | HTMLEscape)) -}}
-						{{- else -}}
-							{{- $content = printf "%s%s" $content (printf "     %s" (.Text | HTMLEscape)) -}}
-						{{- end -}}
-					{{- end -}}
-					{{- $content | safeHtml -}}
-				{{- else -}}
-					{{- .RawText -}}
-				{{- end -}}
-			
+
+ {{- range .Sections -}} + {{- if eq .Type "RAW_TEXT" -}} +
```
{{- .Text -}}
+ {{- else if eq .Type "REFLOW_TEXT" -}} +

{{- .Text -}}

+ {{- else if eq .Type "LINK" -}} + + {{- else if eq .Type "HEADING_1" -}} +
#

{{- .Text -}}

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

{{- .Text -}}

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

{{- .Text -}}

+ {{- else if eq .Type "LIST" -}} +
    + {{- range .Items -}} +
  • {{- . -}}
  • + {{- end -}} +
+ {{- end -}} + {{- end -}} +
{{- template "_modals.html" . -}} diff --git a/internal/port/tpl/gopher.html b/internal/port/tpl/gopher.html index c971847..5436123 100644 --- a/internal/port/tpl/gopher.html +++ b/internal/port/tpl/gopher.html @@ -31,25 +31,16 @@
-
-        {{- $content := "" -}}
+      
{{- $page := . -}} {{- range .Lines -}} - {{- if ne $content "" -}} - {{- $content = printf "%s\n" $content -}} - {{- end -}} - {{- if $page.IsPlain -}} - {{- $content = printf "%s%s" $content (.Text | HTMLEscape) -}} + {{- if .Link -}} +
{{- .Type -}}{{- .Text -}}
{{- else -}} - {{- if .Link -}} - {{- $content = printf "%s%s" $content (printf "%s %s" .Type .Type .Link (.Text | HTMLEscape)) -}} - {{- else -}} - {{- $content = printf "%s%s" $content (printf " %s" (.Text | HTMLEscape)) -}} - {{- end -}} +
{{- .Text -}}
{{- end -}} {{- end -}} - {{- $content | safeHtml -}} -
+
{{- template "_modals.html" . -}} diff --git a/js/main.ts b/js/main.ts index 2d11ea4..031e959 100644 --- a/js/main.ts +++ b/js/main.ts @@ -128,9 +128,9 @@ const settings = new KeyValueStore({ const settingMonospaceFontValueEl = settingMonospaceFontEl.getElementsByClassName('setting__value')[0]; const settingMonospaceFontCallback = (value: boolean) => { if (value) { - contentEl.classList.add("content--has-monospace-font"); + contentEl.classList.add("content--prefer-monospace"); } else { - contentEl.classList.remove("content--has-monospace-font"); + contentEl.classList.remove("content--prefer-monospace"); } settingMonospaceFontValueEl.textContent = value ? '[yes]' : '[no]'; diff --git a/pkg/libgemini/libgemini.go b/pkg/libgemini/libgemini.go index 48a8ed0..5e37490 100644 --- a/pkg/libgemini/libgemini.go +++ b/pkg/libgemini/libgemini.go @@ -53,10 +53,10 @@ var ( HeaderPattern = regexp.MustCompile("^(\\d\\d)[ \\t]+(.*)$") LinkPattern = regexp.MustCompile("^=>[ \\t]*([^ \\t]+)(?:[ \\t]+(.*))?$") ReflowModePattern = regexp.MustCompile("^```(.*)$") - Heading1Pattern = regexp.MustCompile("^#(.*)$") - Heading2Pattern = regexp.MustCompile("^##(.*)$") - Heading3Pattern = regexp.MustCompile("^###(.*)$") - ListItemPattern = regexp.MustCompile("^\\*(.*)$") + Heading1Pattern = regexp.MustCompile("^# *(.*)$") + Heading2Pattern = regexp.MustCompile("^## *(.*)$") + Heading3Pattern = regexp.MustCompile("^### *(.*)$") + ListItemPattern = regexp.MustCompile("^\\* *(.*)$") TermEscapeSGRPattern = regexp.MustCompile("\\[\\d+(;\\d+)*m") ) @@ -82,6 +82,27 @@ const ( LIST = GeminiDocSectionType(6) ) +func (it GeminiDocSectionType) String() string { + switch it { + case RAW_TEXT: + return "RAW_TEXT" + case REFLOW_TEXT: + return "REFLOW_TEXT" + case LINK: + return "LINK" + case HEADING_1: + return "HEADING_1" + case HEADING_2: + return "HEADING_2" + case HEADING_3: + return "HEADING_3" + case LIST: + return "LIST" + default: + return "???" + } +} + type GeminiDocSection struct { Type GeminiDocSectionType Text string @@ -191,20 +212,13 @@ func ParseGeminiDocument(body *bytes.Buffer) (sections []GeminiDocSection) { if !reflow { if !ignoreSection { - if section.Type != RAW_TEXT { - sections = append(sections, section) - section = GeminiDocSection{ - Type: RAW_TEXT, - } - } - } else { - ignoreSection = false - section = GeminiDocSection{ - Type: RAW_TEXT, - } + sections = append(sections, section) } - section.Text = section.Text + "\n" + line + section = GeminiDocSection{ + Type: RAW_TEXT, + Text: line, + } continue } @@ -297,20 +311,14 @@ func ParseGeminiDocument(body *bytes.Buffer) (sections []GeminiDocSection) { } if !ignoreSection { - if section.Type != REFLOW_TEXT { - sections = append(sections, section) - section = GeminiDocSection{ - Type: REFLOW_TEXT, - } - } - } else { - ignoreSection = false - section = GeminiDocSection{ - Type: REFLOW_TEXT, - } + sections = append(sections, section) } - section.Text = section.Text + "\n" + line + ignoreSection = false + section = GeminiDocSection{ + Type: REFLOW_TEXT, + Text: line, + } } if !ignoreSection { -- cgit v1.2.3-70-g09d2