Skip to content
This repository was archived by the owner on Feb 9, 2021. It is now read-only.

Commit 559c723

Browse files
authored
Merge pull request #2 from edcs/feature/specify-asset-path
Make it possible to define asset URL
2 parents 36a413c + b1c5110 commit 559c723

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

LaravelMixTrait.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ trait LaravelMixTrait
1818
/**
1919
* The name of Mix's revision manifest file.
2020
*/
21-
protected $manifest = 'mix-manifest.json';
21+
static $manifest = 'mix-manifest.json';
2222

2323
/**
2424
* Returns the path of given asset type.
@@ -28,8 +28,8 @@ trait LaravelMixTrait
2828
*/
2929
public function getAssetPath($type)
3030
{
31-
$theme = Config::get('theming.theme');
32-
$path = '/' . $type . '/' . Str::ensureRight($theme, '.' . $type);
31+
$src = $this->get('src', Config::get('theming.theme'));
32+
$path = '/' . $type . '/' . Str::ensureRight($src, '.' . $type);
3333
$manifest = $this->getManifest()->get($path);
3434

3535
return $this->themeUrl($manifest);
@@ -43,11 +43,15 @@ public function getAssetPath($type)
4343
*/
4444
private function themeUrl($path)
4545
{
46-
$url = URL::assemble(
47-
Config::get('system.filesystems.themes.url'),
48-
Config::get('theming.theme'),
49-
$path
50-
);
46+
if (!$this->getParam('path', false)) {
47+
$url = URL::assemble(
48+
Config::get('system.filesystems.themes.url'),
49+
Config::get('theming.theme'),
50+
$path
51+
);
52+
} else {
53+
$url = URL::assemble($this->getParam('path'), $path);
54+
}
5155

5256
$url = URL::prependSiteUrl(
5357
$url,
@@ -69,7 +73,7 @@ private function themeUrl($path)
6973
*/
7074
private function getManifest()
7175
{
72-
$path = webroot_path('site/themes/' . Config::get('theming.theme') . '/' . $this->manifest);
76+
$path = webroot_path(static::$manifest);
7377

7478
return collect(json_decode(File::get($path), true));
7579
}

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ You can now update your theme template tags to use those provided by this add-on
6868
{{ laravel_mix:js }}
6969
```
7070

71-
This add-on supports some of the parameters as the default Statamic tags, these are:
71+
This add-on supports the following tags, these are:
7272

7373
| Parameter | Default | Description |
74-
|:----------:|:---------------:|:----------------------------------------:|
74+
|:----------:|:---------------:|------------------------------------------|
7575
| `tag` | `boolean` false | Enable this to output the full HTML tag. |
7676
| `absolute` | `boolean` false | Output an absolute or relative URL. |
77+
| `path` | `string` null | The path which gets prepended to the URL of the asset. If it is omitted, the default Statamitc behaviour is invoked which is to generate a URL relative to the theme's public directory |
7778

7879
## Using with Laravel Blade instead of Antlers.
7980

0 commit comments

Comments
 (0)