<h1 class="my-3">Sideload Encyclopedia</h1>

<div class="my-3 p-3 border bg-light">
<p>This will side-load a MediaWiki-style OpenZim data set.  Place a zim file in the uploads directory.
    For Wikipedia, the zim file can be downloaded from <a href="https://download.kiwix.org/zim/wikipedia/">https://download.kiwix.org/zim/wikipedia/</a>.
    The en_all_nopic sets are recommended for wikipedia, since they are smaller and do not contain images
    (which are not used anyway).   For testing, the _mini or _en_100 sets are good choices.
   <p></p>
   The zim file will be converted to a sqlite database (.db-file) with a similar name to
   the zim file, which then automatically is turned into processed data.
   <p></p>
   Since the first stage of processing is very time-consuming, the sqlite database can
   also be loaded from this form.
</p>
</div>
<form method="post" action="actions/sideload-encyclopedia" onsubmit="return confirm('Confirm sideloading')">
    <div class="my-3 py-3">

        <table class="table">
            <th></th><th>Filename</th><th>Size</th><th>Last Modified</th>
            {{#each uploadDirContents.items}}
                <tr>
                    <td><input {{#unless isZim}}disabled{{/unless}} class="form-check-input" type="radio" name="source" id="{{name}}" value="{{name}}"></td>
                    <td {{#unless isZim}}class="text-muted"{{/unless}}>
                        <label class="form-check-label" for="{{name}}">{{name}}{{#if directory}}/{{/if}}</label>
                    </td>
                    <td>{{#unless directory}}{{size}}{{/unless}}</td>
                    <td title={{lastModifiedTime}}>{{shortTimestamp lastModifiedTime}}</td>
                </tr>
            {{/each}}
            {{#unless uploadDirContents.items}}
                <tr>
                    <td colspan="3">Nothing found in upload directory</td>
                </tr>
            {{/unless}}
        </table>

        <p>
            <small class="text-muted">
                The upload directory is typically mounted to /uploads on the server.  The external
                directory is typically something like index-{{node.id}}/uploads.
            </small>
        </p>

        <label for="baseUrl" class="form-label">Base URL</label>
        <div class="col mb-3">
            <input id="baseUrl" name="baseUrl" class="form-control" value="https://en.wikipedia.org/wiki/">
        </div>

        <small class="text-muted">
            The base URL is used to construct the URL for each article.  The base URL is prepended to the article path,
            and the result is used as the URL for the article.  The default value will point to English Wikipedia.
        </small>

        <div class="row mt-3">
            <div class="col">
                <button {{#unless uploadDirContents.items}}disabled{{/unless}} type="submit" class="btn btn-primary">Sideload Encyclopedia</button>
            </div>
        </div>
    </div>
</form>