#!/bin/bash

version=$1
date=$2
windows_version=$3
windows_date=$4

cat << __EOF__
__HTML5__
        <title>Anonymine - guess free minesweeper</title>
        <meta name="description" content="Anonymine is a text based
minesweeper that can be won without any guessing, and has a few other
features, including hexagonal and von Neumann fields."/>

        <style>
            #screenshots p
            {
                margin-bottom: 2em;
            }
            #platforms dt
            {
                font-size: 105%;
            }
            #platforms dd
            {
                font-size: 95%;
                margin-bottom: 0.167em;
            }
            .dl-
            {
                padding-left: .5em;
            }
            .download
            {
                vertical-align: middle;
                font-size: 110%;
            }
            .download::before
            {
                vertical-align: middle;
                font-size: 250%;
                content: '⭳';
                padding-right: .25em;
            }
        </style>
    </head>
    <body>
        __NAVIGATION__
        <main><div id="content">
            <h1 id="title">Anonymine - guess free minesweeper</h1>
            <p class="notprint" style="max-width: 100%;">
            <!-- If I make these images link back, it will cause
            accessiblity issues on mobile devices. -->
            <img src="imgs4/banner1.png" alt="" width="420" height="280"/>
            <img src="imgs4/banner2.png" alt="" width="420" height="280"/>
            </p>
            <div id="top">
                <p>Latest version: ${version} released on ${date}
                   - <a href="#news">what's new</a></p>
                <ul>
                    <li><a href="#about">About</a></li>
                    <li>
                        <a href="#download">Download</a>
                        <small>
                            <span class="dl-">(<a href="#dl-unix">Linux &amp; Unix,</a></span>
                            <a href="#dl-unix" class="dl-">macOS,</a>
                            <a href="#dl-windows" class="dl-">Windows,</a>
                            <a href="#dl-unix" class="dl-">Haiku OS</a>)
                        </small>
                    </li>
                    <li><a href="#screenshots">Screenshots</a></li>
                    <li><a href="#platforms">Platforms</a></li>
                    <li><a href="#news">What's new?</a></li>
                </ul>
                <p>
                    You can try it on my demo server using SSH.
                    Log in as play@anonymine-demo.oskog97.com,
                    password is "play".<br/>
                    <a href="http://anonymine-demo.oskog97.com/" class="printurl"
                    >Leaderboard for public demo server</a>
                </p>
            </div>

            <section><div class="section" id="about">
            <h2>About</h2>
            <p class="notprint"><small><a href="#top">To top of the page</a></small></p>
            <p>
                Anonymine is the "anonymous minesweeper" as I never had any
                name for it, but I think "Anonymine" works just fine.
                Back in December 2015 I was curious about creating an algorithm
                for solving minesweeper, and then I needed an excuse for it
                so I turned it into a terminal game that can be solved wihout any
                guessing.
            </p>
            <p>
                Do note that it runs in the terminal, so it may not be your cup of
                tea.  Mouse input is usually supported, but only really useful in
                hexagonal mode.
            </p>
            <p>
                Being solvable without guessing is not its only feature,
                it has many other unusual or even unique features:
                the games are fully customizable and Anonymine seems to be the
                only minesweeper with <span class="a"><a
                href="https://en.wikipedia.org/wiki/Von_Neumann_neighborhood"
                >von Neumann grids</a>.</span>
                <!-- No printurl, it's just Wikipedia. -->
            </p>
            <p>
                For each game you can set the field type (normal / hexagonal
                / von Neumann), width, height and number of mines, only
                restricted to certain minimums and security limits (to avoid
                igniting your computer).
            </p>
            <div class="atom">
            <h3>The supported field types/game types are:</h3>
            <div class="atom">
            <!-- FIXME: This should be a dl with dt and dd. -->
            <h4>Von Neumann grids</h4>
                <p>
                    I have never seen another
                    minesweeper that can have fields with von Neumann
                    grids.  In a von Neumann neighbourhood (grid),
                    each cell/square has only four neighbours, at the edges
                    but not at the corners.
                </p>
                <p>
                    The biggest number you'll ever see is 3. But that doesn't
                    mean it's easy, it's quite the opposite.
                </p>
            </div>
            <div class="atom">
            <h4>Traditional fields with Moore grids</h4>
                <p>Like any other minsweeper.</p>
            </div>
            <div class="atom">
            <h4>Hexagonal fields</h4>
                <p>
                    Every cell is a hexagon and has six
                    neighbours, (with obvious exceptions).
                    This mode has separate key bindings because there is no
                    single "up" and single "down" direction.
                </p>
            </div>
            </div>
            <div class="atom">
            <h3>More features:</h3>
            <ul>
                <li>
                    It looks almost fine on monochrome terminals.
                </li>
                <li>
                    Even the losers can get on their very own highscores table.
                </li>
                <li>
                    There are cheat codes. They're not useful, but will be a
                    challenge to crack.
                </li>
            </ul>
            </div>
            </div></section>



            <section><div class="section" id="download">
            <h2>Download</h2>
            <p class="notprint"><small><a href="#top">To top of the page</a></small></p>
            <p><strong>NOTE</strong>:  Not for smartphones and tablets.</p>
            <p class="notprint bold">
                <a href="#dl-unix">Linux, macOS, unix-likes, Haiku</a>,
                <a href="#dl-windows">Windows</a>,
            </p>
            <p><a href="__SITE__/archive/anonymine/?C=M&amp;O=A"
                  class="printurl">Archive of all released versions</a></p>
            <p>
                If you find any bugs, please <span class="a"><a
                     class="printurl"
                    href="https://gitlab.com/oskog97/anonymine/issues"
                >create an issue</a>.</span>
            </p>

            <div class="atom">
            <h3 id="dl-unix">GNU/Linux, macOS, *BSD, Cygwin, other unix-like
                             operating systems, and Haiku</h3>
            <ul>
                <li><a href="__SITE__/archive/anonymine/anonymine-${version}.tar.xz"
                    class="printurl download">xz compressed tarball of version ${version} from ${date}</a></li>
                <li><a class="printurl"
                    href="https://gitlab.com/oskog97/anonymine/">GitLab</a></li>
                <li><a href="#release-notes">Release notes</a></li>
            </ul>
            </div>

            <div class="atom">
            <h3 id="dl-windows">Windows</h3>
            <p>There are a few options:</p>
            <ol>
                <li><strong>Recommended:</strong> WSL (both 1 and 2 work just fine)</li>
                <li>Automatic Cygwin and Anonymine installer</li>
                <li>Install Python and windows-curses</li>
            </ol>
            <p><a href="https://gitlab.com/oskog97/anonymine/-/wikis/Windows"
                >Comparison of options</a></p>
            <h4>Automatic Cygwin installer</h4>
            Downloads:
            <ul>
                <li><a href="__SITE__/archive/anonymine/windows/Anonymine-Windows-${windows_version}.zip"
                    class="printurl download">Windows installer from ${windows_date}
                    (version $(echo "$windows_version" | cut -d- -f1-3)
                    with Cygwin setup $(echo "$windows_version" | cut -d- -f5))
                </a></li>
                <li><a href="https://gitlab.com/oskog97/anonymine-windows"
                    class="printurl">Fetch newest version from GitLab
                </a></li>
            </ul>
            <h4>Install Python and windows-curses</h4>
            It is possible to run the unix version with some limitations.
            <ul>
                <li><a class="printurl"
href="https://gitlab.com/oskog97/anonymine/blob/master/doc/INSTALL.Windows.txt">
                    Instructions</a>
                    </li>
                <li>You can download as a zip from <span class="a"><a
href="https://gitlab.com/oskog97/anonymine/-/archive/master/anonymine-master.zip"
                    class="printurl">Gitlab</a>.</span></li>
            </ul>
            </div>
            </div></section>




            <section><div class="section" id="screenshots">
            <h2>Screenshots</h2>
            <p class="notprint"><small><a href="#top">To top of the page</a></small></p>
            <p>
                <img width="484" height="316" alt="" src="imgs4/last-cells.png"/>
                <br/><span class="caption">
                    The von Neumann field: The biggest number you'll ever see
                    is 3.  This mode makes Anonymine a unique minesweeper.
                    (Attention mode has been enabled to find the last few
                    cells.)
                </span>
            </p>
            <p>
                <img width="484" height="316" alt="" src="imgs4/traditional.png"/>
                <br/><span class="caption">
                    Traditional (Moore) field, nothing special
                </span>
            </p>
            <p>
                <img width="484" height="316" alt="" src="imgs4/hexagonal.png"/>
                <br/><span class="caption">
                    Hexagonal field
                </span>
            </p>
            <p>
                <img width="484" height="316" alt="" src="imgs4/losers.png"/>
                <br/><span class="caption">
                    The losers' highscores
                </span>
            </p>
            </div></section>



            <section><div class="section" id="platforms">
            <h2>Platforms</h2>
            <p class="notprint"><small><a href="#top">To top of the page</a></small></p>
            <p>
                Check the <a class="printurl"
href="https://gitlab.com/oskog97/anonymine/-/blob/master/README.md#blob-content-holder"
                >readme</a> and <a class="printurl"
