#!/bin/sh

dom="easylang.online"
test $1 && dom=$1

src=$(pwd)

o=$HOME/out/easylang/show
mkdir -p $o
rm -f $o/*

for i in *.js; do
	if test  ! -e  $o/$i -o $i -nt $o/$i; then
		echo cp -p $i $o
		cp -p $i $o
	fi
done

cd ../main/web
for i in easy.js; do
	if test $i -nt $o/$i -o ! -e $o/$i; then
		echo cp -p $i $o
		cp -p $i $o
	fi
done
cd $o/..
for i in easyw.js easyw.wasm; do
	if test $i -nt $o/$i -o ! -e $o/$i; then
		echo cp -p $i $o
		cp -p $i $o
	fi
done

# --------------------------------------------------------------


make_big() {
	cd $src/../misc/aoc$1/

	exec >$o/aoc$1.html

	cat <<xxx
<!doctype html>
<meta charset=utf-8><title>easylang.online - AoC-$1</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="../icon.png" type="image/x-png">

<h3><a href=https://adventofcode.com/20$1/>AoC 20$1</a> done with <a href=..>easylang.online</a></h3>

<i>easylang</i> does not have many features and has a simple syntax. It is statically typed and has as data types only strings and numbers (floating point), arrays of strings and numbers, and arrays of arrays. Arrays can grow. Programs compiled into an AST tree run in the browser or in the browser IDE. There are built-in features for canvas graphics.
<p>
It can be useful as a teaching and learning language due to its reduced feature set, simple syntax, browser IDE, and built-in graphics.
<p>
However, since <i>easylang</i> has no built-in functions for special things like sorting or hashmaps, you have to program them yourself, which makes the programs longer, but in a way more informative. 

<div id=tut><b>Loading ...</b></div>
<script src=easy.js></script>
<script src=easy_code.js></script>
<script src=easy_tut2.js></script>

<script>
xxx

	cat <<'xxx'
txt_split = "\n*\n"

txt_tutor=`-
*
xxx

	for i in $(seq 1 25); do
		if test -f $i.el; then
			s=$(head -1 $i.el | cut -c12-)
			echo "* $s"
			echo "*"
			echo "@ https://adventofcode.com/20$1/day/$i@AoC 20$1 - Day $i"
			echo "*"
			if test $1$i = 2019 -o $1$i = 1813 -o $1$i = 1512; then
				cat $i.el | $src/tr.py
			else
				cat $i.el | tr '\\' '\\\\'
			fi
			echo "*"
		fi
	done
	cat <<'xxx'
+ Have fun :-)
`
function hook() {
	var dom = window.location.host
	tut.insertAdjacentHTML("beforeend", `
<p><hr><p>
The examples were created with <a href=..>${dom}<a>.
<p><small>christof.kaser@gmail.com</small>
`)
}
</script>
xxx

}

make_big 15
make_big 16
make_big 17
make_big 18
make_big 19
make_big 20
make_big 21


# --------------------------------------------------------------

exec > $o/index.html

cat <<xxx
<!doctype html><title>$dom examples</title>
<meta name="description" content="aoc solutions for easylang.online - an easy programming language">
<meta charset=utf-8>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="../icon.png" type="image/x-png">

<style>
body{
  background-color:#eee;
  font:normal normal normal 16px/1.4 Arial,sans-serif;
  margin-left:16px;margin-right:16px;
  max-width:730px;
}


h2 {background-color:#bdb;padding:7px;padding-left:12px}
h3 {background-color:#bdb;padding:5px;padding-left:12px;margin-top:20px}

</style>

<h2><a href=https://adventofcode.com/>AoC</a> done with <a href=..>easylang.online</a></h2>

This simple programming language with built-in graphical functions and an easy to use and offline usable <a href="../ide/">browser IDE</a> is well suited as a teaching and learning language.  You can also use it to write graphical applications that you can embed in a web page.

<a href="../">More ...</a>

<p><small>
A language that doesn’t have everything is actually easier to program in than some that do. -- Dennis M. Ritchie
</small>

<h3>Solutions</h3>

<a href=../aoc15/>AoC 2015</a>
<p>
<a href=../aoc16/>AoC 2016</a>
<p>
<a href=../aoc17/>AoC 2017</a>
<p>
<a href=../aoc18/>AoC 2018</a>
<p>
<a href=../aoc19/>AoC 2019</a>
<p>
<a href=../aoc20/>AoC 2020</a>
<p>
<a href=../aoc21/>AoC 2021</a>
xxx


vis15="18"
vis16="8 13"
vis17="19 22"
vis18="6 10 13 15 17 18 20"
vis19="3 8 10 11 13 15 18 19 20 24"
vis20="20 24"
vis21="5 8 9 11 13 15 23 24 25"

echo "<h3>Visualizations</h3>"

f=""
for v in $vis15; do
	test $f && f="$f,"
	f="${f}aoc15/$v.el"
done
echo "<a href=../apps/show.html?f=$f>2015 Visualizations</a><p>"

f=""
for v in $vis16; do
	test $f && f="$f,"
	f="${f}aoc16/$v.el"
done
echo "<a href=../apps/show.html?f=$f>2016 Visualizations</a><p>"

f=""
for v in $vis17; do
	test $f && f="$f,"
	f="${f}aoc17/$v.el"
done
echo "<a href=../apps/show.html?f=$f>2017 Visualizations</a><p>"

f=""
for v in $vis18; do
	test $f && f="$f,"
	f="${f}aoc18/$v.el"
done
echo "<a href=../apps/show.html?f=$f>2018 Visualizations</a><p>"
f=""
for v in $vis19; do
	test $f && f="$f,"
	f="${f}aoc19/$v.el"
done
echo "<a href=../apps/show.html?f=$f>2019 Visualizations</a><p>"
f=""
for v in $vis20; do
	test $f && f="$f,"
	f="${f}aoc20/$v.el"
done
echo "<a href=../apps/show.html?f=$f>2020 Visualizations</a><p>"

f=""
for v in $vis21; do
	test $f && f="$f,"
	f="${f}aoc21/$v.el"
done
echo "<a href=../apps/show.html?f=$f>2021 Visualizations</a><p>"

cat <<xxx
<h3>A year on one big web page</h3>

All tasks of one year on one big page. The programs are editable and runnable. 

<p><a href="aoc15.html">AoC 2015 - Big page</a>
<p><a href="aoc16.html">AoC 2016 - Big page</a>
<p><a href="aoc17.html">AoC 2017 - Big page</a>
<p><a href="aoc18.html">AoC 2018 - Big page</a>
<p><a href="aoc19.html">AoC 2019 - Big page</a>
<p><a href="aoc20.html">AoC 2020 - Big page</a>
<p><a href="aoc21.html">AoC 2021 - Big page</a>
<p>
<hr>
<small><small>christof.kaser@gmail.com</small></small>
xxx



