Skip to content

Commit

Permalink
Add the Site URL feature, remember to update config!
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Mar 23, 2022
1 parent ee49391 commit ee2f5c6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
16 changes: 16 additions & 0 deletions config/hyde.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@
'name' => 'HydePHP',


/*
|--------------------------------------------------------------------------
| Site URL
|--------------------------------------------------------------------------
|
| If you want, you can set your site's URL here or in the .env file.
|
| The URL will then be used in meta tags to create permalinks.
| If you are serving your site from a subdirectory, you will
| need to include that in the path without a trailing slash.
|
| Example: https://example.com/blog
|
*/
'site_url' => env('SITE_URL', null),

/*
|--------------------------------------------------------------------------
| Features
Expand Down
4 changes: 4 additions & 0 deletions resources/views/layouts/post.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<meta property="og:type" content="article" />
@if($title) <meta property="og:title" content="{{ $title }}"> @endif
@if($date) <meta property="og:article:published_time" content="{{ $date }}"> @endif
@if(Hyde::uriPath())
<meta property="og:url" content="{{ Hyde::uriPath($post->slug) }}">
@endif

@endpush

<main class="mx-auto max-w-7xl py-16 px-8">
Expand Down
15 changes: 15 additions & 0 deletions src/Hyde.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ public static function relativePath(string $destination, string $current = ""):
return $route;
}

/**
* Return a qualified URI path, if SITE_URL is set in .env, else return false.
*
* @param string|null $path optional relative path suffix. Omit to return base url.
* @return string|false
*/
public static function uriPath(?string $path = ''): string|false
{
if (config('hyde.site_url', false)) {
return rtrim(config('hyde.site_url'), '/') . '/' . (trim($path, '/') ?? '');
}

return false;
}

/**
* Get a Laravel Collection of all Posts as MarkdownPost objects.
*
Expand Down

0 comments on commit ee2f5c6

Please sign in to comment.