├── README.md
├── src
└── attributes
│ └── PrefectUrlsProps.php
├── templates
└── _components
│ └── meta
│ └── prefetch-urls.twig
├── composer.json
└── LICENSE.md
/README.md:
--------------------------------------------------------------------------------
1 | # Craft Twig Base Components
2 |
3 | Brought to you by [nystudio107](http://nystudio107.com)
4 |
--------------------------------------------------------------------------------
/src/attributes/PrefectUrlsProps.php:
--------------------------------------------------------------------------------
1 | tags should be output */
13 | public bool $outputLinks = true;
14 |
15 | /* @var bool $outputHeaders Whether Link: headers should be output */
16 | public bool $outputHeaders = true;
17 | }
18 |
--------------------------------------------------------------------------------
/templates/_components/meta/prefetch-urls.twig:
--------------------------------------------------------------------------------
1 | {# -- Prefetch & preconnect headers and links -- #}
2 |
3 | {# @var \nystudio107\craftTwigBaseComponents\attributes\PrefectUrlsProps props #}
4 | {% set props = {
5 | prefetchUrls = [],
6 | outputLinks = true,
7 | outputHeaders = true,
8 | } | merge(props ?? {}) %}
9 |
10 | {% for url in props.prefetchUrls %}
11 | {% set headerLink = headerLink ~ "<#{url}>; rel=dns-prefetch;," %}
12 | {% set headerLink = headerLink ~ "<#{url}>; rel=preconnect; crossorigin;" %}
13 | {% if not loop.last %}
14 | {% set headerLink = headerLink ~ "," %}
15 | {% endif %}
16 | {% if props.outputLinks %}
17 |
18 |
19 | {% endif %}
20 | {% endfor %}
21 | {% if headerLink is not empty and props.outputHeaders %}
22 | {% header "Link: " ~ headerLink %}
23 | {% endif %}
24 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nystudio107/craft-twig-base-components",
3 | "description": "Craft CMS Twig base components",
4 | "type": "twig-bundle",
5 | "version": "1.0.0",
6 | "keywords": [
7 | "twig",
8 | "twig-bundle",
9 | "composer",
10 | "installer",
11 | "bundle"
12 | ],
13 | "homepage": "https://nystudio107.com",
14 | "require": {
15 | "craftcms/cms": "*",
16 | "nystudio107/twig-bundle-installer": "^1.0.0"
17 | },
18 | "support": {
19 | "email": "info@nystudio107.com",
20 | "issues": "https://github.com/nystudio107/craft-twig-base-components/issues",
21 | "source": "https://github.com/nystudio107/craft-twig-base-components",
22 | "docs": "https://github.com/nystudio107/craft-twig-base-components"
23 | },
24 | "autoload": {
25 | "psr-4": {
26 | "nystudio107\\craftTwigBaseComponents\\": "src/"
27 | }
28 | },
29 | "license": "MIT",
30 | "minimum-stability": "stable"
31 | }
32 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) nystudio107.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------