- commit
- 9a1bd6b4e3f1b16deada62943e17e825f62741db
- parent
- b4a1efd92932cd8909e259a7f87648e91677950c
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2018-10-12 17:31
allow to edit site config
Diffstat
| M | index.php | 20 | ++++++++++++-------- |
| R | templates/form.html -> templates/page.html | 0 | |
| R | templates/form.html -> templates/site.html | 18 | +----------------- |
3 files changed, 13 insertions, 25 deletions
diff --git a/index.php b/index.php
@@ -54,11 +54,6 @@ function getSubpages($path) 54 54 return $subpages; 55 55 } 56 5657 -1 function getSite()58 -1 {59 -1 return Yaml::parseFile("../_site/site.yml");60 -1 }61 -162 57 function validatePath($path) 63 58 { 64 59 if ( @@ -89,7 +84,7 @@ function render($path, $verbose=false) 89 84 $template = $data['yml']['template'] ?? 'base.html'; 90 85 $html = $twig->render($template, array( 91 86 'page' => Yaml::parse($data['yml']),92 -1 'site' => getSite(),-1 87 'site' => Yaml::parseFile("../_site/site.yml"), 93 88 'body' => $parsedown->text($data['md']), 94 89 'date' => time(), 95 90 )); @@ -118,12 +113,22 @@ if (isset($_SERVER['REQUEST_METHOD'])) { 118 113 119 114 if (empty($_GET['path'])) { 120 115 header("Location: ?path=/", true, 302); -1 116 } elseif ($_GET['path'] === '_site') { -1 117 if ($_SERVER['REQUEST_METHOD'] == 'GET') { -1 118 echo $twig->render('site.html', array( -1 119 'yml' => file_get_contents("../_site/site.yml"), -1 120 )); -1 121 } else { -1 122 file_put_contents("../_site/site.yml", $_POST['yml']); -1 123 renderAll(); -1 124 header("Location: ", true, 302); -1 125 } 121 126 } else { 122 127 $path = validatePath($_GET['path']); 123 128 124 129 if ($_SERVER['REQUEST_METHOD'] == 'GET') { 125 130 $data = getData($path);126 -1 echo $twig->render('form.html', array(-1 131 echo $twig->render('page.html', array( 127 132 'data' => $data, 128 133 'subpages' => getSubpages($path), 129 134 'path' => $path, @@ -140,7 +145,6 @@ if (isset($_SERVER['REQUEST_METHOD'])) { 140 145 // TODO validate form 141 146 setData($path, $_POST); 142 147 render($path);143 -1144 148 header("Location: ", true, 302); 145 149 } 146 150 }
diff --git a/templates/form.html b/templates/page.html
diff --git a/templates/form.html b/templates/site.html
@@ -3,26 +3,10 @@ 3 3 {% block content %} 4 4 <form method="POST"> 5 5 <label>6 -1 Body7 -1 <textarea name="md">{{ data.md }}</textarea>8 -1 </label>9 -110 -1 <label>11 6 Metadata12 -1 <textarea name="yml">{{ data.yml }}</textarea>-1 7 <textarea name="yml">{{ yml }}</textarea> 13 8 </label> 14 9 15 10 <input type="submit" value="Save">16 -1 <input type="submit" class="button--danger" name="delete" value="Löschen">17 11 </form>18 -119 -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>26 -127 -1 <a href="{{ path }}/" class="button">View</a>28 12 {% endblock %}