Giter VIP home page Giter VIP logo

laravel-valet-hugo-driver's Introduction

Hugo Valet Driver

This is a very simple Laravel Valet driver for serving static sites, specifically ones generated by Hugo. It looks for config.toml, config.yaml, or config.json file in the project root, along with a public folder, to indicate that it should be the active driver. Simply download the HugoValetDriver.php driver and place it in your ~/.config/valet/Drivers directory.

curl 'https://raw.githubusercontent.com/amsoell/laravel-valet-hugo-driver/master/HugoValetDriver.php' > ~/.config/valet/Drivers/HugoValetDriver.php

laravel-valet-hugo-driver's People

Contributors

amsoell avatar

Stargazers

 avatar

Watchers

 avatar  avatar

laravel-valet-hugo-driver's Issues

Valet V4 compatibilty

Hi, here is a Valet 4 compatible file, if ever someone needs it !

<?php

namespace Valet\Drivers\Custom;

use Valet\Drivers\ValetDriver;

class HugoValetDriver extends ValetDriver
{
    /**
     * Determine if the driver serves the request.
     *
     * @param  string $sitePath
     * @param  string $siteName
     * @param  string $uri
     * @return void
     */

     public function serves(string $sitePath, string $siteName, string $uri): bool
    {
        if ((file_exists($sitePath . '/config.toml') ||
            file_exists($sitePath . '/config.yaml') ||
            file_exists($sitePath . '/config.json')) &&
            file_exists($sitePath . '/public')
            ) {
            return true;
        }

        return false;
    }

    /**
     * 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(string $sitePath, string $siteName, string $uri)/*: string|false */
    {
        if ( file_exists( $staticPath = $sitePath . '/' . $this->getServingFolderName() . $uri ) && ! is_dir($staticPath) ) {
            return $staticPath;
        } elseif ( file_exists( $fauxPath = $staticPath . '/' . $this->getServingFileName() ) ) {
            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(string $sitePath, string $siteName, string $uri): string
    {
        return $sitePath . '/' . $this->getServingFolderName() . '/' . $this->getServingFileName();
    }

    private function getServingFolderName()
    {
        return 'public';
    }

    private function getServingFileName()
    {
        return 'index.html';
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.