Skip to content

Commit

Permalink
Fix searching on @self (#53)
Browse files Browse the repository at this point in the history
* Fix searching on @self

If a page had

```
simplesearch:
    route: '@self'
```

then search was not really working

* Fill changelog
  • Loading branch information
flaviocopes authored Jul 21, 2016
1 parent d9ce4b0 commit 0efc7f6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

1. [](#new)
* Multiple search boxes support [#52](/~https://github.com/getgrav/grav-plugin-simplesearch/pull/52)
1. [](#bugfix)
* Fix searching on `@self
 `[#53](/~https://github.com/getgrav/grav-plugin-simplesearch/pull/53)

# v1.8.0
## 07/14/2016
Expand Down
50 changes: 26 additions & 24 deletions simplesearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,30 @@ public function onPluginsInitialized()
]);
}


/**
* Build search results.
*/
public function onPagesInitialized()
{
$page = $this->grav['page'];

// Support `route: '@self'` syntax
if ($this->config->get('plugins.simplesearch.route') === '@self') {
$route = $page->route();
$this->config->set('plugins.simplesearch.route', $route);
}

// If a page exists merge the configs
if ($page) {
$this->config->set('plugins.simplesearch', $this->mergeConfig($page));
$mergedConfig = $this->mergeConfig($page);

// Support `route: '@self'` syntax
if ($mergedConfig->route === '@self') {
$route = $page->rawRoute();
$mergedConfig->route = $route;
}

$this->config->set('plugins.simplesearch', $mergedConfig);
}

/** @var Uri $uri */
Expand All @@ -97,12 +110,6 @@ public function onPagesInitialized()
return;
}

// Support `route: '@self'` syntax
if($route === '@self') {
$route = $page.route();
$this->config->set('plugins.simplesearch.route', $route);
}

// performance check for route
if (!($route && $route == $uri->path())) {
return;
Expand Down Expand Up @@ -158,7 +165,6 @@ public function onPagesInitialized()
}
}


$extras = [];

if ($query) {
Expand All @@ -181,7 +187,6 @@ public function onPagesInitialized()
}
}


if (!empty($extras)) {
$this->collection->append($extras);
}
Expand All @@ -194,23 +199,20 @@ public function onPagesInitialized()
);
}

// if page doesn't have settings set, create a page
if (!isset($page->header()->simplesearch)) {
// create the search page
$page = new Page;
$page->init(new \SplFileInfo(__DIR__ . '/pages/simplesearch.md'));
// create the search page
$page = new Page;
$page->init(new \SplFileInfo(__DIR__ . '/pages/simplesearch.md'));

// override the template is set in the config
$template_override = $this->config->get('plugins.simplesearch.template');
if ($template_override) {
$page->template($template_override);
}
// override the template is set in the config
$template_override = $this->config->get('plugins.simplesearch.template');
if ($template_override) {
$page->template($template_override);
}

// fix RuntimeException: Cannot override frozen service "page" issue
unset($this->grav['page']);
// fix RuntimeException: Cannot override frozen service "page" issue
unset($this->grav['page']);

$this->grav['page'] = $page;
}
$this->grav['page'] = $page;
}


Expand Down

0 comments on commit 0efc7f6

Please sign in to comment.