Skip to content

Commit

Permalink
Merge branch 'release/2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed May 27, 2020
2 parents 4cedc5e + df93af0 commit 51803f6
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v2.1.0
## 05/27/2020

1. [](#new)
* Added ability to search page headers (excluding title, taxonomy, content)

# v2.0.0
## 05/13/2020

Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![SimpleSearch](assets/readme_1.png)

`SimpleSearch` is a simple, yet very powerful [Grav][grav] plugin that adds search capabilities to your Grav instance. By default it can search Page **Titles**, **Content** and also **Taxonomy**.
`SimpleSearch` is a simple, yet very powerful [Grav][grav] plugin that adds search capabilities to your Grav instance. By default it can search Page **Titles**, **Content**, **Taxonomy**, and also a raw page **Header**.

# Installation

Expand Down Expand Up @@ -40,12 +40,17 @@ route: /search
search_content: rendered
template: simplesearch_results
filters:
category: blog
category:
filter_combinator: and
ignore_accented_characters: false
order:
by: date
dir: desc
searchable_types:
title: true
content: true
taxonomy: true
header: false
```

By creating the configuration file: `user/config/plugins/simplesearch.yaml` you have effectively created a site-wide configuration for SimpleSearch. However, you may want to have multiple searches.
Expand Down
4 changes: 3 additions & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: SimpleSearch
version: 2.0.0
version: 2.1.0
description: "Don't be fooled, the **SimpleSearch** plugin provides a **fast** and highly **configurable** way to search your content."
icon: search
author:
Expand Down Expand Up @@ -103,9 +103,11 @@ form:
searchable_types:
type: checkboxes
label: PLUGIN_SIMPLESEARCH.SEARCHABLE_TYPES
description: PLUGIN_SIMPLESEARCH.SEARCHABLE_TYPES_DESCRIPTION
options:
title: Title
content: Content
header: Header
taxonomy: Taxonomy
use: keys

Expand Down
3 changes: 2 additions & 1 deletion languages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ en:
AND_COMBINATOR: 'And - Boolean &&'
OR_COMBINATOR: 'Or - Boolean ||'
SEARCHABLE_TYPES: "Searchable Types"

SEARCHABLE_TYPES_DESCRIPTION: "<b>Title</b> = Search Page Title<br><b>Content</b> = Search Page Content<br><b>Header</b> = Search Raw Headers (excluding title, content, taxonomy)<br><b>Taxonomy</b> = Search Taxonomy"

ro:
PLUGIN_SIMPLESEARCH:
SEARCH_PLACEHOLDER: "Caută …"
Expand Down
17 changes: 17 additions & 0 deletions simplesearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ private function notFound($query, $page, $taxonomies)
$content = $page->content();
}
$result = $this->matchText(strip_tags($content), $query) === false;
} elseif ($type == 'header' && $enabled) {
$header = (array) $page->header();
$content = $this->getArrayValues($header);
$result = $this->matchText(strip_tags($content), $query) === false;
}
$results = $results && $result;
if ($results === false) {
Expand Down Expand Up @@ -388,4 +392,17 @@ public function onTwigSiteVariables()
$this->grav['assets']->addJs('plugin://simplesearch/js/simplesearch.js', ['group' => 'bottom']);
}
}

protected function getArrayValues($array, $ignore_keys = ['title','taxonomy','content'], $output = '') {
foreach ($array as $key => $child) {
if (!in_array($key, $ignore_keys)) {
if (is_array($child)) {
$output .= " " . $this->getArrayValues($child, $ignore_keys, $output);
} else {
$output .= " " . $child;
}
}
}
return trim($output);
}
}
3 changes: 2 additions & 1 deletion simplesearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ order:
searchable_types:
title: true
content: true
taxonomy: true
taxonomy: true
header: false

0 comments on commit 51803f6

Please sign in to comment.