1#!/bin/bash 2set -eu 3 4examples_style=" 5.source { 6 display: grid; 7 grid-template-columns: 1fr 1fr; 8 grid-gap: 1rem; 9} 10.org, .html { 11 border: 1px dashed grey; 12 padding: 1em; 13 overflow-x: auto; 14} 15.sections { margin-left: 2rem; } 16.sections a { display: block; padding: 0.25em 0; } 17.sections a:hover, .sections a:focus, .sections a:active { background: rgba(200, 200, 200, 0.2); }" 18 19org_files=org/testdata/*.org 20go_org_examples=" 21<h1>Sections</h1> 22<style>$examples_style</style> 23<ul class='sections'>" 24for org_file in $org_files; do 25 name=$(basename $org_file) 26 go_org_examples+="<li><a id='toc-${name}' href='#${name}'>${name}</a>" 27done 28go_org_examples+="</ul><hr>" 29 30for org_file in $org_files; do 31 echo generating content for $org_file 32 name=$(basename $org_file) 33 go_org_examples+=" 34 <h2><a id='${name}' href='#toc-${name}'>${name}</a></h2> 35 <div class='source'> 36 <pre class='org'>$(sed 's/&/\&/g; s/</\</g; s/>/\>/g;' $org_file)</pre> 37 <div class='html'>$(./go-org render $org_file html-chroma)</div> 38 </div>" 39done 40 41convert=" 42 <h1>Convert</h1> 43 <button id='run' disabled='true' onclick='run()'> 44 RUN (initializing...) 45 </button> 46 or ctrl + return 47 <textarea id='input'>* Hello World</textarea> 48 <div id='output'></div> 49 <style> 50 #run { 51 background-color: #50CCDD; 52 border: none; 53 border-radius: 0.33em; 54 color: #FFF; 55 cursor: pointer; 56 font-weight: bold; 57 letter-spacing: 0.1em; 58 padding: 0.5em 1.5em; 59 } 60 61 #run:hover { 62 background-color: #40AACC; 63 outline: 0; 64 } 65 66 #run:disabled { 67 background-color: #AAA; 68 cursor: wait; 69 } 70 71 #input, #output { 72 display: block; 73 border: 1px dashed grey; 74 margin: 0.5em 0; 75 overflow: auto; 76 padding: 0.25em; 77 width: 100%; 78 } 79 #input { height: 30%; } 80 #output { max-height: 100%; } 81 </style> 82 <script src='wasm_exec.js'></script> 83 <script> 84 const go = new Go(); 85 WebAssembly 86 .instantiateStreaming(fetch('main.wasm'), go.importObject) 87 .then((result) => go.run(result.instance), 88 (error) => { 89 const button = document.getElementById('run'); 90 button.textContent = 'ERROR: (' + error + ')'; 91 }); 92 93 function initialized() { 94 const button = document.getElementById('run'); 95 button.textContent = 'RUN'; 96 button.removeAttribute('disabled'); 97 } 98 99 document.getElementById('input').addEventListener('keydown', function(e) { 100 if (e.keyCode == 13 && e.ctrlKey) { // ctrl+enter 101 run(); 102 e.preventDefault(); 103 } 104 }, false) 105 </script>" 106 107index="<html> 108 <head> 109 <style>$(cat etc/style.css)</style> 110 </head> 111 <body> 112 $convert 113 $go_org_examples 114 </body> 115</html>" 116 117 118convert="<html> 119 <head> 120 <style>$(cat etc/style.css)</style> 121 </head> 122 <body> 123 $convert 124 </body> 125</html>" 126 127mkdir -p docs 128go get github.com/chaseadamsio/goorgeous 129cp etc/_goorgeous.go docs/goorgeous.go 130go build -o docs/goorgeous docs/goorgeous.go 131go_org_vs_goorgeous_examples="<html> 132 <head> 133 <style> 134 $(cat etc/style.css) 135 $examples_style 136 </style> 137 </head> 138 <body>" 139for org_file in $org_files; do 140 echo generating content for $org_file 141 name=$(basename $org_file) 142 go_org_vs_goorgeous_examples+=" 143 <h2><a id='${name}' href='#toc-${name}'>${name}</a></h2> 144 <div class='source'> 145 <div class='html'>$(./docs/goorgeous $org_file)</div> 146 <div class='html'>$(./go-org render $org_file html-chroma)</div> 147 </div>" 148done 149go_org_vs_goorgeous_examples+="</body></html>" 150rm docs/goorgeous docs/goorgeous.go 151 152echo "$index" > docs/index.html 153echo "$convert" > docs/convert.html 154echo "$go_org_vs_goorgeous_examples" > docs/go-org-vs-goorgeous.html 155cp etc/_wasm.go docs/wasm.go 156GOOS=js GOARCH=wasm go build -o docs/main.wasm docs/wasm.go 157rm docs/wasm.go 158cp $(go env GOROOT)/misc/wasm/wasm_exec.js docs/wasm_exec.js 159 160mkdir -p docs/blorg 161cp -r blorg/testdata/public/* docs/blorg/ 162