Commit 210cd2ec authored by Administrator's avatar Administrator 💬

feat: add a new template: parallel pages

parent 29e9202a
<?php
namespace Grav\Plugin;
use Grav\Common\Grav;
use Grav\Common\Page\Page;
use Grav\Common\Page\Pages;
use Grav\Common\Plugin;
......@@ -44,9 +45,8 @@ class M3P2Plugin extends Plugin
*/
public function onPluginsInitialized()
{
// Don't proceed if we are in the admin plugin
if ($this->isAdmin()) {
return;
return; // Don't proceed if we are in the admin backend
}
$uri = $this->grav['uri'];
......@@ -60,10 +60,15 @@ class M3P2Plugin extends Plugin
]);
}
$this->enable([
'onTwigInitialized' => ['setupTwigGoodies', 0],
]);
$this->enable([
'onTwigInitialized' => ['setupWebIdeUrl', 0],
]);
// $that_page_route = $uri->query('page');
// if ($that_page_route) {
// $this->enable([
......@@ -95,10 +100,11 @@ class M3P2Plugin extends Plugin
public function onSyncPageInitialized()
{
// shell cwd is project root
$out = "";
$out = "Opening a fortune cookie…\n\n\n";
// $out .= shell_exec("fortune | cowsay -e Oø -f dragon") . "\n";
$out .= shell_exec("fortune") . "\n\n";
//$out = "Opening a fortune cookie…\n\n\n";
//$out .= shell_exec("fortune") . "\n\n";
//$out .= shell_exec("fortune | cowsay -e Oø -f dragon") . "\n";
$out .= "Trying to sync content with GitLab…\n\n\n";
$out .= shell_exec("cd user/pages && git pull --rebase --autostash origin master 2>&1") . "\n";
......@@ -108,6 +114,17 @@ class M3P2Plugin extends Plugin
die("<pre>".$out."</pre>"); // This is all I could find to write to the page.
}
public function setupTwigGoodies()
{
/** @var Pages $pages */
$pages = Grav::instance()['pages'];
$this->grav['twig']->twig()->addGlobal('localized_pages', $pages);
$this->grav['twig']->twig()->addFilter(
new \Twig_SimpleFilter('to_page', [$this, 'getPageForPath'])
);
}
public function setupWebIdeUrl()
{
$this->grav['twig']->twig()->addFilter(
......@@ -130,6 +147,46 @@ class M3P2Plugin extends Plugin
// );
// }
public function getPageForPath($meta)
{
if (is_array($meta)) {
if (isset($meta['path'])) {
$path = $meta['path'];
} else {
trigger_error("Missing `path` in: ".print_r($meta, true));
}
} elseif (is_string($meta)) {
$path = $meta;
} else {
trigger_error("Unrecognized page: ".print_r($meta, true));
}
/** @var Pages $pages */
$pages = Grav::instance()['pages'];
$page = $pages->find($path);
if ( ! $page) {
try {
$page = $pages->get($path);
} catch (\Exception $e) {}
}
if ( ! $page) {
try {
$cwd = $pages->root()->filePath(); // ends with /
if (0 === strpos($path, '/')) {
$page = $pages->get($cwd . substr($path, 1));
} else {
$page = $pages->get($cwd . $path);
}
// die($cwd . $path);
} catch (\Exception $e) {}
}
return $page;
}
public function getWebIdeUrlForPage(Page $page)
{
$url = "https://gitlab.m3p2.com/-/ide/project/m3p2/courses/edit/master/-/"; # todo: move to YAML config
......
{% extends 'partials/base.html.twig' %}
{% block stylesheets %}
{% do assets.addCss('theme://css/columns.css') %}
{{ parent() }}
{% endblock %}
{% block body %}
{# {{ localized_pages.instances | keys | join('<br>') }}#}
<div class="claude-columns">
{% for column_page_meta in page.header.pages %}
{% set column = column_page_meta | to_page %}
{% if column %}
<section id="{{ macro.pageLinkName(column.menu) }}" class="claude-column">
{{ column.content | raw }}
{% include 'partials/contributions-incentive.html.twig' with {page: column} %}
</section>
{% else %}
<p class="col-4">
Column <code>{{ column_page_meta | join(' ') }}</code> not found.
</p>
{% endif %}
{% endfor %}
</div>
{#{{ page.content|raw }}#}
{% endblock %}
{# Disable the Rosetta option of the language selector, for now. #}
{# How to access the Rosettas of the children poages? #}
{% block header_language_selection %}
{% embed 'partials/language-selector.html.twig' %}
{% block polyglot_language_selector %}{% endblock %}
{% endembed %}
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment