Skip to content

Instantly share code, notes, and snippets.

View Sebobo's full-sized avatar
:shipit:
Thinking about things

Sebastian Helzle Sebobo

:shipit:
Thinking about things
View GitHub Profile
@Sebobo
Sebobo / preact-signals-global-state.ts
Last active March 9, 2023 08:10
Preact/Signals global state example
function createAppState(initialState: AppState) {
// Define a signal to hold the state
const appState = signal(initialState);
// Define a function to dispatch events to the reducer and its state machine and update the state with the result
const dispatch = (event: AppEvent) => {
appState.value = appStateReducer(appState.value, event);
};
// Derive readonly selectors for partial state values
@Sebobo
Sebobo / dimension_fix.sql
Created September 13, 2022 08:30
Remove duplicate nodes in a Neos setup with nodes without and with dimensions
UPDATE neos_contentrepository_domain_model_nodedata SET dimensionvalues = '{
"language": {
"0": "de"
}
}' WHERE dimensionvalues = '{}' and path <> '/' and path <> '/sites';
delete t1 FROM neos_contentrepository_domain_model_nodedata t1
INNER JOIN neos_contentrepository_domain_model_nodedata t2
WHERE
t1.lastmodificationdatetime <= t2.lastmodificationdatetime AND
@Sebobo
Sebobo / Helper_MenuItemsUriEnhancer.fusion
Last active March 3, 2022 15:55
Neos CMS integration/presentation separated navigation components
prototype(My.Site:Helper.MenuItemsUriEnhancer) < prototype(Neos.Fusion:Map) {
items = ${[]}
itemRenderer = Neos.Fusion:Value {
nodeUri = Neos.Neos:NodeUri {
node = ${item.node}
}
subItems = My.Site:Helper.MenuItemsUriEnhancer {
items = ${item.subItems}
}
@Sebobo
Sebobo / FlattenTransformation.php
Created June 22, 2021 14:21
Flatten transformation for Neos CMS Content Repository
<?php
declare(strict_types=1);
namespace My\Site\ContentRepository\Transformations;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\ContentRepository\Domain\Model\NodeData;
use Neos\ContentRepository\Migration\Transformations\AbstractTransformation;
use Neos\Neos\Controller\CreateContentContextTrait;
@Sebobo
Sebobo / ContentReferences.fusion
Created June 16, 2021 09:37
Optimized ContentReferences for NeosCMS
prototype(Neos.NodeTypes.ContentReferences:ContentReferences) >
prototype(Neos.NodeTypes.ContentReferences:ContentReferences) < prototype(Neos.Neos:ContentComponent) {
@context.referenceNodesArray = ${q(node).property('references')}
referenceNodes = Neos.Fusion:Collection {
collection = ${referenceNodesArray}
itemRenderer = Neos.Neos:ContentCase
itemName = 'node'
}
@Sebobo
Sebobo / composer.json
Last active February 4, 2021 15:45
Test script for comparing imagine scaled file sizes.
{
"name": "imagine/test",
"require": {
"imagine/imagine": "^1.2",
"rokka/imagine-vips": "0.12.0"
}
@Sebobo
Sebobo / ConditionGenerator.php
Created October 22, 2020 07:23
Modified ReadNodePrivilege for Neos CMS to restrict access to pages with subpages
<?php
declare(strict_types=1);
namespace My\Vendor\Security\Authorization\Privilege\Node\Doctrine;
use Neos\Flow\Security\Authorization\Privilege\Entity\Doctrine\FalseConditionGenerator;
use Neos\Flow\Security\Authorization\Privilege\Entity\Doctrine\PropertyConditionGenerator;
use Neos\Flow\Security\Authorization\Privilege\Entity\Doctrine\SqlGeneratorInterface;
/**
@Sebobo
Sebobo / ContentCollectionComponent.fusion
Created May 8, 2020 07:00
Nested schedule element without additional Content Collections for Neos CMS
# This is a variant of th enormal ContentComponent that already includes
# a prop which loads it's children as ContentCollectionRenderer and has the necessary caching configuration
# to make everything work like with the standard ContentCollection.
#
# You can inherit from this prototype instead of ContentComponent for the Schedule and Day types above
# and remove the `items` prop from them.
prototype(Meetup.Example:ContentCollectionComponent) < prototype(Neos.Neos:ContentComponent) {
items = Neos.Neos:ContentCollectionRenderer
@cache {
@Sebobo
Sebobo / LazyLoadImageExample.fusion
Created May 6, 2020 08:31
How to enable native lazy loading for all images in Neos CMS
# Modify all image tags and add the attribute
prototype(Neos.Neos:ImageTag) {
attributes.loading = 'lazy'
}
# Example on the usage, see https://fusionpen.punkt.de/fusionpen/4e19425fc39184b13790ff00e8ce1c10328fa36d.html
prototype(YourVendor:LazyImageDemo) < prototype(Neos.Fusion:Component) {
chapters = ${q(site).find('[instanceof Neos.Demo:Document.Chapter]').get()}
@Sebobo
Sebobo / Example.fusion
Created April 7, 2020 10:28
NeosCMS Eel helper to load a file with translations for the current locale as array. This allows for example to use the localisation features of the framework and forward all labels to a frontend app.
prototype(MyVendor.Package:Component.Example) < prototype(Neos.Fusion:Component) {
translations = ${MyVendor.Package.Translation.getTranslations('MyVendor.Package', 'MyJsApp')}
renderer = afx`
<div data-translations={Json.stringify(props.translations)} id="my-cool-app">Loading the app ...</div>
`
}