pupupu

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

commit
8ca92a332c4ffbd3af1a22e7ce828a1a6f660d86
parent
cfdde6592202e6c06691c11646e2afd6db79625a
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2018-12-04 10:49
validate yaml

Diffstat

M static/main.scss 7 ++++++-
M templates/page.html 3 +++
M templates/site.html 3 +++
M views.php 40 ++++++++++++++++++++++++++++++++--------

4 files changed, 44 insertions, 9 deletions


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

@@ -40,7 +40,7 @@ button {
   40    40 }
   41    41 
   42    42 .button--danger {
   43    -1 	@include button-color(red, white, darkred);
   -1    43 	@include button-color($color-invalid, white, darkred);
   44    44 }
   45    45 
   46    46 .button--small {
@@ -82,3 +82,8 @@ header {
   82    82 		margin-right: $padding;
   83    83 	}
   84    84 }
   -1    85 
   -1    86 .form-error {
   -1    87 	color: $color-invalid;
   -1    88 	font-size: 80%;
   -1    89 }

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

@@ -10,6 +10,9 @@
   10    10         <label>
   11    11             {{ 'Metadata'|trans }}
   12    12             <textarea name="yml">{{ yml }}</textarea>
   -1    13             {% if error %}
   -1    14                 <p class="form-error">{{ 'Data is invalid'|trans }}</p>
   -1    15             {% endif %}
   13    16         </label>
   14    17 
   15    18         <div class="button-row">

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

@@ -3,6 +3,9 @@
    3     3 {% block main %}
    4     4     <form method="POST">
    5     5         <textarea name="yml">{{ yml }}</textarea>
   -1     6         {% if error %}
   -1     7             <p class="form-error">{{ 'Data is invalid'|trans }}</p>
   -1     8         {% endif %}
    6     9 
    7    10         <div class="button-row">
    8    11             <div>

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

@@ -1,5 +1,9 @@
    1     1 <?php declare(strict_types=1);
    2     2 
   -1     3 require __DIR__ . '/vendor/autoload.php';
   -1     4 use Symfony\Component\Yaml\Yaml;
   -1     5 use Symfony\Component\Yaml\Exception\ParseException;
   -1     6 
    3     7 include_once('utils.php');
    4     8 
    5     9 class HttpException extends Exception {}
@@ -53,9 +57,18 @@ function siteView($pupupu, $twig)
   53    57             'yml' => $pupupu->get('/_site', 'yml'),
   54    58         ));
   55    59     } else {
   56    -1         $pupupu->put('/_site', 'yml', $_POST['yml']);
   57    -1         $pupupu->renderAll();
   58    -1         header('Location: ', true, 302);
   -1    60         try {
   -1    61             Yaml::parse($_POST['yml'], 'yml');
   -1    62             $pupupu->put('/_site', 'yml', $_POST['yml']);
   -1    63             $pupupu->renderAll();
   -1    64             header('Location: ', true, 302);
   -1    65         } catch (ParseException $e) {
   -1    66             http_response_code(400);
   -1    67             echo $twig->render('site.html', array(
   -1    68                 'yml' => $_POST['yml'],
   -1    69                 'error' => $e
   -1    70             ));
   -1    71         }
   59    72     }
   60    73 }
   61    74 
@@ -81,11 +94,22 @@ function pageView($pupupu, $twig)
   81    94             $target = pathDirname($path);
   82    95             header('Location: ?', true, 302);
   83    96         } else {
   84    -1             $pupupu->put($path, 'yml', $_POST['yml']);
   85    -1             $pupupu->put($path, 'md', $_POST['md']);
   86    -1             $pupupu->render($path);
   87    -1             $pupupu->renderDynamic();
   88    -1             header('Location: ', true, 302);
   -1    97             try {
   -1    98                 Yaml::parse($_POST['yml'], 'yml');
   -1    99                 $pupupu->put($path, 'yml', $_POST['yml']);
   -1   100                 $pupupu->put($path, 'md', $_POST['md']);
   -1   101                 $pupupu->render($path);
   -1   102                 $pupupu->renderDynamic();
   -1   103                 header('Location: ', true, 302);
   -1   104             } catch (ParseException $e) {
   -1   105                 http_response_code(400);
   -1   106                 echo $twig->render('page.html', array(
   -1   107                     'yml' => $_POST['yml'],
   -1   108                     'md' => $_POST['md'],
   -1   109                     'url' => $pupupu->getUrl($path),
   -1   110                     'error' => $e,
   -1   111                 ));
   -1   112             }
   89   113         }
   90   114     }
   91   115 }