Skip to content

Commit

Permalink
refactor stylesheet detection
Browse files Browse the repository at this point in the history
  • Loading branch information
idleberg committed Jun 8, 2024
1 parent 64495d6 commit 7ae73b1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function inject(array|string $entrypoint, array $customOptions = []): voi

add_action($action, function () use ($entries, $options) {
array_map(function($entry) use ($options) {
$tag = str_ends_with($entry, '.css') || str_ends_with($entry, '.scss')
$tag = $this->isStylesheet($entry)
? array_key_first($this->getStyleTags($entry, $options))
: $this->getScriptTag($entry, $options);

Expand Down Expand Up @@ -216,4 +216,17 @@ private function mergeOptions(array $options = [])
$options
);
}

/**
* Determines wether a file is a stylesheet based on its extension
*
* @param string $entry
* @return bool
*/
private function isStylesheet(string $entry)
{
$styleSheets = ['.css', '.less', '.scss', '.styl'];

return in_array(pathinfo($entry, PATHINFO_EXTENSION), $styleSheets);
}
}

0 comments on commit 7ae73b1

Please sign in to comment.