pupupu

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

commit
190d09a930064ef401956abfc0dddf77819cddf2
parent
2b72173c390538f9f47c79938c51f8e5688a6799
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2018-10-12 18:09
foo

Diffstat

M index.php 36 +++++++++++++++++++++++++-----------
M static/main.scss 9 +++++++++
M templates/page.html 54 ++++++++++++++++++++++++++++++++++--------------------
M templates/site.html 25 ++++++++++++++++++-------

4 files changed, 86 insertions, 38 deletions


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

@@ -18,6 +18,20 @@ function rrmdir($path)
   18    18     rmdir($path);
   19    19 }
   20    20 
   -1    21 function validatePath($path)
   -1    22 {
   -1    23     if (
   -1    24         (strlen($path) > 1 && $path[0] !== '/') ||
   -1    25         substr($path, -1) === '/' ||
   -1    26         strpos($path, '.') !== false
   -1    27     ) {
   -1    28         http_response_code(400);
   -1    29         die();
   -1    30     } else {
   -1    31         return $path;
   -1    32     }
   -1    33 }
   -1    34 
   21    35 function getData($path, $raise=false)
   22    36 {
   23    37     $data = array(
@@ -54,24 +68,23 @@ function getSubpages($path)
   54    68     return $subpages;
   55    69 }
   56    70 
   57    -1 function validatePath($path)
   -1    71 function getBreadcrumbs($path)
   58    72 {
   59    -1     if (
   60    -1         (strlen($path) > 1 && $path[0] !== '/') ||
   61    -1         substr($path, -1) === '/' ||
   62    -1         strpos($path, '.') !== false
   63    -1     ) {
   64    -1         http_response_code(400);
   65    -1         die();
   66    -1     } else {
   67    -1         return $path;
   -1    73     $breadcrumbs = array('home' => '');
   -1    74     $parts = explode('/', $path);
   -1    75     for ($i = 1; $i < count($parts); $i++) {
   -1    76         $name = $parts[$i];
   -1    77         $path = implode('/', array_slice($parts, 0, $i + 1));
   -1    78         $breadcrumbs[$name] = $path;
   68    79     }
   -1    80     return $breadcrumbs;
   69    81 }
   70    82 
   71    83 function render($path, $verbose=false)
   72    84 {
   73    85     $parsedown = new Parsedown();
   74    -1     $parsedown->setSafeMode(true);
   -1    86     // $parsedown->setMarkupEscaped(true);
   -1    87     // $parsedown->setSafeMode(true);
   75    88     $loader = new Twig_Loader_Filesystem('../_templates');
   76    89     $twig = new Twig_Environment($loader);
   77    90 
@@ -130,6 +143,7 @@ if (isset($_SERVER['REQUEST_METHOD'])) {
  130   143                 'data' => $data,
  131   144                 'subpages' => getSubpages($path),
  132   145                 'path' => $path,
   -1   146                 'breadcrumbs' => getBreadcrumbs($path),
  133   147             ));
  134   148         } elseif ($_POST['delete']) {
  135   149             if ($path === '') {

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

@@ -17,3 +17,12 @@ textarea {
   17    17 textarea {
   18    18 	max-height: 60vh;
   19    19 }
   -1    20 
   -1    21 header {
   -1    22 	border-bottom: 1px solid $color-border;
   -1    23 	margin-bottom: 2 * $spacer;
   -1    24 	padding: ($padding / 2) 0;
   -1    25 	display: flex;
   -1    26 	justify-content: space-between;
   -1    27 	align-items: center;
   -1    28 }

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

@@ -1,28 +1,42 @@
    1     1 {% extends 'base.html' %}
    2     2 
    3     3 {% block content %}
    4    -1     <form method="POST">
    5    -1         <label>
    6    -1             Body
    7    -1             <textarea name="md">{{ data.md }}</textarea>
    8    -1         </label>
   -1     4     <header>
   -1     5         <nav aria-label="Breadcrumbs">
   -1     6             {% for name, path in breadcrumbs %}
   -1     7                 <a href="?path={{ path }}">{{ name }}</a> /
   -1     8             {% endfor %}
   -1     9         </nav>
   -1    10         <nav>
   -1    11             <a href="?path=_site">site config</a>
   -1    12             <a href="{{ path }}/" class="button">View</a>
   -1    13         </nav>
   -1    14     </header>
    9    15 
   10    -1         <label>
   11    -1             Metadata
   12    -1             <textarea name="yml">{{ data.yml }}</textarea>
   13    -1         </label>
   -1    16     <main>
   -1    17         <form method="POST">
   -1    18             <label>
   -1    19                 Body
   -1    20                 <textarea name="md">{{ data.md }}</textarea>
   -1    21             </label>
   14    22 
   15    -1         <input type="submit" value="Save">
   16    -1         <input type="submit" class="button--danger" name="delete" value="Löschen">
   17    -1     </form>
   -1    23             <label>
   -1    24                 Metadata
   -1    25                 <textarea name="yml">{{ data.yml }}</textarea>
   -1    26             </label>
   18    27 
   19    -1     <nav aria-label="Subpages">
   20    -1         <ul>
   21    -1             {% for name, _path in subpages %}
   22    -1                 <li><a href="?path={{ _path }}">{{ name }}</a></li>
   23    -1             {% endfor %}
   24    -1         </ul>
   25    -1     </nav>
   -1    28             <input type="submit" value="Save">
   -1    29             <input type="submit" class="button--danger" name="delete" value="Löschen">
   -1    30         </form>
   -1    31     </main>
   26    32 
   27    -1     <a href="{{ path }}/" class="button">View</a>
   -1    33     <aside>
   -1    34         <nav aria-label="Subpages">
   -1    35             <ul>
   -1    36                 {% for name, _path in subpages %}
   -1    37                     <li><a href="?path={{ _path }}">{{ name }}</a></li>
   -1    38                 {% endfor %}
   -1    39             </ul>
   -1    40         </nav>
   -1    41     </aside>
   28    42 {% endblock %}

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

@@ -1,12 +1,23 @@
    1     1 {% extends 'base.html' %}
    2     2 
    3     3 {% block content %}
    4    -1     <form method="POST">
    5    -1         <label>
    6    -1             Metadata
    7    -1             <textarea name="yml">{{ yml }}</textarea>
    8    -1         </label>
   -1     4     <header>
   -1     5         <nav aria-label="Breadcrumbs">
   -1     6             <a href="?path=">home</a> /
   -1     7         </nav>
   -1     8         <nav>
   -1     9             <a href="?path=_site">site config</a>
   -1    10         </nav>
   -1    11     </header>
    9    12 
   10    -1         <input type="submit" value="Save">
   11    -1     </form>
   -1    13     <main>
   -1    14         <form method="POST">
   -1    15             <label>
   -1    16                 Metadata
   -1    17                 <textarea name="yml">{{ yml }}</textarea>
   -1    18             </label>
   -1    19 
   -1    20             <input type="submit" value="Save">
   -1    21         </form>
   -1    22     </main>
   12    23 {% endblock %}