Commit 443668f2 authored by Administrator's avatar Administrator 💬

Implement the lesson columns.

The route is `/lesson/<lesson-slug>`.
The level parameter is not yet taken into account.
The language is not yet taken into account either.
parent 96066245
......@@ -65,8 +65,14 @@ class M3P2Plugin extends Plugin
// ]);
// }
$priority = 1; // must be higher than the error plugin's
$this->enable([
'onPageNotFound' => ['perhapsDisplayPolyglotColumns', $priority],
]);
$this->enable([
'onPageNotFound' => ['perhapsDisplayPolyglotColumns', 1],
'onPageNotFound' => ['perhapsDisplayLessonColumns', $priority],
]);
// if ("" == $current_route) {
......@@ -212,4 +218,64 @@ class M3P2Plugin extends Plugin
$event->page = $page;
$event->stopPropagation();
}
public function perhapsDisplayLessonColumns(Event $event)
{
/** @var Uri $uri */
$uri = $this->grav['uri'];
// var_dump($uri); // best doc ftw
if ("lesson" != $uri->paths(0)) {
return; // perhaps not
}
/** @var Pages $pages */
$pages = $this->grav['pages'];
if (count($uri->paths()) < 2) {
// user is toying with URI, probably
// idea: display an index of the lessons here todo
return;
}
$lesson_slug = $uri->paths(1);
// var_dump($lesson_slug);
// $target_pages = $pages->all()->filter(function ($p) use ($lesson_slug) {
$target_pages = array_filter($pages->instances(), function (Page $p) use ($lesson_slug) {
$h = $p->header();
if ( ! isset($h->pedagogic_paths) || empty($h->pedagogic_paths)) {
return false;
}
foreach ($h->pedagogic_paths as $lesson) {
if ($lesson_slug == $lesson['slug']) {
return true; // yay, this page is part of the lesson
}
}
return false;
});
// var_dump($target_pages);
// fixme: sort pages
// $target_page = $pages->all();
if (empty($target_pages)) {
return;
}
$this->grav['twig']->twig()->addGlobal('target_pages', $target_pages);
$page = new Page;
$page->init(new \SplFileInfo(__DIR__ . '/pages/lesson-columns.md'));
// here: perhaps add a title and other metadata
$event->page = $page;
$event->stopPropagation();
}
}
{% extends 'partials/base.html.twig' %}
{# `page` is irrelevant here #}
{# use `target_pages`, injected by m3-p2 plugin #}
{% block stylesheets %}
{% do assets.addCss('theme://css/columns.css') %}
{{ parent() }}
{% endblock %}
{#{% block javascripts %}#}
{#{% do assets.addJs('theme://js/syncscroll.js', {group:'bottom'}) %}#}
{#{{ parent() }}#}
{#{% endblock %}#}
{% block body %}
<div class="claude-columns">
{% for column in target_pages %}
<section id="{{ column.slug }}" class="claude-column" name="language">
{{ column.content | raw }}
{% include 'partials/contributions-incentive.html.twig' with {page: column} %}
</section>
{% endfor %}
</div>
{% endblock %}
{# Disable the language selector. #}
{#{% block header_language_selection %}{% endblock %}#}
{# … disabling the whole section instead is semantically correct but it offsets the navigation. TBD #}
{#{% block header_language_selection_section %}{% 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