Skip to content

Commit e656555

Browse files
committed
Merge branch 'feature/opensearch' into development
2 parents 8bc6e75 + 514db60 commit e656555

File tree

12 files changed

+117
-31
lines changed

12 files changed

+117
-31
lines changed

app/App/MetaController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,14 @@ public function licenses()
6464
'jsLibData' => file_get_contents(base_path('dev/licensing/js-library-licenses.txt')),
6565
]);
6666
}
67+
68+
/**
69+
* Show the view for /opensearch.xml.
70+
*/
71+
public function opensearch()
72+
{
73+
return response()
74+
->view('misc.opensearch')
75+
->header('Content-Type', 'application/opensearchdescription+xml');
76+
}
6777
}

lang/en/common.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,7 @@
107107
// Not directly used but available for convenience to users.
108108
'privacy_policy' => 'Privacy Policy',
109109
'terms_of_service' => 'Terms of Service',
110+
111+
// OpenSearch
112+
'opensearch_description' => 'Search :appName',
110113
];

resources/views/layouts/base.blade.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class="{{ setting()->getForCurrentUser('dark-mode-enabled') ? 'dark-mode ' : ''
3232
<link rel="manifest" href="{{ url('/manifest.json') }}">
3333
<meta name="mobile-web-app-capable" content="yes">
3434

35+
<!-- OpenSearch -->
36+
<link rel="search" type="application/opensearchdescription+xml" title="{{ setting('app-name') }}" href="{{ url('/opensearch.xml') }}">
37+
3538
@yield('head')
3639

3740
<!-- Custom Styles & Head Content -->
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
3+
<ShortName>{{ mb_strimwidth(setting('app-name'), 0, 16) }}</ShortName>
4+
<Description>{{ trans('common.opensearch_description', ['appName' => setting('app-name')]) }}</Description>
5+
<Image width="256" height="256" type="image/png">{{ setting('app-icon') ?: url('/icon.png') }}</Image>
6+
<Image width="180" height="180" type="image/png">{{ setting('app-icon-180') ?: url('/icon-180.png') }}</Image>
7+
<Image width="128" height="128" type="image/png">{{ setting('app-icon-128') ?: url('/icon-128.png') }}</Image>
8+
<Image width="64" height="64" type="image/png">{{ setting('app-icon-64') ?: url('/icon-64.png') }}</Image>
9+
<Image width="32" height="32" type="image/png">{{ setting('app-icon-32') ?: url('/icon-32.png') }}</Image>
10+
<Url type="text/html" rel="results" template="{{ url('/search') }}?term={searchTerms}"/>
11+
<Url type="application/opensearchdescription+xml" rel="self" template="{{ url('/opensearch.xml') }}"/>
12+
</OpenSearchDescription>

routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
Route::get('/favicon.ico', [MetaController::class, 'favicon']);
2424
Route::get('/manifest.json', [MetaController::class, 'pwaManifest']);
2525
Route::get('/licenses', [MetaController::class, 'licenses']);
26+
Route::get('/opensearch.xml', [MetaController::class, 'opensearch']);
2627

2728
// Authenticated routes...
2829
Route::middleware('auth')->group(function () {

tests/HelpTest.php renamed to tests/Meta/HelpTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
namespace Tests;
3+
namespace Tests\Meta;
4+
5+
use Tests\TestCase;
46

57
class HelpTest extends TestCase
68
{

tests/LicensesTest.php renamed to tests/Meta/LicensesTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
namespace Tests;
3+
namespace Tests\Meta;
4+
5+
use Tests\TestCase;
46

57
class LicensesTest extends TestCase
68
{

tests/OpenGraphTest.php renamed to tests/Meta/OpenGraphTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
22

3-
namespace Tests;
3+
namespace Tests\Meta;
44

55
use BookStack\Entities\Repos\BaseRepo;
66
use BookStack\Entities\Repos\BookRepo;
77
use Illuminate\Support\Str;
88
use Illuminate\Testing\TestResponse;
9+
use Tests\TestCase;
910

1011
class OpenGraphTest extends TestCase
1112
{

tests/Meta/OpensearchTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Tests\Meta;
4+
5+
use Tests\TestCase;
6+
7+
class OpensearchTest extends TestCase
8+
{
9+
public function test_opensearch_endpoint()
10+
{
11+
$appName = 'MyAppNameThatsReallyLongLikeThis';
12+
setting()->put('app-name', $appName);
13+
$resultUrl = url('/search') . '?term={searchTerms}';
14+
$selfUrl = url('/opensearch.xml');
15+
16+
$resp = $this->get('/opensearch.xml');
17+
$resp->assertOk();
18+
19+
$html = $this->withHtml($resp);
20+
21+
$html->assertElementExists('OpenSearchDescription > ShortName');
22+
$html->assertElementContains('OpenSearchDescription > ShortName', mb_strimwidth($appName, 0, 16));
23+
$html->assertElementNotContains('OpenSearchDescription > ShortName', $appName);
24+
25+
$html->assertElementExists('OpenSearchDescription > Description');
26+
$html->assertElementContains('OpenSearchDescription > Description', "Search {$appName}");
27+
$html->assertElementExists('OpenSearchDescription > Image');
28+
$html->assertElementExists('OpenSearchDescription > Url[rel="results"][template="' . htmlspecialchars($resultUrl) . '"]');
29+
$html->assertElementExists('OpenSearchDescription > Url[rel="self"][template="' . htmlspecialchars($selfUrl) . '"]');
30+
}
31+
32+
public function test_opensearch_linked_to_from_home()
33+
{
34+
$appName = setting('app-name');
35+
$endpointUrl = url('/opensearch.xml');
36+
37+
$resp = $this->asViewer()->get('/');
38+
$html = $this->withHtml($resp);
39+
40+
$html->assertElementExists('head > link[rel="search"][type="application/opensearchdescription+xml"][title="' . htmlspecialchars($appName) . '"][href="' . htmlspecialchars($endpointUrl) . '"]');
41+
}
42+
}

tests/PwaManifestTest.php renamed to tests/Meta/PwaManifestTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
namespace Tests;
3+
namespace Tests\Meta;
4+
5+
use Tests\TestCase;
46

57
class PwaManifestTest extends TestCase
68
{

0 commit comments

Comments
 (0)