Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support non-JSON config properties (such as callbacks and regexes) through config/ckeditor.js #54

Merged
merged 5 commits into from
Jan 12, 2023
Merged

Support non-JSON config properties (such as callbacks and regexes) through config/ckeditor.js #54

merged 5 commits into from
Jan 12, 2023

Conversation

timraasveld
Copy link
Contributor

@timraasveld timraasveld commented Jan 3, 2023

This PR allows creating a config/ckeditor.js (or .ts) in a Strapi project to as a replacement for the editor: section in config/plugins.ts.

In config/plugins.ts, properties which are non serializable, such as regexes and callbacks, would get truncated when fetching the config. This makes it impossible to configure, for example, mediaEmbed providers.

This PR tackles the problem by having a config/ckeditor.js inserted in a <script> tag, and assigning that to the CKEditor config.

Example use case to make mediaEmbed use youtube-nocookie.com when a YT video is inserted:

// config/ckeditor.js
globalThis.ckEditorConfig = {
    toolbar: {
        items: [
          ...
        ]
    },
    mediaEmbed: {
        previewsInData: true,

        providers: [
            {
                name: 'youtube',
                url: [
                    /^(?:m\.)?youtube\.com\/watch\?v=([\w-]+)(?:&t=(\d+))?/,
                    /^(?:m\.)?youtube\.com\/v\/([\w-]+)(?:\?t=(\d+))?/,
                    /^youtube\.com\/embed\/([\w-]+)(?:\?start=(\d+))?/,
                    /^youtu\.be\/([\w-]+)(?:\?t=(\d+))?/
                ],
                html: match => {
                    const id = match[1];
                    
                    return (`<iframe
                              src="https://www.youtube-nocookie.com/embed/${id}"
                              frameborder="0"
                              allow="autoplay; encrypted-media" 
                              allowfullscreen />
                        `);
                }
            },
        ]
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants