feat: reworked the template structure
This commit is contained in:
parent
c607d57221
commit
c9808f90f8
24 changed files with 216 additions and 80 deletions
|
@ -6,8 +6,6 @@ class Post implements ArrayAccess {
|
||||||
private $content_html;
|
private $content_html;
|
||||||
private $content_markdown;
|
private $content_markdown;
|
||||||
|
|
||||||
private $site_defaults;
|
|
||||||
|
|
||||||
public $data;
|
public $data;
|
||||||
|
|
||||||
public $html_data;
|
public $html_data;
|
||||||
|
@ -66,14 +64,12 @@ class Post implements ArrayAccess {
|
||||||
|
|
||||||
$this->content_html = null;
|
$this->content_html = null;
|
||||||
$this->content_markdown = null;
|
$this->content_markdown = null;
|
||||||
|
|
||||||
$this->site_defaults = $site_defaults;
|
|
||||||
|
|
||||||
if(!isset($post_data) or !isset($post_data['id'])) {
|
if(!isset($post_data) or !isset($post_data['id'])) {
|
||||||
$post_data = $this->_generate_404($post_data);
|
$post_data = $this->_generate_404($post_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $post_data;
|
$data = array_merge($site_defaults, $post_data);
|
||||||
|
|
||||||
if($data['path'] == '') {
|
if($data['path'] == '') {
|
||||||
$data['path'] = '/';
|
$data['path'] = '/';
|
||||||
|
@ -127,11 +123,7 @@ class Post implements ArrayAccess {
|
||||||
return $this->data[$name];
|
return $this->data[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_null($this->site_defaults)) {
|
return null;
|
||||||
throw new RuntimeException("Post site defaults have not been set properly!");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->site_defaults[$name] ?? null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function offsetGet($offset) : mixed {
|
public function offsetGet($offset) : mixed {
|
||||||
|
@ -141,9 +133,6 @@ class Post implements ArrayAccess {
|
||||||
if(isset($this->data[$offset])) {
|
if(isset($this->data[$offset])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(isset($this->site_defaults[$offset])) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return !is_null($this->offsetGet($offset));
|
return !is_null($this->offsetGet($offset));
|
||||||
}
|
}
|
||||||
|
@ -179,7 +168,7 @@ class Post implements ArrayAccess {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function to_array($options = []) {
|
public function to_array($options = []) {
|
||||||
$out_data = array_merge($this->site_defaults, $this->data);
|
$out_data = $this->data;
|
||||||
|
|
||||||
if(isset($options['markdown'])) {
|
if(isset($options['markdown'])) {
|
||||||
$out_data['markdown'] = $this->get_markdown();
|
$out_data['markdown'] = $this->get_markdown();
|
||||||
|
|
|
@ -61,6 +61,8 @@ $db_connection->execute_query("DELETE FROM posts;");
|
||||||
$sql_adapter = new MySQLHandler($db_connection, $SERVER_HOST);
|
$sql_adapter = new MySQLHandler($db_connection, $SERVER_HOST);
|
||||||
$adapter = new PostHandler($sql_adapter);
|
$adapter = new PostHandler($sql_adapter);
|
||||||
|
|
||||||
|
$adapter->site_defaults = [];
|
||||||
|
|
||||||
$sql_adapter->debugging = true;
|
$sql_adapter->debugging = true;
|
||||||
|
|
||||||
function test_accounce($title) {
|
function test_accounce($title) {
|
||||||
|
@ -127,15 +129,23 @@ test_accounce("Setting post markdown...");
|
||||||
$sql_adapter->set_postdata([
|
$sql_adapter->set_postdata([
|
||||||
'path' => '/testing/markdowntest',
|
'path' => '/testing/markdowntest',
|
||||||
'markdown' => 'Inline markdown test should work...',
|
'markdown' => 'Inline markdown test should work...',
|
||||||
'title' => "A Markdown Test"
|
'title' => "A Markdown Test",
|
||||||
|
'brief' => "The dragons explore markdown, sort of properly... Maybe.",
|
||||||
|
'tags' => ['one', 'two', 'three', 'sexee']
|
||||||
]);
|
]);
|
||||||
$post = $sql_adapter->get_postdata('/testing/markdowntest');
|
$post = $sql_adapter->get_postdata('/testing/markdowntest');
|
||||||
var_dump($sql_adapter->get_post_markdown($post['id']));
|
var_dump($sql_adapter->get_post_markdown($post['id']));
|
||||||
|
|
||||||
$sql_adapter->set_post_markdown($post['id'],
|
$sql_adapter->set_post_markdown($post['id'],
|
||||||
'
|
'
|
||||||
This is one hell of a cute test!
|
|
||||||
|
This is one hell of a cute test!
|
||||||
|
|
||||||
> Just checking in...
|
> Just checking in...
|
||||||
|
|
||||||
|
{{
|
||||||
|
template: fragments/blog/card.html
|
||||||
|
}}
|
||||||
'
|
'
|
||||||
);
|
);
|
||||||
var_dump($sql_adapter->get_post_markdown($post['id']));
|
var_dump($sql_adapter->get_post_markdown($post['id']));
|
||||||
|
|
|
@ -1,22 +1,97 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Symfony\Component\Yaml\Yaml;
|
||||||
use Highlight\Highlighter;
|
use Highlight\Highlighter;
|
||||||
|
|
||||||
class Dergdown extends ParsedownExtra
|
class Dergdown extends ParsedownExtra
|
||||||
{
|
{
|
||||||
protected $highlighter;
|
protected $highlighter;
|
||||||
|
|
||||||
|
protected $dergInsertRenderer;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->highlighter = new Highlighter();
|
$this->highlighter = null;
|
||||||
|
$this->BlockTypes['{'] []= 'DergInsert';
|
||||||
|
|
||||||
|
$this->dergInsertRenderer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDergRenderer($dergRenderer) {
|
||||||
|
$this->dergInsertRenderer = $dergRenderer;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function blockDergInsert($Line, $currentBlock) {
|
||||||
|
if (preg_match('/^{{\s?(.*)$/', $Line['body'], $match)) {
|
||||||
|
return array(
|
||||||
|
'text' => $match[1] ?? ''
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function blockDergInsertContinue($Line, $Block) {
|
||||||
|
if(isset($Block['complete'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(preg_match('/(.*)}}/', $Line['body'], $match)) {
|
||||||
|
$Block['text'] .= "\n" . $match[1];
|
||||||
|
$Block['complete'] = true;
|
||||||
|
return $Block;
|
||||||
|
}
|
||||||
|
|
||||||
|
$Block['text'] .= "\n" . $Line['body'];
|
||||||
|
|
||||||
|
return $Block;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function blockDergInsertComplete($Block) {
|
||||||
|
try {
|
||||||
|
$parsed_data = Yaml::parse($Block['text']);
|
||||||
|
}
|
||||||
|
catch (Exception $ex) {
|
||||||
|
return array(
|
||||||
|
'markup' => '
|
||||||
|
<div class="derg-insert-error">
|
||||||
|
<h3> Error in a dergen template! </h3>
|
||||||
|
YAML could not be parsed properly: <br>
|
||||||
|
<code>
|
||||||
|
' . $ex->getMessage() . '</code> </div>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(!isset($this->dergInsertRenderer)) {
|
||||||
|
throw new Exception("No Dergen Renderer was set!");
|
||||||
|
}
|
||||||
|
|
||||||
|
$render_output = $this->dergInsertRenderer->dergRender($parsed_data);
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
return array(
|
||||||
|
'markup' => '
|
||||||
|
<div class="derg-insert-error">
|
||||||
|
<h3> Error in a dergen template! </h3>
|
||||||
|
Rendering engine threw an error: <br>
|
||||||
|
<code>
|
||||||
|
' . $ex->getMessage() . '</code> </div>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'markup' => $render_output
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function blockFencedCodeComplete($block)
|
protected function blockFencedCodeComplete($block)
|
||||||
{
|
{
|
||||||
if (! isset($block['element']['text']['attributes'])) {
|
if (! isset($block['element']['text']['attributes'])) {
|
||||||
return $block;
|
return $block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!isset($this->highlighter)) {
|
||||||
|
$this->highlighter = new Highlighter();
|
||||||
|
}
|
||||||
|
|
||||||
$code = $block['element']['text']['text'];
|
$code = $block['element']['text']['text'];
|
||||||
$languageClass = $block['element']['text']['attributes']['class'];
|
$languageClass = $block['element']['text']['attributes']['class'];
|
||||||
$language = explode('-', $languageClass);
|
$language = explode('-', $languageClass);
|
||||||
|
|
|
@ -21,6 +21,8 @@ if(isset($REQUEST_QUERY['page'])) {
|
||||||
$ajax_args['fa'] = $FONT_AWESOME_ARRAY;
|
$ajax_args['fa'] = $FONT_AWESOME_ARRAY;
|
||||||
$ajax_args['page'] ??= $SITE_CONFIG['site_defaults'];
|
$ajax_args['page'] ??= $SITE_CONFIG['site_defaults'];
|
||||||
|
|
||||||
echo $twig->render('/ajax/' . $AJAX_REQUEST_TEMPLATE, $ajax_args);
|
$ajax_args['post'] ??= $ajax_args['page'];
|
||||||
|
|
||||||
|
echo $twig->render($AJAX_REQUEST_TEMPLATE, $ajax_args);
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -29,14 +29,27 @@ $sql_adapter = new MySQLHandler($db_connection, $SERVER_HOST);
|
||||||
$adapter = new PostHandler($sql_adapter);
|
$adapter = new PostHandler($sql_adapter);
|
||||||
|
|
||||||
require_once 'dergdown.php';
|
require_once 'dergdown.php';
|
||||||
|
require_once 'setup/derg_insert.php';
|
||||||
|
|
||||||
function dergdown_to_html($text) {
|
function dergdown_to_html($post) {
|
||||||
|
$DergInsert = new DergInsertRenderer($post);
|
||||||
$Parsedown = new Dergdown();
|
$Parsedown = new Dergdown();
|
||||||
|
$Parsedown->setDergRenderer($DergInsert);
|
||||||
|
|
||||||
return $Parsedown->text($text);
|
$markdown = $post->markdown;
|
||||||
|
|
||||||
|
if($markdown == '') {
|
||||||
|
$markdown = '
|
||||||
|
{{
|
||||||
|
template: fragments/directory/inline.html
|
||||||
|
}}
|
||||||
|
';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $Parsedown->text($markdown);
|
||||||
}
|
}
|
||||||
function post_to_html($post) {
|
function post_to_html($post) {
|
||||||
return dergdown_to_html($post->markdown);
|
return dergdown_to_html($post);
|
||||||
}
|
}
|
||||||
$adapter->markdown_engine = "post_to_html";
|
$adapter->markdown_engine = "post_to_html";
|
||||||
|
|
||||||
|
|
43
www/src/setup/derg_insert.php
Normal file
43
www/src/setup/derg_insert.php
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class DergInsertRenderer {
|
||||||
|
protected $twig;
|
||||||
|
protected $post;
|
||||||
|
protected $postAdapter;
|
||||||
|
|
||||||
|
public function __construct($post) {
|
||||||
|
global $twig;
|
||||||
|
global $adapter;
|
||||||
|
|
||||||
|
$this->twig = $twig;
|
||||||
|
$this->post = $post;
|
||||||
|
$this->postAdapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dergRender($renderConfig) {
|
||||||
|
global $FONT_AWESOME_ARRAY;
|
||||||
|
|
||||||
|
if(!isset($renderConfig['template'])) {
|
||||||
|
throw new Exception("No template type given!");
|
||||||
|
}
|
||||||
|
|
||||||
|
$template = $renderConfig['template'];
|
||||||
|
|
||||||
|
$args = [
|
||||||
|
'post' => $this->post,
|
||||||
|
'page' => $this->post,
|
||||||
|
'fa' => $FONT_AWESOME_ARRAY
|
||||||
|
];
|
||||||
|
|
||||||
|
if(isset($renderConfig['post'])) {
|
||||||
|
$args['post'] = $this->postAdapter->get_post($renderConfig['post']);
|
||||||
|
}
|
||||||
|
if(isset($renderConfig['page'])) {
|
||||||
|
$args['page'] = $this->postAdapter->get_post($renderConfig['page']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->twig->render($template, $args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
const BANNER_TIME = 600 * 1000.0
|
const BANNER_TIME = 600 * 1000.0
|
||||||
const BANNER_ANIMATION = "opacity 0.8s linear, transform 0.1s linear"
|
// const BANNER_ANIMATION = "opacity 0.8s linear, transform 0.1s linear"
|
||||||
|
const BANNER_ANIMATION = "opacity 0.8s linear"
|
||||||
|
|
||||||
|
|
||||||
class BannerHandler {
|
class BannerHandler {
|
||||||
constructor(banner_container, banner_image, banner_link) {
|
constructor(banner_container, banner_image, banner_link) {
|
||||||
|
@ -32,7 +34,7 @@ class BannerHandler {
|
||||||
|
|
||||||
console.log("Starting tick")
|
console.log("Starting tick")
|
||||||
|
|
||||||
this.bannerUpdateTimer = setInterval(() => { this.updateTick() }, 100);
|
this.bannerUpdateTimer = setInterval(() => { this.updateTick() }, 1000);
|
||||||
}
|
}
|
||||||
stopUpdateTick() {
|
stopUpdateTick() {
|
||||||
if(this.bannerUpdateTimer === null) {
|
if(this.bannerUpdateTimer === null) {
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
|
|
||||||
{% for post in page.child_posts %}
|
|
||||||
{{ include('ajax/compact_filelist/entry.html') }}
|
|
||||||
{% endfor %}
|
|
|
@ -1,5 +1,4 @@
|
||||||
|
|
||||||
|
|
||||||
<a href="{{post.url}}">
|
<a href="{{post.url}}">
|
||||||
<div class="article_blop">
|
<div class="article_blop">
|
||||||
<div class="article_blop_bg" style="background-image:url({{post.preview_image}});"></div>
|
<div class="article_blop_bg" style="background-image:url({{post.preview_image}});"></div>
|
||||||
|
@ -16,7 +15,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<span class="article_blop_excerpt">
|
<span class="article_blop_excerpt">
|
||||||
{{post.excerpt}}
|
{{ post.brief }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
0
www/templates/fragments/blog/listing.html
Normal file
0
www/templates/fragments/blog/listing.html
Normal file
10
www/templates/fragments/decoration/blog_header.html
Normal file
10
www/templates/fragments/decoration/blog_header.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h1>
|
||||||
|
{{ post.title }}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
{% if post.authors %}
|
||||||
|
Written by {{ post.authors }}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
|
@ -61,7 +61,7 @@
|
||||||
<a href={{page.parent.path}}>..</a>
|
<a href={{page.parent.path}}>..</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
{{ include('ajax/compact_filelist/listing.html') }}
|
{{ include('fragments/directory/compact/listing.html') }}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
|
@ -6,7 +6,7 @@
|
||||||
<input type="checkbox" id="folder-open-{{folder_key}}" name="folder-open-{{folder_key}}">
|
<input type="checkbox" id="folder-open-{{folder_key}}" name="folder-open-{{folder_key}}">
|
||||||
<label for="folder-open-{{folder_key}}"
|
<label for="folder-open-{{folder_key}}"
|
||||||
hx-trigger="click once queue:last, mouseenter once queue:all, intersect once queue:all"
|
hx-trigger="click once queue:last, mouseenter once queue:all, intersect once queue:all"
|
||||||
hx-get="/ajax/compact_filelist/listing.html?page={{ post.path }}"
|
hx-get="/ajax/fragments/directory/compact/listing.html?page={{ post.path }}"
|
||||||
hx-target="next ul">
|
hx-target="next ul">
|
||||||
|
|
||||||
{{ fa['folder'] | raw }}
|
{{ fa['folder'] | raw }}
|
4
www/templates/fragments/directory/compact/listing.html
Normal file
4
www/templates/fragments/directory/compact/listing.html
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
{% for post in page.child_posts %}
|
||||||
|
{{ include('fragments/directory/compact/entry.html') }}
|
||||||
|
{% endfor %}
|
39
www/templates/fragments/directory/inline.html
Normal file
39
www/templates/fragments/directory/inline.html
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<h3>Directory contents for {{page.basename}}:</h3>
|
||||||
|
<table class="directory">
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
<th class="hsmol_hide">Name</th>
|
||||||
|
<th>Title</th>
|
||||||
|
<th class="entry_update_time hsmol_hide">Modified</th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr class="entry">
|
||||||
|
<td>
|
||||||
|
{{ fa['turn-up'] | raw }}
|
||||||
|
</td>
|
||||||
|
<td class="hsmol_hide">
|
||||||
|
<a href={{page.parent.path}}> .. </a>
|
||||||
|
</td>
|
||||||
|
<td class="entry_title">
|
||||||
|
<a href={{page.parent.path}}> .. </a>
|
||||||
|
</td>
|
||||||
|
<td class="entry_update_time hsmol_hide">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% for post in page.child_posts %}
|
||||||
|
<tr class="entry">
|
||||||
|
<td>
|
||||||
|
{{ fa[post.icon] | raw }}
|
||||||
|
</td>
|
||||||
|
<td class="hsmol_hide">
|
||||||
|
<a href={{post.path}}>{{post.basename}}</a>
|
||||||
|
</td>
|
||||||
|
<td class="entry_title">
|
||||||
|
<a href={{post.path}}>{{ post.title }}</a>
|
||||||
|
</td>
|
||||||
|
<td class="entry_update_time hsmol_hide">
|
||||||
|
{{ post.updated_at }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
|
@ -1,28 +0,0 @@
|
||||||
|
|
||||||
{% extends "root.html" %}
|
|
||||||
|
|
||||||
{% block extra_head %}
|
|
||||||
<link rel="stylesheet" href="/static/gallerystyle.css">
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block second_title %}
|
|
||||||
<h2> Gallery </h2>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{%block main_content%}
|
|
||||||
<figure>
|
|
||||||
|
|
||||||
<a href="{{ image_url }}" target="_blank">
|
|
||||||
<img id="gallery_image" src="{{ image_url }}"> </img>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<article>
|
|
||||||
<figcaption id="gallery_title"> {{ image_title }} </figcaption>
|
|
||||||
<span> {{ image_desc }} </span>
|
|
||||||
<br>
|
|
||||||
<a href="{{ artist_src_link }}"> Artist: {{ artist_name }} </a>
|
|
||||||
<br>
|
|
||||||
<a href="{{ image_src_link }}"> Source link </a>
|
|
||||||
</article>
|
|
||||||
</figure>
|
|
||||||
{%endblock%}
|
|
|
@ -1,18 +0,0 @@
|
||||||
|
|
||||||
{% extends "root.html" %}
|
|
||||||
|
|
||||||
{% block extra_head %}
|
|
||||||
<link rel="stylesheet" href="/static/gallerystyle.css">
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block second_title %}
|
|
||||||
<h2> Gallery </h2>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{%block main_content%}
|
|
||||||
<div id="gallery_root_grid">
|
|
||||||
{% for key,value in array_path %}
|
|
||||||
<div class=""
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{%endblock%}
|
|
|
@ -9,7 +9,7 @@
|
||||||
{%endblock %}
|
{%endblock %}
|
||||||
|
|
||||||
{%block content_article%}
|
{%block content_article%}
|
||||||
{% if page.title %}
|
{% if page.title and (page.title != page.basename) %}
|
||||||
<h1 class="content-title"> {{ page.title }} </h1>
|
<h1 class="content-title"> {{ page.title }} </h1>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
{%block main_content%}
|
{%block main_content%}
|
||||||
|
|
||||||
{{ include('fragments/filepath_bar.html') }}
|
{{ include('fragments/decoration/navbar.html') }}
|
||||||
|
|
||||||
<article id="content_article">
|
<article id="content_article">
|
||||||
{%block content_article %}
|
{%block content_article %}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue