Skip to content

Commit

Permalink
[#72] Always load UI JS on all parts kit pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuapease committed Jan 10, 2024
1 parent be05410 commit 76b8616
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/services/PartsKit.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ public static function getNav(): array
return array_values($result);
}

/**
* The JS file for the parts kit UI library. This needs to be added on both the
* parts kit root page and on each "part" page.
*
* unpkg.com respects server. This URL will need to be adjusted when major versions
* are released.
*
* @return string
*/
public static function getUiScriptUrl(): string
{
return 'https://unpkg.com/@viget/parts-kit@^0/lib/parts-kit.js';
}

/**
* Remove extension from file name
*
Expand Down
4 changes: 4 additions & 0 deletions src/templates/_layouts/parts-kit.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<meta name="robots" content="none">
{% endhtml %}

{% js craft.viget.partsKit.getUiScriptUrl() with {
type: 'module',
} %}

{% block content %}
{% block main %}
{% endblock %}
Expand Down
5 changes: 1 addition & 4 deletions src/templates/parts-kit-root.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
<meta name="robots" content="none">
</head>
<body>
<script
type="module"
src="https://unpkg.com/@viget/parts-kit@^0/lib/parts-kit.js"
></script>
<script type="module" src="{{ craft.viget.partsKit.getUiScriptUrl() }}"></script>
<parts-kit config-url="{{ actionUrl('parts-kit/config') }}"></parts-kit>
</body>
</html>

0 comments on commit 76b8616

Please sign in to comment.