href="https://gitlab.com/oskog97/anonymine/blob/master/doc/INSTALL.txt"
                >installation instructions</a> for more details.
            </p>
            <div class="atom">
            <h3>Tested on</h3>
            <p>
                Here's a list of various platforms Anonymine has been tested
                on.  It works on all of them unless I say otherwise, but there
                may be some minor issues.
            </p>
            <ul>
                <li>Various GNU/Linux distributions</li>
                <li>FreeBSD, OpenBSD, NetBSD, DragonflyBSD</li>
                <li>Haiku</li>
                <li>SerenityOS</li>
                <li>macOS</li>
                <li>OpenIndiana and Solaris</li>
                <li>Debian GNU/Hurd</li>
                <li>Cygwin (on Windows and ReactOS)</li>
                <li>Windows and ReactOS (without Cygwin)</li>
            </ul>
            Python interpreters:
            <ul>
                <li>CPython</li>
                <li>PyPy (lacks <code>curses</code> on Windows)</li>
            </ul>
            </div>

            <div class="atom">
            <h4>"Some coercion required"</h4>
            <p>
                Using <span class="a"><a href="http://gitlab.com/oskog97/poop"
                class="printurl">Pööp</a>,</span> Anonymine can be made to work
                on even more platforms.
                <span class="bold">"Do not try this at home"</span>
            </p>
            <dl>
                <dt>GraalVM Python</dt>
                <dd>Needs only <code>curses</code></dd>

                <dt>PyPy on Windows</dt>
                <dd>Needs only <code>curses</code>,
                    but the Windows console is really slow</dd>

                <dt>Jython</dt>
                <dd>Needs <code>curses</code> and <code>multiprocessing</code></dd>

                <dt>IronPython</dt>
                <dd>Needs very different configuration files and
                    <code>curses</code> and <code>multiprocessing</code></dd>

                <dt>Minix 3.4</dt>
                <dd>Needs <code>multiprocessing</code> and <code>threading</code></dd>
            </dl>
            </div>
            </div></section>


__EOF__

echo;echo;echo

write_news ()
{
    news=~oskar/projects/anonymine/doc/NEWS
    changelog=~oskar/projects/anonymine/ChangeLog
    release_notes=~oskar/projects/anonymine/doc/RELEASE-NOTES
    _get_snippet ()
    {
        _internal ()
        {
            file=$1
            regex=$2
            tailcut=$3
            count=$4
            lim=$5
            n=1
            while [ "$(head -n$n $file | grep -E "$regex" | wc -l)" -le $count ]; do
                n=$(($n + 1))
            done
            n=$(($n - $tailcut))
            if [ "$n" -lt $(($lim + 1)) ]; then
                head -n$n $file
            else
                head -n$lim $file
                echo '...'
            fi
        }
        _internal "$1" "$2" "$3" "$4" "$5" \
            | sed -e 's/[&]/\&amp;/g' \
            | sed -e 's/[<]/\&lt;/g' \
            | sed -e 's/[>]/\&gt;/g'
    }
    get_news ()
    {
        _get_snippet $news '====' 3 1 30
    }
    get_changelog ()
    {
        _get_snippet $changelog '^    [0-9]+\.[0-9]+\.[0-9]+$' 3 1 7
    }
    get_release_notes ()
    {
        _get_snippet $release_notes '^[0-9]+\.[0-9]+\.[0-9]+' 2 4 30
        # 2 3 15 -> 2 4 25 -> 2 4 30
    }
    cat <<__EOF__
            <section><div class="section" id="news">
                <h2>What's new?</h2>
                <p class="notprint"><small><a href="#top">To top of the page</a></small></p>
                <dl>
                <dt id="release-notes">Release notes</dt>
                <dd>
                <pre>$(get_release_notes)</pre>
                <p><a class="printurl"
        href="https://gitlab.com/oskog97/anonymine/blob/master/doc/RELEASE-NOTES"
                >See the rest of the file on Gitlab</a></p>
                </dd>
                <dt>Bigger changes</dt>
                <dd>
                <pre>$(get_news)</pre>
                <p><a class="printurl"
        href="https://gitlab.com/oskog97/anonymine/blob/master/doc/NEWS"
                >See the rest of NEWS on Gitlab</a></p>
                </dd>
                <dt>Low level changes</dt>
                <dd>
                <p><a class="printurl"
        href="https://gitlab.com/oskog97/anonymine/blob/master/ChangeLog"
                >See ChangeLog on Gitlab</a></p>
                </dd>
                </dl>
            </div></section>
__EOF__
}

write_news

echo;echo;echo

cat <<__EOF__


        </div></main>
        __FOOTER__
    </body>
</html>

__EOF__