pupupu

simple static CMS for crappy servers
git clone https://git.ce9e.org/pupupu.git

commit
de853b0114fe5bc66d5504d4608c8bdad2d1ccfe
parent
190d09a930064ef401956abfc0dddf77819cddf2
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2018-10-12 18:30
use datalist for subpages

Diffstat

M index.php 10 ++++++----
M static/main.scss 5 +++++
M templates/page.html 24 ++++++++++++------------

3 files changed, 23 insertions, 16 deletions


diff --git a/index.php b/index.php

@@ -62,7 +62,7 @@ function getSubpages($path)
   62    62     $subpages = array();
   63    63     foreach (scandir($p) as $name) {
   64    64         if ($name !== '.' && $name !== '..' && is_dir("$p/$name")) {
   65    -1             $subpages[$name] = $path === '/' ? "/$name" : "$path/$name";
   -1    65             $subpages[] = $name;
   66    66         }
   67    67     }
   68    68     return $subpages;
@@ -123,7 +123,9 @@ if (isset($_SERVER['REQUEST_METHOD'])) {
  123   123     $twig = new Twig_Environment($loader);
  124   124 
  125   125     if (empty($_GET['path']) && $_GET['path'] !== '') {
  126    -1         header("Location: ?path=", true, 302);
   -1   126         header('Location: ?path=', true, 302);
   -1   127     } elseif (isset($_GET['add'])) {
   -1   128         header("Location: ?path=${_GET['path']}/${_GET['add']}", true, 302);
  127   129     } elseif ($_GET['path'] === '_site') {
  128   130         if ($_SERVER['REQUEST_METHOD'] == 'GET') {
  129   131             echo $twig->render('site.html', array(
@@ -152,12 +154,12 @@ if (isset($_SERVER['REQUEST_METHOD'])) {
  152   154             }
  153   155             rrmdir("../_content$path");
  154   156             rrmdir("..$path");
  155    -1             header("Location: ?path=", true, 302);
   -1   157             header('Location: ?path=', true, 302);
  156   158         } else {
  157   159             // TODO validate form
  158   160             setData($path, $_POST);
  159   161             render($path);
  160    -1             header("Location: ", true, 302);
   -1   162             header('Location: ', true, 302);
  161   163         }
  162   164     }
  163   165 } else {

diff --git a/static/main.scss b/static/main.scss

@@ -23,6 +23,11 @@ header {
   23    23 	margin-bottom: 2 * $spacer;
   24    24 	padding: ($padding / 2) 0;
   25    25 	display: flex;
   -1    26 	flex-flow: row wrap;
   26    27 	justify-content: space-between;
   27    28 	align-items: center;
   28    29 }
   -1    30 
   -1    31 header form {
   -1    32 	display: inline;
   -1    33 }

diff --git a/templates/page.html b/templates/page.html

@@ -6,10 +6,20 @@
    6     6             {% for name, path in breadcrumbs %}
    7     7                 <a href="?path={{ path }}">{{ name }}</a> /
    8     8             {% endfor %}
   -1     9 
   -1    10             <form>
   -1    11                 <input type="hidden" name="path" value="{{ path }}">
   -1    12                 <input type="text" name="add" list="subpages" autocomplete="off">
   -1    13                 <datalist id="subpages">
   -1    14                     {% for name in subpages %}
   -1    15                         <option value="{{ name }}">
   -1    16                     {% endfor %}
   -1    17                 </datalist>
   -1    18             </form>
    9    19         </nav>
   10    20         <nav>
   11    21             <a href="?path=_site">site config</a>
   12    -1             <a href="{{ path }}/" class="button">View</a>
   -1    22             <a href="{{ path }}/" target="_blank" class="button">View</a>
   13    23         </nav>
   14    24     </header>
   15    25 
@@ -26,17 +36,7 @@
   26    36             </label>
   27    37 
   28    38             <input type="submit" value="Save">
   29    -1             <input type="submit" class="button--danger" name="delete" value="Löschen">
   -1    39             <input type="submit" class="button--danger" name="delete" value="Delete">
   30    40         </form>
   31    41     </main>
   32    -1 
   33    -1     <aside>
   34    -1         <nav aria-label="Subpages">
   35    -1             <ul>
   36    -1                 {% for name, _path in subpages %}
   37    -1                     <li><a href="?path={{ _path }}">{{ name }}</a></li>
   38    -1                 {% endfor %}
   39    -1             </ul>
   40    -1         </nav>
   41    -1     </aside>
   42    42 {% endblock %}