GrapesJS / export

Export GrapesJS templates in a zip archive
BSD 3-Clause "New" or "Revised" License
76 stars 68 forks source link

Multi-Page Support #14

Closed kyng-cytro closed 2 years ago

kyng-cytro commented 3 years ago

Using this plugin, I noticed it only exports the active page. Could you work around making it all pages?

Stage4000 commented 2 years ago

Bump ---edit--- Recanting my bump because it's already a feature.

Stage4000 commented 2 years ago

root can be a function so you can use a configuration like below:

           'grapesjs-plugin-export': {
                root(ed) { 
                    const all = ed.Pages.getAll();
                    const pages = {};
                    const css = {};
                    all.map(page => {
                        pages[(page.get('name') || page.id) + '.html'] = '<!doctype html>' +
                            '<html lang="en">' +
                            '<head>' +
                            '<meta charset="utf-8">' +
                            '<link rel="stylesheet" href="/css/style-' + page.id + '.css">' +
                            '</head>' +
                            '<body>' +
                            page.getMainComponent().toHTML() +
                            '</body>' +
                            '</html>';
                        css['style-' + page.id + '.css'] = editor.CodeManager.getCode(page.getMainComponent(), 'css')
                    });
                    return {
                        css: {
                            ...css
                        },
                        ...pages
                    }
                }
            }

Credit: Juggernaut, via the GrapesJS discussions area.