Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set view paths on each page, taking multi-site into consideration #129

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Generator
protected $extraUrls;
protected $workers = 1;
protected $taskResults;
protected $viewPaths;

public function __construct(Application $app, Filesystem $files, Router $router, Tasks $tasks)
{
Expand Down Expand Up @@ -86,10 +87,12 @@ public function generate()

$this
->bindGlide()
->backupViewPaths()
->clearDirectory()
->createContentFiles()
->createSymlinks()
->copyFiles()
->restoreViewPaths()
->outputSummary();

if ($this->after) {
Expand Down Expand Up @@ -167,6 +170,21 @@ public function copyFiles()
return $this;
}

protected function backupViewPaths()
{
$this->viewPaths = view()->getFinder()->getPaths();

return $this;
}

protected function restoreViewPaths()
{
view()->getFinder()->setPaths($this->viewPaths);

return $this;
}


protected function createContentFiles()
{
$request = tap(Request::capture(), function ($request) {
Expand Down Expand Up @@ -398,6 +416,7 @@ protected function updateCurrentSite($site)
{
Site::setCurrent($site->handle());
Cascade::withSite($site);
$this->setViewPaths($site->handle());

// Set the locale for dates, carbon, and for the translator.
// This is what happens in Statamic's Localize middleware.
Expand Down Expand Up @@ -433,4 +452,20 @@ protected function shouldSetCarbonFormat($page)
|| $content instanceof \Statamic\Contracts\Taxonomies\Term
|| $content instanceof StatamicRoute;
}

protected function setViewPaths($site)
{
$paths = collect($this->viewPaths)->flatMap(function ($path) use ($site) {
$amp = Statamic::isAmpRequest();

return [
$amp ? $path . '/' . $site . '/amp' : null,
$path . '/' . $site,
$amp ? $path . '/amp' : null,
$path,
];
})->filter()->values()->all();

view()->getFinder()->setPaths($paths);
}
}