Skip to content

Commit

Permalink
Merge pull request #550 from hydephp/develop
Browse files Browse the repository at this point in the history
v0.40.0-beta
  • Loading branch information
caendesilva authored Jun 22, 2022
2 parents ed79d61 + 0fa588c commit 0ff183b
Show file tree
Hide file tree
Showing 15 changed files with 475 additions and 73 deletions.
19 changes: 19 additions & 0 deletions config/docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,23 @@
'min_heading_level' => 2,
'max_heading_level' => 4,
],

/*
|--------------------------------------------------------------------------
| Search Customization
|--------------------------------------------------------------------------
|
| Hyde comes with an easy to use search feature for documentation pages.
| @see https://hydephp.com/docs/master/documentation-pages#search-feature
|
*/

// Should a docs/search.html page be generated?
'create_search_page' => true,

// Are there any pages you don't want to show in the search results?
'exclude_from_search' => [
'changelog',
],

];
3 changes: 3 additions & 0 deletions config/hyde.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@
|
*/

/**
* @deprecated will be handled in the service provider
*/
'site_output_path' => Hyde\Framework\Hyde::path('_site'),

/*
Expand Down
113 changes: 62 additions & 51 deletions resources/views/components/docs/search.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,71 +18,82 @@
</dialog>

<script>
const searchMenu = document.getElementById('searchMenu');
if (typeof HTMLDialogElement === 'function') {
const searchMenu = document.getElementById('searchMenu');
function toggleSearchMenu() {
if (searchMenu.hasAttribute('open')) {
closeSearchMenu();
} else {
openSearchMenu();
function toggleSearchMenu() {
if (searchMenu.hasAttribute('open')) {
closeSearchMenu();
} else {
openSearchMenu();
}
}
}
function closeSearchMenu() {
searchMenu.removeAttribute('open');
function closeSearchMenu() {
searchMenu.removeAttribute('open');
document.getElementById('searchMenuBackdrop').remove();
document.getElementById('searchMenuCloseButton').remove();
document.getElementById('searchMenuBackdrop').remove();
document.getElementById('searchMenuCloseButton').remove();
document.getElementById('searchMenuButton').style.visibility = 'visible';
}
document.getElementById('searchMenuButton').style.visibility = 'visible';
}
function openSearchMenu() {
searchMenu.setAttribute('open', '');
function openSearchMenu() {
searchMenu.setAttribute('open', '');
createBackdrop();
createCloseButton();
document.getElementById('searchMenuButton').style.visibility = 'hidden';
createBackdrop();
createCloseButton();
document.getElementById('searchMenuButton').style.visibility = 'hidden';
document.getElementById('search-input').focus();
document.getElementById('search-input').focus();
function createBackdrop() {
const backdrop = document.createElement('div');
backdrop.id = 'searchMenuBackdrop';
backdrop.classList.add('backdrop', 'active');
backdrop.addEventListener('click', () => {
closeSearchMenu();
});
document.body.appendChild(backdrop);
}
function createBackdrop() {
const backdrop = document.createElement('div');
backdrop.id = 'searchMenuBackdrop';
backdrop.classList.add('backdrop', 'active');
backdrop.addEventListener('click', () => {
closeSearchMenu();
});
document.body.appendChild(backdrop);
}
function createCloseButton() {
const closeButton = document.createElement('button');
closeButton.id = 'searchMenuCloseButton';
closeButton.classList.add('fixed');
closeButton.setAttribute('aria-label', 'Close search menu');
closeButton.addEventListener('click', () => {
closeSearchMenu();
});
closeButton.innerHTML = `<svg class="w-6 h-6" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd" />
</svg>`;
function createCloseButton() {
const closeButton = document.createElement('button');
closeButton.id = 'searchMenuCloseButton';
closeButton.classList.add('fixed');
closeButton.setAttribute('aria-label', 'Close search menu');
closeButton.addEventListener('click', () => {
closeSearchMenu();
});
closeButton.innerHTML = `<svg class="w-6 h-6" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd" />
</svg>`;
document.body.appendChild(closeButton);
document.body.appendChild(closeButton);
}
}
}
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && searchMenu.hasAttribute('open')) {
closeSearchMenu();
}
});
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && searchMenu.hasAttribute('open')) {
closeSearchMenu();
}
});
document.addEventListener('keypress', (e) => {
if (e.key === '/' && !searchMenu.hasAttribute('open')) {
e.preventDefault();
openSearchMenu();
document.addEventListener('keypress', (e) => {
if (e.key === '/' && !searchMenu.hasAttribute('open')) {
e.preventDefault();
openSearchMenu();
}
});
} else {
// The browser does not support the <dialog> element
document.getElementById('searchMenu').remove();
function toggleSearchMenu() {
window.location.href = 'search.html';
}
}
});
</script>
@endpush
9 changes: 9 additions & 0 deletions src/Actions/CreatesNewPageSourceFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Hyde\Framework\Actions;

use Hyde\Framework\Concerns\InteractsWithDirectories;
use Hyde\Framework\Exceptions\FileConflictException;
use Hyde\Framework\Exceptions\UnsupportedPageTypeException;
use Hyde\Framework\Hyde;
Expand All @@ -17,6 +18,8 @@
*/
class CreatesNewPageSourceFile
{
use InteractsWithDirectories;

public string $title;
public string $slug;
public string $outputPath;
Expand All @@ -39,13 +42,19 @@ public function canSaveFile(string $path): void
public function createPage(string $type): int|false
{
if ($type === MarkdownPage::class) {
$this->needsDirectory(MarkdownPage::$sourceDirectory);

return $this->createMarkdownFile();
}
if ($type === BladePage::class) {
$this->needsDirectory(BladePage::$sourceDirectory);

return $this->createBladeFile();
}

if ($type === DocumentationPage::class) {
$this->needsDirectory(DocumentationPage::$sourceDirectory);

return $this->createDocumentationFile();
}

Expand Down
5 changes: 4 additions & 1 deletion src/Actions/GeneratesDocumentationSearchIndexFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public function generatePageObject(string $slug): object

public function getSourceFileSlugs(): array
{
return CollectionService::getDocumentationPageList();
return array_diff(
CollectionService::getDocumentationPageList(),
config('docs.exclude_from_search', [])
);
}

public function getObject(): object
Expand Down
21 changes: 21 additions & 0 deletions src/Actions/PostBuildTasks/GenerateSitemap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Hyde\Framework\Actions\PostBuildTasks;

use Hyde\Framework\Contracts\AbstractBuildTask;
use Illuminate\Support\Facades\Artisan;

class GenerateSitemap extends AbstractBuildTask
{
public static string $description = 'Generating sitemap';

public function run(): void
{
Artisan::call('build:sitemap');
}

public function then(): void
{
$this->writeln("\n".' > Created <info>sitemap.xml</info> in '.$this->getExecutionTime());
}
}
10 changes: 7 additions & 3 deletions src/Commands/HydeBuildStaticSiteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Hyde\Framework\Commands;

use Exception;
use Hyde\Framework\Actions\PostBuildTasks\GenerateSitemap;
use Hyde\Framework\Concerns\Internal\BuildActionRunner;
use Hyde\Framework\Concerns\Internal\TransfersMediaAssetsForBuildCommands;
use Hyde\Framework\Helpers\Features;
Expand All @@ -11,6 +12,7 @@
use Hyde\Framework\Models\DocumentationPage;
use Hyde\Framework\Models\MarkdownPage;
use Hyde\Framework\Models\MarkdownPost;
use Hyde\Framework\Services\BuildHookService;
use Hyde\Framework\Services\CollectionService;
use Hyde\Framework\Services\DiscoveryService;
use Hyde\Framework\Services\RssFeedService;
Expand Down Expand Up @@ -117,6 +119,8 @@ protected function runPreBuildActions(): void
*/
public function runPostBuildActions(): void
{
$service = new BuildHookService($this->output);

if ($this->option('run-prettier') || $this->option('pretty')) {
if ($this->option('pretty')) {
$this->warn('<error>Warning:</> The --pretty option is deprecated, use --run-prettier instead');
Expand All @@ -136,9 +140,7 @@ public function runPostBuildActions(): void
$this->runNodeCommand('npm run prod', 'Building frontend assets for production!');
}

if ($this->canGenerateSitemap()) {
Artisan::call('build:sitemap', outputBuffer: $this->output);
}
$service->runIf(GenerateSitemap::class, $this->canGenerateSitemap());

if ($this->canGenerateFeed()) {
Artisan::call('build:rss', outputBuffer: $this->output);
Expand All @@ -147,6 +149,8 @@ public function runPostBuildActions(): void
if ($this->canGenerateSearch()) {
Artisan::call('build:search', outputBuffer: $this->output);
}

$service->runPostBuildTasks();
}

/** @internal */
Expand Down
63 changes: 63 additions & 0 deletions src/Contracts/AbstractBuildTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Hyde\Framework\Contracts;

use Illuminate\Console\Concerns\InteractsWithIO;
use Illuminate\Console\OutputStyle;

/**
* @experimental This feature was recently added and may be changed without notice.
*
* @since 0.40.0
*/
abstract class AbstractBuildTask implements BuildTaskContract
{
use InteractsWithIO;

protected static string $description = 'Generic build task';

protected float $timeStart;

public function __construct(?OutputStyle $output = null)
{
$this->output = $output;
$this->timeStart = microtime(true);
}

public function handle(): void
{
$this->write('<comment>'.$this->getDescription().'...</comment> ');

$this->run();
$this->then();

$this->write("\n");
}

abstract public function run(): void;

public function then(): void
{
$this->writeln('<fg=gray>Done in '.$this->getExecutionTime().'</>');
}

public function getDescription(): string
{
return static::$description;
}

public function getExecutionTime(): string
{
return number_format((microtime(true) - $this->timeStart) * 1000, 2).'ms';
}

public function write(string $message): void
{
$this->output?->write($message);
}

public function writeln(string $message): void
{
$this->output?->writeln($message);
}
}
25 changes: 25 additions & 0 deletions src/Contracts/BuildTaskContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Hyde\Framework\Contracts;

use Illuminate\Console\OutputStyle;

/**
* @experimental This feature was recently added and may be changed without notice.
*
* @since 0.40.0
*/
interface BuildTaskContract
{
public function __construct(?OutputStyle $output = null);

public function run(): void;

public function then(): void;

public function handle(): void;

public function getDescription(): string;

public function getExecutionTime(): string;
}
Loading

0 comments on commit 0ff183b

Please sign in to comment.