Move index to template-index.html; Use router to render index

Makes it possible to render announcements more easily
This commit is contained in:
Robbie Antenesse 2019-06-06 13:17:00 -06:00 committed by Robbie Antenesse
parent 1b6247f457
commit 90464fd15c
5 changed files with 34 additions and 4 deletions

View File

@ -2,17 +2,17 @@
"name": "lexiconga-lite",
"version": "1.0.0",
"description": "A light-as-possible rewrite of Lexiconga",
"main": "index.html",
"main": "template-index.html",
"repository": "https://cybre.tech/Alamantus/lexiconga-lite.git",
"author": "Robbie Antenesse <dev@alamantus.com>",
"license": "UNLICENCED",
"scripts": {
"start": "concurrently \"npm run watch-js\" \"npm run watch-php\" \"npm run copy-files\"",
"watch-js": "parcel watch index.html offline.html template-view.html template-passwordreset.html --no-hmr --public-url ./",
"watch-js": "parcel watch template-index.html offline.html template-view.html template-passwordreset.html --no-hmr --public-url ./",
"watch-php": "cpx \"src/php/**/{*,.*}\" dist -v -w",
"copy-files": "cpx \"node_modules/upup/dist/upup.sw.min.js\" dist -v",
"bundle": "parcel build index.html offline.html template-view.html template-passwordreset.html && npm run copy-files && cpx \"src/php/**/{*,.*}\" dist",
"serve-frontend-only": "parcel index.html",
"bundle": "parcel build template-index.html offline.html template-view.html template-passwordreset.html && npm run copy-files && cpx \"src/php/**/{*,.*}\" dist",
"serve-frontend-only": "parcel template-index.html",
"clear": "npm run clear-dist && npm run clear-cache",
"clear-dist": "rimraf dist/*",
"clear-cache": "rimraf .cache/*"

View File

@ -8,6 +8,8 @@ RewriteRule ^view/([0-9]+)/?$ router.php?view=dictionary&dict=$1 [NC,L]
RewriteRule ^([0-9]+)/?$ router.php?view=dictionary&dict=$1 [NC,L] # Handle dictionary ids.
RewriteRule ^/?(index.html)?$ router.php [NC,L] # Handle dictionary ids.
#RewriteRule ^issues/?$ https://github.com/Alamantus/Lexiconga/issues [R=301,L] # Shorten issues url.
#RewriteRule ^updates/?$ https://github.com/Alamantus/Lexiconga/releases [R=301,L] # Shorten updates url.

View File

@ -0,0 +1,7 @@
[
{
"header": "Test",
"body": "<p>Test</p>",
"expire": "January 1, 2020"
}
]

View File

@ -66,4 +66,24 @@ switch ($view) {
}
break;
}
default: {
$html = file_get_contents(realpath(dirname(__FILE__) . '/./template-index.html'));
$announcements = file_get_contents(realpath(dirname(__FILE__) . '/./announcements.json'));
$announcements = json_decode($announcements, true);
$announcements_html = '';
foreach ($announcements as $announcement) {
$expire = strtotime($announcement['expire']);
if (time() < $expire) {
$announcements_html .= '<article class="announcement">
<a class="close-button" title="Close Announcement" onclick="this.parentElement.parentElement.removeChild(this.parentElement);">&times;&#xFE0E;</a>
<h4>' . $announcement['header'] . '</h4>
' . $announcement['body'] . '
</article>';
}
}
$html = str_replace('{{announcements}}', $announcements_html, $html);
return Response::html($html);
break;
}
}

View File

@ -121,6 +121,7 @@
</aside>
<section id="mainColumn">
{{announcements}}
<section id="detailsSection">
<h2 id="dictionaryName">Dictionary Name</h2>
<nav>