Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new /meta/notes route which lists pages with a note #49

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/template/dist/app.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/template/dist/app.css.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions public/template/src/scss/components/_nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@

}

&--metaroot {
margin-top: 1.5rem;
padding-top: 1.5rem;
border-top: 2px solid #ddd;
}

&--level1 > a {
font-size: rem(16);
font-weight: 700;
Expand Down
3 changes: 3 additions & 0 deletions src/DocsApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace MODXDocs;

use MODXDocs\Containers\DB;
use MODXDocs\Views\Meta\Notes;
use MODXDocs\Views\Search;
use Slim\App;
use Slim\Http\Request;
Expand Down Expand Up @@ -32,6 +33,8 @@ public function __construct(array $settings)
private function routes()
{
$this->app->get('/', Doc::class . ':get')->setName('home');
$this->app->get('/{version}/meta', Notes::class . ':get')->setName('meta');
$this->app->get('/{version}/meta/notes', Notes::class . ':get')->setName('meta/notes');
$this->app->get('/{version}/{language}/search', Search::class . ':get')->setName('search');
$this->app->get('/{version}/{language}/{path:.*}', Doc::class . ':get')->setName('documentation');
}
Expand Down
72 changes: 72 additions & 0 deletions src/Views/Meta/Notes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace MODXDocs\Views\Meta;

use MODXDocs\Navigation\Tree;
use MODXDocs\Model\PageRequest;
use MODXDocs\Services\SearchService;
use MODXDocs\Services\VersionsService;
use MODXDocs\Views\Base;
use Psr\Container\ContainerInterface;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Router;

class Notes extends Base
{
/** @var Router */
private $router;
/** @var VersionsService */
private $versionsService;

public function __construct(ContainerInterface $container)
{
parent::__construct($container);
$this->router = $this->container->get('router');
$this->versionsService = $this->container->get(VersionsService::class);
}

/**
* @param Request $request
* @param Response $response
* @return \Psr\Http\Message\ResponseInterface
* @throws \Exception
*/
public function get(Request $request, Response $response)
{
$pageRequest = PageRequest::fromRequest($request);

$crumbs = [];
$crumbs[] = [
'title' => 'Meta', // @todo i18n
'href' => $this->router->pathFor('meta', ['version' => $pageRequest->getVersion()])
];
$crumbs[] = [
'title' => 'Notes',
'href' => $this->router->pathFor('meta/notes', ['version' => $pageRequest->getVersion()])
];

$tree = Tree::get($pageRequest->getVersion(), $pageRequest->getLanguage());

$notes = [];
$items = $tree->getAllItems();
foreach ($items as $item) {
if (array_key_exists('note', $item)) {
$notes[] = $item;
}
elseif (array_key_exists('suggest_delete', $item)) {
$notes[] = $item;
}
}

$title = 'Notes';
return $this->render($request, $response, 'meta/notes.twig', [
'page_title' => $title,
'crumbs' => $crumbs,
'items' => $notes,
'canonical_url' => '',
'versions' => $this->versionsService->getVersions($pageRequest),
'nav' => $tree->renderTree($this->view),
]);
}
}
14 changes: 14 additions & 0 deletions templates/layout.twig
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@
{# {{ icon('close', 'Close', 'o-closemenu__icon', null, 'aria-hidden="true"') }} #}
</a>
{{ nav|raw }}

{% include "partials/nav.twig" with {
children: [{
title: 'Meta',
classes: 'c-nav__item c-nav__item--metaroot c-nav__item--has-children',
uri: path_for('meta', {version: 'current'}),
level: 1,
children: [{
title: "Notes",
level: 2,
uri: path_for('meta/notes', {version: 'current'})
}]
}]
} %}
</nav>
{% endif %}

Expand Down
80 changes: 80 additions & 0 deletions templates/meta/notes.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{% extends "layout.twig" %}

{% block title %}{{ page_title }}{% endblock %}

{% block content %}
<main id="main" class="l-main">
<div class="l-main__title">
{% if crumbs|length > 1 %}
<nav class="c-breadcrumb" aria-label="Breadcrumb">
<ol class="c-breadcrumb__list" itemscope itemtype="https://schema.org/BreadcrumbList">
{% for crumb in crumbs %}
<li class="c-breadcrumb__item" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
<a class="c-breadcrumb__link" href="{{ crumb.href }}" itemtype="https://schema.org/Thing" itemprop="item">
<span itemprop="name">{{ crumb.title }}</span>
<meta itemprop="position" content="{{ loop.index }}">
</a>
</li>
{% endfor %}
{# current item gets special markup: #}
<li class="c-breadcrumb__item u-show-for-sr" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
{# aria-current for current visible page and --current modifier class #}
<a class="c-breadcrumb__link c-breadcrumb__link--current" href="{{ current_uri }}" aria-current="page" itemtype="https://schema.org/Thing" itemprop="item">
<span itemprop="name">{{ title }}</span>
<meta itemprop="position" content="{{ crumbs|length + 1 }}">
</a>
</li>
</ol>
</nav>
{% endif %}

<h1 class="u-no-margin--top">{{ page_title }}</h1>

<p class="o-docmeta">
<small>
<em>
{% if versions %}
Other versions:
{% for version in versions %}
<a href="{{ version.uri }}">{{ version.title }}</a>
{% endfor %}
{% endif %}
</em>
</small>
</p>
</div>

<div class="l-main__contentwrapper">


<div class="l-main__content">
<p>This page lists documentation pages with a <code>note</code> or <code>suggest_delete</code> meta item. These are typically pages that may need to be rewritten or contain incorrect information.</p>

<p>Also see the <a href="https://github.com/modxorg/Docs/issues">issue tracker on GitHub</a>.</p>

<table>
<thead>
<th>Document</th>
<th>Note</th>
</thead>
<tbody>
{% for item in items %}
<tr>
<td>
<a href="{{ item.uri }}" target="_blank">{{ item.title }}</a>
</td>
<td {% if item.suggest_delete %}style="background: #ffc6e0"{% endif %}>
{{ item.suggest_delete }}
{{ item.note }}
</td>
</tr>
{% else %}
<tr><td colspan="2">No pages found with a note.</td></tr>
{% endfor %}
</tbody>
</table>
</div>
</div>

</main>
{% endblock %}