Skip to content

Commit

Permalink
Bedrock support: Use site URLs instead of paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Oriol Arcas committed Nov 20, 2021
1 parent e4c97d4 commit b95baaa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/DetectThemeAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ public static function detect( string $theme_type ) : array {

$detected_filename =
str_replace(
$site_path,
'/',
$template_path,
$template_url,
$filename
);

$detected_filename =
str_replace(
get_home_url(),
'/',
$detected_filename
);

if ( $path_crawlable ) {
if ( is_string( $detected_filename ) ) {
array_push(
Expand Down
22 changes: 15 additions & 7 deletions src/FilesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,17 @@ public static function deleteDirWithFiles( string $dir ) : void {
* Get public URLs for all files in a local directory.
*
* @param string $dir
* @param string $base_url
* @param array<string> $filenames_to_ignore
* @param array<string> $file_extensions_to_ignore
* @return string[] list of relative, urlencoded URLs
*/
public static function getListOfLocalFilesByDir(
string $dir,
string $base_url,
array $filenames_to_ignore,
array $file_extensions_to_ignore
) : array {
$site_path = SiteInfo::getPath( 'site' );

if ( ! is_string( $site_path ) ) {
return [];
}

$files = [];

if ( is_dir( $dir ) ) {
Expand All @@ -72,7 +68,19 @@ public static function getListOfLocalFilesByDir(
);

if ( $path_crawlable ) {
$url = str_replace( $site_path, '/', $filename );
$url =
str_replace(
$dir,
$base_url,
$filename
);

$url =
str_replace(
get_home_url(),
'/',
$url
);

if ( is_string( $url ) ) {
$files[] = $url;
Expand Down
1 change: 1 addition & 0 deletions src/URLDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public static function detectURLs() : string {
$arrays_to_merge[] =
FilesHelper::getListOfLocalFilesByDir(
SiteInfo::getPath( 'uploads' ),
SiteInfo::getUrl( 'uploads' ),
$filenames_to_ignore,
$file_extensions_to_ignore
);
Expand Down

0 comments on commit b95baaa

Please sign in to comment.