| 1 |
#!/bin/bash |
| 2 |
set -eu |
| 3 |
|
| 4 |
examples_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 |
|
| 19 |
org_files=org/testdata/*.org |
| 20 |
go_org_examples=" |
| 21 |
<h1>Sections</h1> |
| 22 |
<style>$examples_style</style> |
| 23 |
<ul class='sections'>" |
| 24 |
for org_file in $org_files; do |
| 25 |
name=$(basename $org_file) |
| 26 |
go_org_examples+="<li><a id='toc-${name}' href='#${name}'>${name}</a>" |
| 27 |
done |
| 28 |
go_org_examples+="</ul><hr>" |
| 29 |
|
| 30 |
for 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>" |
| 39 |
done |
| 40 |
|
| 41 |
convert=" |
| 42 |
<h1>Blorg</h1> |
| 43 |
<a href=blorg/>example blorg output</a> |
| 44 |
<h1>Convert</h1> |
| 45 |
<button id='run' disabled='true' onclick='run()'> |
| 46 |
RUN (initializing...) |
| 47 |
</button> |
| 48 |
or ctrl + return |
| 49 |
<textarea id='input'>* Hello World</textarea> |
| 50 |
<div id='output'></div> |
| 51 |
<style> |
| 52 |
#run { |
| 53 |
background-color: #50CCDD; |
| 54 |
border: none; |
| 55 |
border-radius: 0.33em; |
| 56 |
color: #FFF; |
| 57 |
cursor: pointer; |
| 58 |
font-weight: bold; |
| 59 |
letter-spacing: 0.1em; |
| 60 |
padding: 0.5em 1.5em; |
| 61 |
} |
| 62 |
|
| 63 |
#run:hover { |
| 64 |
background-color: #40AACC; |
| 65 |
outline: 0; |
| 66 |
} |
| 67 |
|
| 68 |
#run:disabled { |
| 69 |
background-color: #AAA; |
| 70 |
cursor: wait; |
| 71 |
} |
| 72 |
|
| 73 |
#input, #output { |
| 74 |
display: block; |
| 75 |
border: 1px dashed grey; |
| 76 |
margin: 0.5em 0; |
| 77 |
overflow: auto; |
| 78 |
padding: 0.25em; |
| 79 |
width: 100%; |
| 80 |
} |
| 81 |
#input { height: 30%; } |
| 82 |
#output { max-height: 100%; } |
| 83 |
</style> |
| 84 |
<script src='wasm_exec.js'></script> |
| 85 |
<script> |
| 86 |
const go = new Go(); |
| 87 |
WebAssembly |
| 88 |
.instantiateStreaming(fetch('main.wasm'), go.importObject) |
| 89 |
.then((result) => go.run(result.instance), |
| 90 |
(error) => { |
| 91 |
const button = document.getElementById('run'); |
| 92 |
button.textContent = 'ERROR: (' + error + ')'; |
| 93 |
}); |
| 94 |
|
| 95 |
function initialized() { |
| 96 |
const button = document.getElementById('run'); |
| 97 |
button.textContent = 'RUN'; |
| 98 |
button.removeAttribute('disabled'); |
| 99 |
} |
| 100 |
|
| 101 |
document.getElementById('input').addEventListener('keydown', function(e) { |
| 102 |
if (e.keyCode == 13 && e.ctrlKey) { // ctrl+enter |
| 103 |
run(); |
| 104 |
e.preventDefault(); |
| 105 |
} |
| 106 |
}, false) |
| 107 |
</script>" |
| 108 |
|
| 109 |
index="<html> |
| 110 |
<head> |
| 111 |
<style>$(cat etc/style.css)</style> |
| 112 |
</head> |
| 113 |
<body> |
| 114 |
$convert |
| 115 |
$go_org_examples |
| 116 |
</body> |
| 117 |
</html>" |
| 118 |
|
| 119 |
|
| 120 |
convert="<html> |
| 121 |
<head> |
| 122 |
<style>$(cat etc/style.css)</style> |
| 123 |
</head> |
| 124 |
<body> |
| 125 |
$convert |
| 126 |
</body> |
| 127 |
</html>" |
| 128 |
|
| 129 |
rm -rf docs |
| 130 |
mkdir docs |
| 131 |
|
| 132 |
echo "$index" > docs/index.html |
| 133 |
echo "$convert" > docs/convert.html |
| 134 |
cp etc/_wasm.go docs/wasm.go |
| 135 |
GOOS=js GOARCH=wasm go build -o docs/main.wasm docs/wasm.go |
| 136 |
cp $(go env GOROOT)/lib/wasm/wasm_exec.js docs/wasm_exec.js |
| 137 |
|
| 138 |
mkdir -p docs/blorg |
| 139 |
cp -r blorg/testdata/public/* docs/blorg/ |