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

Allow site output directory to be customized #362

Merged
merged 33 commits into from May 16, 2022

Conversation

caendesilva
Copy link
Member

@caendesilva caendesilva commented May 16, 2022

Introduces a new config option:

/*
|--------------------------------------------------------------------------
| Site Output Directory (Experimental 🧪)
|--------------------------------------------------------------------------
|
| If you want to store your compiled website in a different directory than
| the default `_pages`, you can change the path here. The Hyde::path()
| helper ensures the path is relative to your Hyde project. While
| you can set the path to an absolute path outside the project,
| this is not officially supported and may be unstable.
|
*/

'siteOutputPath' => 'C:\xampp\htdocs',

Which is then registered in the HydeServiceProvider.

$this->storeCompiledSiteIn(config(
    'hyde.siteOutputPath', Hyde::path('_site')
));

The registered property value is stored in the StaticPageBuilder.

protected function storeCompiledSiteIn(string $directory): void
{
    StaticPageBuilder::$outputPath = $directory;
}

And the path can be accessed fluently through the helpers

Hyde::getSiteOutputPath() // Absolute base path
Hyde::getSiteOutputPath('foo.html') // File within the base path

Hyde::getRelativeSiteOutputPath() // Base path relative to the Hyde project
Hyde::getRelativeSiteOutputPath('foo.html') // Relative filepath to same

Will fix #351

@caendesilva
Copy link
Member Author

caendesilva commented May 16, 2022

While not officially supported, for me it works wonders to use absolute paths leading to outside the project root.

// config/hyde.php
'siteOutputPath' => 'C:\xampp\htdocs',
All done! Finished in 1.73 seconds. (1,733.34ms)
Congratulations! 🎉 Your static site has been built!
Your new homepage is stored here -> file://C:/xampp/htdocs/index.html

Edit: I did not think this would work, but it actually can prettify external files using Prettier as well.

Prettifying code! This may take a second.
C:\xampp\htdocs\404.html 271ms
C:\xampp\htdocs\blade.html 235ms
C:\xampp\htdocs\docs\headings.html 35ms
C:\xampp\htdocs\docs\index.html 33ms

@caendesilva caendesilva marked this pull request as ready for review May 16, 2022 14:29
StyleCIBot and others added 2 commits May 16, 2022 14:32
@caendesilva caendesilva merged commit 1d92b74 into master May 16, 2022
@caendesilva caendesilva deleted the 351-allow-site-output-directory-to-be-customized branch May 16, 2022 14:54
caendesilva pushed a commit that referenced this pull request Aug 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow site output directory to be customized
2 participants