Skip to content

Commit 31310ae

Browse files
committed
🐛 Now every type of resource hints accepts attributes
1 parent 4d2d512 commit 31310ae

File tree

2 files changed

+60
-71
lines changed

2 files changed

+60
-71
lines changed

Classes/Eel/Helper/IncludeAssetsHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class IncludeAssetsHelper implements ProtectedContextAwareInterface
2222

2323
public function parseFilename(string $string): ?array
2424
{
25-
$types = array('js', 'css', 'mjs', 'preload', 'preloadasset', 'preloadcss', 'preloadscript', 'modulepreload');
25+
$types = array('js', 'css', 'mjs', 'resourcehint', 'preloadasset', 'preloadcss', 'preloadscript', 'modulepreload');
2626
// 1 => Filename
2727
// 2 => Search string
2828
// 3 => Attributes

Resources/Private/Fusion/External/ResourceHints.fusion

Lines changed: 59 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -15,76 +15,65 @@ prototype(Carbon.IncludeAssets:ResourceHints) < prototype(Neos.Fusion:Component)
1515
// Pass documentNodes who should be prerendererd (Array, FlowQuery or a single node)
1616
prerenderNodes = null
1717

18-
renderer = Neos.Fusion:Array {
19-
dnsPrefetch = Neos.Fusion:Collection {
20-
@if.set = ${Type.isArray(this.collection) && Array.length(this.collection)}
21-
collection = ${props.dnsPrefetch}
22-
[email protected] = ${Carbon.Array.unique(Type.isString(value) ? String.split(value, ',') : value)}
23-
itemRenderer = afx`<link rel='dns-prefetch' href={item} />`
24-
}
25-
preconnect = Neos.Fusion:Collection {
26-
@if.set = ${Type.isArray(this.collection) && Array.length(this.collection)}
27-
collection = ${props.preconnect}
28-
[email protected] = ${Carbon.Array.unique(Type.isString(value) ? String.split(value, ',') : value)}
29-
itemRenderer = afx`<link rel='preconnect' href={item} />`
30-
}
31-
prefetch = Neos.Fusion:Collection {
32-
@if.set = ${Type.isArray(this.collection) && Array.length(this.collection)}
33-
collection = ${props.prefetch}
34-
[email protected] = ${Carbon.Array.unique(Type.isString(value) ? String.split(value, ',') : value)}
35-
itemRenderer = afx`<link rel='prefetch' href={item} />`
36-
}
37-
modulePreload = Neos.Fusion:Collection {
38-
@if.set = ${Type.isArray(this.collection) && Array.length(this.collection)}
39-
collection = ${props.modulePreload}
40-
[email protected] = ${Carbon.Array.unique(Type.isString(value) ? String.split(value, ',') : value)}
41-
itemRenderer = Carbon.IncludeAssets:Internal.Tag.ModulePreload {
42-
fileObject = ${Carbon.IncludeAssets.parseFilename(item + '(modulePreload)')}
43-
path = ${this.fileObject.filename}
44-
}
45-
}
46-
preload = Neos.Fusion:Collection {
47-
@if.set = ${Type.isArray(this.collection) && Array.length(this.collection)}
48-
collection = ${props.preload}
49-
[email protected] = ${Carbon.Array.unique(Type.isString(value) ? String.split(value, ',') : value)}
50-
itemRenderer = Carbon.IncludeAssets:Internal.Tag.Preload {
51-
fileObject = ${Carbon.IncludeAssets.parseFilename(item + '(preload)')}
52-
path = ${this.fileObject.filename}
53-
}
54-
}
55-
preloadNodes = Neos.Fusion:Collection {
56-
@if.set = ${props.preloadNodes && Type.isArray(this.collection) && Array.length(this.collection)}
57-
collection = ${props.preloadNodes}
58-
collection.@process {
59-
convertFlowQueryToArray = ${Type.instance(value, 'Neos\Eel\FlowQuery\FlowQuery') ? value.get() : value}
60-
convertSingleToArray = ${Type.instance(value, 'Neos\ContentRepository\Domain\Model\Node') ? [value] : value}
61-
uniqueArray = ${Carbon.Array.unique(value)}
62-
}
63-
itemRenderer = afx`
64-
<link rel='preload' as='document' @if.set={Type.instance(item, 'Neos\ContentRepository\Domain\Model\Node') && documentNode != item}>
65-
<Neos.Neos:NodeUri @path='attributes.href' node={item} absolute={true} />
66-
</link>
67-
`
68-
}
69-
prerender = Neos.Fusion:Collection {
70-
@if.set = ${Type.isArray(this.collection) && Array.length(this.collection)}
71-
collection = ${props.prerender}
72-
[email protected] = ${Carbon.Array.unique(Type.isString(value) ? String.split(value, ',') : value)}
73-
itemRenderer = afx`<link rel='prerender' href={item} />`
74-
}
75-
prerenderNodes = Neos.Fusion:Collection {
76-
@if.set = ${props.prerenderNodes && Type.isArray(this.collection) && Array.length(this.collection)}
77-
collection = ${props.prerenderNodes}
78-
collection.@process {
79-
convertFlowQueryToArray = ${Type.instance(value, 'Neos\Eel\FlowQuery\FlowQuery') ? value.get() : value}
80-
convertSingleToArray = ${Type.instance(value, 'Neos\ContentRepository\Domain\Model\Node') ? [value] : value}
81-
uniqueArray = ${Carbon.Array.unique(value)}
82-
}
83-
itemRenderer = afx`
84-
<link rel='prerender' @if.set={Type.instance(item, 'Neos\ContentRepository\Domain\Model\Node') && documentNode != item}>
85-
<Neos.Neos:NodeUri @path='attributes.href' node={item} absolute={true} />
86-
</link>
87-
`
18+
renderer = afx`
19+
<Carbon.IncludeAssets:ResourceHints.Items @key='dnsPrefetch' items={props.dnsPrefetch} rel='dns-prefetch' />
20+
<Carbon.IncludeAssets:ResourceHints.Items @key='preconnect' items={props.preconnect} rel='preconnect' />
21+
<Carbon.IncludeAssets:ResourceHints.Items @key='prefetch' items={props.prefetch} rel='prefetch' />
22+
<Carbon.IncludeAssets:ResourceHints.Items @key='modulePreload' items={props.modulePreload} rel='modulepreload' />
23+
<Carbon.IncludeAssets:ResourceHints.Items @key='preload' items={props.preload} rel='preload' />
24+
<Carbon.IncludeAssets:ResourceHints.Nodes @key='preloadNodes' items={props.preloadNodes} rel='preload' as='document' />
25+
<Carbon.IncludeAssets:ResourceHints.Items @key='prerender' items={props.prerender} rel='prerender' />
26+
<Carbon.IncludeAssets:ResourceHints.Nodes @key='prerenderNodes' items={props.prerenderNodes} rel='prerender' />
27+
`
28+
}
29+
30+
31+
prototype(Carbon.IncludeAssets:ResourceHints.Items) < prototype(Neos.Fusion:Component) {
32+
items = null
33+
rel = null
34+
type = ${this.rel == 'modulepreload' ? 'modulepreload' : 'resourcehint'}
35+
36+
37+
// Internal
38+
[email protected] = ${Type.isString(value) ? String.split(value, ',') : value}
39+
@if.set = ${this.items && this.rel && this.type && Type.isArray(this.items) && Array.length(this.items)}
40+
41+
renderer = Neos.Fusion:Collection {
42+
collection = ${Carbon.Array.unique(props.items)}
43+
itemRenderer = Carbon.IncludeAssets:Internal.Tag.ResourceHint {
44+
rel = ${props.rel}
45+
fileObject = ${Carbon.IncludeAssets.parseFilename(item + '(' + props.type + ')')}
46+
path = ${this.fileObject.filename}
8847
}
8948
}
9049
}
50+
51+
prototype(Carbon.IncludeAssets:ResourceHints.Nodes) < prototype(Neos.Fusion:Component) {
52+
items = null
53+
rel = null
54+
as = null
55+
56+
57+
// Internal
58+
items.@process {
59+
convertFlowQueryToArray = ${Type.instance(value, 'Neos\Eel\FlowQuery\FlowQuery') ? value.get() : value}
60+
convertSingleToArray = ${Type.instance(value, 'Neos\ContentRepository\Domain\Model\Node') ? [value] : value}
61+
}
62+
@if.set = ${this.items && this.rel && Type.isArray(this.items) && Array.length(this.items)}
63+
64+
renderer = Neos.Fusion:Collection {
65+
collection = ${Carbon.Array.unique(props.items)}
66+
itemRenderer = afx`
67+
<link
68+
rel={props.rel}
69+
as={props.as}
70+
@if.isNode={Type.instance(item, 'Neos\ContentRepository\Domain\Model\Node')}
71+
@if.isNotCurrent={documentNode != item}
72+
@if.isDocument={q(item).is('[instanceof Neos.Neos:Document]')}
73+
>
74+
<Neos.Neos:NodeUri @path='attributes.href' node={item} absolute={true} />
75+
</link>
76+
`
77+
}
78+
}
79+

0 commit comments

Comments
 (0)