Skip to content

Commit

Permalink
Fix search-pages, internals
Browse files Browse the repository at this point in the history
  • Loading branch information
OleVik committed Mar 11, 2021
1 parent 611e9f8 commit 3bbf06a
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 43 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# v3.0.0-beta.2
## 12-03-2021

1. [](#new)
* `render`-variables for `templates/partials/header.html.twig` and `components/docs/partials/docs/toolbar/menu.html.twig`
2. [](#improved)
* Search-template
* Expect metadata in `user://data/persist/index.js`
* Expect full data in `user://data/persist/static/index.full.js`
3. [](#bugfix)
* API-alignment to use `Grav\Common\Page\Interfaces\PageInterface`
* ClassNames-getter
* Patch Router Page-instance

# v3.0.0-beta.1
## 08-03-2021

Expand All @@ -8,7 +22,7 @@
* Dependencies strictness
2. [](#bugfix)
* Relocate search-results for correct keyboard-navigation
* Forcibly cast Linked Dataas strings
* Forcibly cast Linked Data as strings
* Fall back to `en` for Linked Data
* Search-mechanisms
* Remove redundant `aria-checked`-attribute
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ A demonstration is available at [OleVik.me/staging/grav-skeleton-scholar](https:

### Version 3.0.0 and higher

This major-version update targets compatibility with Grav Core 1.7, but also updates some internals.
This major-version update targets compatibility with Grav Core 1.7, and also updates and changes some internals.

### Grav Package Manager

Expand All @@ -64,7 +64,7 @@ You should now have all the theme files under

/your/site/grav/user/themes/scholar

This theme started as a clone of Paul Hibbitt's [Learn2 with Git Sync](https://github.com/hibbitts-design/grav-theme-learn2-git-sync)-theme, which is a customized version of the [Learn2](https://github.com/getgrav/grav-theme-learn2)-theme. As this theme decouples and supercedes much of the logic in either, it is rebranded as Scholar.
This theme started as a clone of Paul Hibbitt's [Learn2 with Git Sync](https://github.com/hibbitts-design/grav-theme-learn2-git-sync)-theme, which is a customized version of the [Learn2](https://github.com/getgrav/grav-theme-learn2)-theme. As this theme decouples and supercedes most of the logic in either, it is rebranded as Scholar. It also goes much further in what a documentation-theme can be and do.

## [Advanced Usage](https://github.com/OleVik/grav-theme-scholar/blob/master/ADVANCED.md)

Expand All @@ -75,4 +75,4 @@ This theme started as a clone of Paul Hibbitt's [Learn2 with Git Sync](https://g
## TODO

- [ ] Evaluate metadata text-wrapping
- [ ] Extension: Filter content with FlexSearch
- [ ] Search: Replace with engine-agnostic approach, decoupling into a plugin
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Scholar
version: 3.0.0-beta.1
version: 3.0.0-beta.2
testing: true
slug: scholar
type: theme
Expand Down
11 changes: 6 additions & 5 deletions classes/Content/Content.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Scholar Theme, Content
*
Expand All @@ -11,11 +12,11 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link https://github.com/OleVik/grav-plugin-scholar
*/

namespace Grav\Theme\Scholar\Content;

use Grav\Common\Grav;
use Grav\Common\Inflector;
use Grav\Common\Page\Page;
use Grav\Common\Page\Media;
use Grav\Theme\Scholar\Content\ContentInterface;

Expand Down Expand Up @@ -106,8 +107,8 @@ public static function pageNavigation(string $content, bool $itemize = false): o
$fragment = $doc->createDocumentFragment();
$fragment->appendXML(
'<a name="' . $id . '"><' . $element->nodeName
. '>' . $element->textContent
. '</' . $element->nodeName . '></a>'
. '>' . $element->textContent
. '</' . $element->nodeName . '></a>'
);
$element->parentNode->replaceChild($fragment, $element);
} else {
Expand Down Expand Up @@ -193,7 +194,7 @@ public static function wrapHTML(string $content, string $wrapperTag, array $targ
$node = $doc->getElementsByTagName('body')[0];
return self::getInnerHTML($node, false);
}

/**
* Extract headings from HTML
*
Expand All @@ -214,7 +215,7 @@ public static function buildList($data): string
$href = $data[$title]['href'];
$level = $data[$title]['level'];
$nextLevel = $data[next($keys)]['level'] ?? null;

if ($nextLevel > $level) {
$output .= '<li><a href="#' . $href . '">' . $title . '</a><ol>';
} else {
Expand Down
2 changes: 1 addition & 1 deletion classes/LinkedData/AbstractLinkedData.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use Grav\Common\Grav;
use Grav\Common\Utils;
use Grav\Common\Page\Page;
use Grav\Common\Page\Interfaces\PageInterface as Page;
use Spatie\SchemaOrg\Schema;
use Grav\Theme\Scholar\Utilities;
use Grav\Theme\Scholar\LinkedData\LinkedDataInterface;
Expand Down
2 changes: 1 addition & 1 deletion classes/LinkedData/CVLinkedData.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace Grav\Theme\Scholar\LinkedData;

use Grav\Common\Inflector;
use Grav\Common\Page\Page;
use Grav\Common\Page\Interfaces\PageInterface as Page;
use Grav\Common\Language\Language;

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/LinkedData/LinkedDataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Grav\Theme\Scholar\LinkedData;

use Grav\Common\Page\Page;
use Grav\Common\Page\Interfaces\PageInterface as Page;

/**
* Linked Data Interface
Expand Down
2 changes: 1 addition & 1 deletion classes/LinkedData/PageLinkedData.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace Grav\Theme\Scholar\LinkedData;

use Grav\Theme\Scholar;
use Grav\Common\Page\Page;
use Grav\Common\Page\Interfaces\PageInterface as Page;
use Grav\Common\Language\Language;
use Grav\Common\Config\Config;

Expand Down
12 changes: 7 additions & 5 deletions classes/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function __construct(Grav $Grav)
$this->printRoute = $this->grav['config']->get('theme.routes.print')
?? $this->grav['config']->get('themes.scholar.routes.print')
?? '/print';

$path = $this->grav['uri']->path();
if (\in_array(
'/' . basename($path),
Expand All @@ -65,11 +64,14 @@ public function __construct(Grav $Grav)
]
)) {
$page = $this->dispatch($path);
$page->parent(
$this->grav['pages']->find(
str_replace('/' . basename($path), '', $path)
)
$parent = $this->grav['pages']->find(
str_replace('/' . basename($path), '', $path)
);
if ($parent == null) {
$parent = $this->grav['pages']->find('/');
$parent->template('default');
}
$page->parent($parent);
} else {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion classes/Router/RouterInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Scholar Theme, Router Interface
*
Expand All @@ -15,7 +16,7 @@
namespace Grav\Theme\Scholar\Router;

use Grav\Common\Grav;
use Grav\Common\Page\Page;
use Grav\Common\Page\Interfaces\PageInterface as Page;
use Grav\Common\Page\Collection;

/**
Expand Down
6 changes: 3 additions & 3 deletions components/docs/partials/docs/toolbar/menu.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<nav class="menu" role="navigation">

{% block mobile %}
{% if config.theme.toolbar.navigation %}
{% if renderMobile ?? config.theme.toolbar.navigation %}
<div mobile-menu-open role="button" tabindex="0" data-target="aside.sidebar" aria-label="{{ "THEME_SCHOLAR.GENERIC.OPEN"|t|capitalize }} {{ "THEME_SCHOLAR.MENU"|t }}">
{# Icon8 LineAwesome v1.3.0 Bars #}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" aria-hidden="true"><path d="M 4 7 L 4 9 L 28 9 L 28 7 L 4 7 z M 4 15 L 4 17 L 28 17 L 28 15 L 4 15 z M 4 23 L 4 25 L 28 25 L 28 23 L 4 23 z"/></svg>
Expand All @@ -15,7 +15,7 @@
page.topParent.header.search,
'user://data/persist/index.js'
]) %}
{% if config.theme.toolbar.search and searchFile %}
{% if renderSearch ?? config.theme.toolbar.search and searchFile %}
<form class="search" role="search">
<input id="query" maxlength="100" type="search" name="search" tabindex="0" aria-label="{{ "THEME_SCHOLAR.SEARCH.LABEL"|t }}" placeholder="{{ "THEME_SCHOLAR.SEARCH.PLACEHOLDER"|t }}" aria-label="{{ "THEME_SCHOLAR.SEARCH.TITLE"|t }}" aria-current="false" />
<label class="search-button" for="query" role="button" aria-label="{{ "THEME_SCHOLAR.SEARCH.LABEL"|t }}">
Expand All @@ -27,7 +27,7 @@
{% endblock %}

{% block edit %}
{% if config.plugins['git-sync'].enabled and config.plugins['git-sync'].repository is not empty %}
{% if renderEdit ?? config.plugins['git-sync'].enabled and config.plugins['git-sync'].repository is not empty %}
{% include 'partials/docs/toolbar/git.sync.link.html.twig' %}
{% endif %}
{% endblock %}
Expand Down
1 change: 0 additions & 1 deletion pages/search.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
title: Advanced Search
search: 'user://data/persist/learn.full.js'
---
7 changes: 5 additions & 2 deletions scholar.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ public function onPagesInitialized()
),
$this->grav
);
new $Router($this->grav);
}
}

Expand Down Expand Up @@ -507,9 +508,11 @@ public static function getInstance(string $class, ...$args)
*/
public static function getClassNames(string $key)
{
$classes = \HaydenPierce\ClassFinder\ClassFinder::getClassesInNamespace(
'Grav\Theme',
\HaydenPierce\ClassFinder\ClassFinder::RECURSIVE_MODE
);
$language = Grav::instance()['language'];
$regex = '/Grav\\\\Theme\\\\Scholar\\\\(?<api>.*)/i';
$classes = preg_grep($regex, get_declared_classes());
$matches = preg_grep('/' . $key . '/i', $classes);
$options = [
'' => $language->translate(['THEME_SCHOLAR.GENERIC.NONE'])
Expand Down
6 changes: 3 additions & 3 deletions templates/partials/components/search/assets.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Scholar.searchFieldInit(GravMetadataIndex, ["title", "date", "taxonomy:categories", "taxonomy:tags", "media"], ' ~ json_encode(config.theme.flexsearch.index) ~ ');
', {group: 'bottom'}) %}
{% else %}
{% do assets.addInlineJs('console.debug("No data to search.");', {group: 'bottom'}) %}
{% do assets.addInlineJs('console.debug("No data for search-field.");', {group: 'bottom'}) %}
{% endif %}
{% elseif mode == 'form' %}
{% do assets.addCss('theme://node_modules/mobius1-selectr/dist/selectr.min.css') %}
Expand All @@ -32,15 +32,15 @@
{% set searchFile = files_exist([
page.header.search,
page.topParent.header.search,
'user://data/persist/index.full.js'
'user://data/persist/static/index.full.js'
]) %}
{% if searchFile %}
{% do assets.addJs(searchFile) %}
{% do assets.addInlineJs('
Scholar.searchPageInit(GravDataIndex, ["title", "date", "taxonomy:categories", "taxonomy:tags", "content", "media"], ' ~ json_encode(config.theme.flexsearch.full) ~ ');
', {group: 'bottom'}) %}
{% else %}
{% do assets.addInlineJs('console.debug("No data to search.");', {group: 'bottom'}) %}
{% do assets.addInlineJs('console.debug("No data for search-form.");', {group: 'bottom'}) %}
{% endif %}
{% endif %}
{% endblock %}
8 changes: 4 additions & 4 deletions templates/partials/header.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% if config.theme.toolbar.enabled %}
{% if render ?? config.theme.toolbar.enabled %}

{% block title %}
<h1>
Expand All @@ -21,7 +21,7 @@
<nav class="menu" role="navigation" aria-label="{{ "THEME_SCHOLAR.MENU"|t }}">

{% block mobile %}
{% if config.theme.toolbar.navigation %}
{% if renderMobile ?? config.theme.toolbar.navigation %}
<div mobile-menu-open role="button" tabindex="0" data-target="nav[role='navigation'].links" aria-label="{{ "THEME_SCHOLAR.GENERIC.OPEN"|t|capitalize }} {{ "THEME_SCHOLAR.MENU"|t }}">
{# Icon8 LineAwesome v1.3.0 Bars #}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" aria-hidden="true"><path d="M 4 7 L 4 9 L 28 9 L 28 7 L 4 7 z M 4 15 L 4 17 L 28 17 L 28 15 L 4 15 z M 4 23 L 4 25 L 28 25 L 28 23 L 4 23 z"/></svg>
Expand All @@ -35,13 +35,13 @@
page.topParent.header.search,
'user://data/persist/index.js'
]) %}
{% if config.theme.toolbar.search and searchFile %}
{% if renderSearch ?? config.theme.toolbar.search and searchFile %}
{% include 'partials/components/search/field.html.twig' %}
{% endif %}
{% endblock %}

{% block drawer %}
{% if config.theme.toolbar.navigation and navigablePage.headings is not empty %}
{% if renderNavigation ?? config.theme.toolbar.navigation and navigablePage.headings is not empty %}
<div data-drawer-open role="button" tabindex="0" data-target="drawer-menu" aria-label="{{ "THEME_SCHOLAR.GENERIC.OPEN"|t|capitalize }} {{ "THEME_SCHOLAR.MENU"|t }}">
{# Icon8 LineAwesome v1.3.0 Bars #}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" aria-hidden="true"><path d="M 4 7 L 4 9 L 28 9 L 28 7 L 4 7 z M 4 15 L 4 17 L 28 17 L 28 15 L 4 15 z M 4 23 L 4 25 L 28 25 L 28 23 L 4 23 z"/></svg>
Expand Down
13 changes: 3 additions & 10 deletions templates/search.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{% extends page.topParent.template ?? 'default' ~ '.html.twig' %}

{% set renderSearch = false %}

{% block javascripts %}
{% with {
'mode': 'form'
Expand All @@ -8,16 +10,7 @@
{% endwith %}
{% endblock %}

{% block header %}
<header role="banner">
{% with {
'page': page,
'navigablePage': navigablePage
} %}
{{ block('links', 'partials/docs/header.html.twig') }}
{% endwith %}
</header>
{% endblock %}
{% block search_results %}{% endblock %}

{% block article %}
<article class="search">
Expand Down

0 comments on commit 3bbf06a

Please sign in to comment.