Skip to content

Instantly share code, notes, and snippets.

@rogervila
Last active September 1, 2017 20:28
Show Gist options
  • Save rogervila/3e61ea54553fd4bd4c1a5fe313e6cbb4 to your computer and use it in GitHub Desktop.
Save rogervila/3e61ea54553fd4bd4c1a5fe313e6cbb4 to your computer and use it in GitHub Desktop.
JekyllValetDriver
<?php
class JekyllValetDriver extends ValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return void
*/
public function serves($sitePath, $siteName, $uri)
{
// Check for several default Jekyll folders and files.
return
is_dir($sitePath . DIRECTORY_SEPARATOR . $this->getServingFolderName())
&& file_exists($sitePath .'/_config.yml')
&& file_exists($sitePath . DIRECTORY_SEPARATOR . $this->getServingFileName());
}
/**
* Determine if the incoming request is for a static file.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return string|false
*/
public function isStaticFile($sitePath, $siteName, $uri)
{
if (file_exists($staticPath = $sitePath . DIRECTORY_SEPARATOR . $this->getServingFolderName() . $uri ) && !is_dir($staticPath)) {
// It's a static file.
return $staticPath;
}
if (file_exists($fauxPath = $staticPath. DIRECTORY_SEPARATOR . $this->getServingFileName())) {
// Mimic front controller action for all sub directories.
return $fauxPath;
}
return false;
}
/**
* Get the fully resolved path to the application's front controller.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return string
*/
public function frontControllerPath($sitePath, $siteName, $uri)
{
return $sitePath. DIRECTORY_SEPARATOR . $this->getServingFolderName() . DIRECTORY_SEPARATOR . $this->getServingFileName();
}
private function getServingFolderName()
{
return '_site';
}
private function getServingFileName()
{
return 'index.html';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment