Skip to content

Commit

Permalink
Create and proxy JSON search index, fix #4
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed May 30, 2022
1 parent 1667f2f commit 8ec05bc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions server.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
exit(0);
}

// JSON hotpatch
if ($uri === '/docs/search.json') {
\Hyde\RealtimeCompiler\HydeRC::serveSearchIndex();
exit(0);
}

// If the uri is empty, serve the index file
if (empty($uri) || $uri == '/') {
$uri = '/index';
Expand Down
18 changes: 18 additions & 0 deletions src/HydeRC.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,22 @@ private static function getStaticContentType(string $path): string

return 'text/plain';
}

/**
* Serve the search index JSON, and create it if necessary.
*/
public static function serveSearchIndex(): void
{
$path = HYDE_PATH.'/_site/docs/search.json';

if (!file_exists($path)) {
header('HTTP/1.0 102 Processing (Generating Search Index)');
shell_exec('php '.HYDE_PATH.'/hyde build:search --ansi');
header('HTTP/1.0 201 Created (Search Index Generated)');
}

header('Content-Type: ' . 'application/json');
header('Content-Length: ' . filesize($path));
readfile($path);
}
}

0 comments on commit 8ec05bc

Please sign in to comment.