@silexlabs/silex 3.0.0-alpha.41 → 3.0.0-alpha.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.silex.js +2 -11
- package/dist/client/client/api.d.ts +83 -0
- package/dist/client/client/config.d.ts +3 -3
- package/dist/client/client/events.d.ts +12 -0
- package/dist/client/client/expose.d.ts +6 -0
- package/dist/client/client/grapesjs/LoginDialog.d.ts +3 -2
- package/dist/client/client/grapesjs/PublicationManager.d.ts +9 -3
- package/dist/client/client/grapesjs/PublicationUi.d.ts +9 -6
- package/dist/client/client/grapesjs/index.d.ts +4 -4
- package/dist/client/client/grapesjs/openImport.d.ts +5 -0
- package/dist/client/constants.d.ts +23 -14
- package/dist/client/css/admin.css +5 -0
- package/dist/client/js/main.js +90 -111
- package/dist/client/js/main.js.LICENSE.txt +0 -6
- package/dist/client/page.d.ts +1 -1
- package/dist/client/types.d.ts +125 -86
- package/dist/plugins/client/client/events.d.ts +12 -0
- package/dist/plugins/client/client/events.js +30 -0
- package/dist/plugins/client/client/events.js.map +1 -0
- package/dist/plugins/client/client/utils.d.ts +1 -0
- package/{src/ts/events.ts → dist/plugins/client/client/utils.js} +9 -3
- package/dist/plugins/client/client/utils.js.map +1 -0
- package/dist/plugins/client/constants.d.ts +30 -0
- package/dist/plugins/client/constants.js +47 -0
- package/dist/plugins/client/constants.js.map +1 -0
- package/dist/plugins/client/page.d.ts +2 -0
- package/dist/plugins/client/page.js +31 -0
- package/dist/plugins/client/page.js.map +1 -0
- package/dist/plugins/client/plugins/client/publicationRenderer.d.ts +2 -0
- package/dist/plugins/client/plugins/client/publicationRenderer.js +128 -0
- package/dist/plugins/client/plugins/client/publicationRenderer.js.map +1 -0
- package/dist/plugins/client/plugins/client/template.d.ts +2 -0
- package/dist/plugins/client/plugins/client/template.js +186 -0
- package/dist/plugins/client/plugins/client/template.js.map +1 -0
- package/dist/plugins/client/server/config.d.ts +59 -0
- package/dist/plugins/client/server/config.js +178 -0
- package/dist/plugins/client/server/config.js.map +1 -0
- package/dist/plugins/client/server/connectors/FsHosting.d.ts +13 -0
- package/dist/plugins/client/server/connectors/FsHosting.js +51 -0
- package/dist/plugins/client/server/connectors/FsHosting.js.map +1 -0
- package/dist/plugins/client/server/connectors/FsStorage.d.ts +41 -0
- package/dist/plugins/client/server/connectors/FsStorage.js +220 -0
- package/dist/plugins/client/server/connectors/FsStorage.js.map +1 -0
- package/dist/plugins/client/server/connectors/connectors.d.ts +83 -0
- package/dist/plugins/client/server/connectors/connectors.js +91 -0
- package/dist/plugins/client/server/connectors/connectors.js.map +1 -0
- package/dist/plugins/client/server/events.d.ts +26 -0
- package/dist/plugins/client/server/events.js +12 -0
- package/dist/plugins/client/server/events.js.map +1 -0
- package/dist/plugins/client/server/jobs.js +67 -0
- package/dist/plugins/client/server/jobs.js.map +1 -0
- package/dist/plugins/client/server/utils/validation.js +34 -0
- package/dist/plugins/client/server/utils/validation.js.map +1 -0
- package/dist/plugins/client/types.d.ts +309 -0
- package/dist/plugins/client/types.js +49 -0
- package/dist/plugins/client/types.js.map +1 -0
- package/dist/plugins/server/constants.d.ts +30 -0
- package/dist/plugins/server/constants.js +50 -0
- package/dist/plugins/server/constants.js.map +1 -0
- package/dist/plugins/server/plugins/server/AuthPlugin.js.map +1 -0
- package/dist/plugins/server/plugins/server/Cache.js.map +1 -0
- package/dist/plugins/server/plugins/server/FtpConnector.d.ts +94 -0
- package/dist/plugins/server/plugins/server/FtpConnector.js +521 -0
- package/dist/plugins/server/plugins/server/FtpConnector.js.map +1 -0
- package/dist/plugins/{HooksPlugin.d.ts → server/plugins/server/HooksPlugin.d.ts} +1 -1
- package/dist/plugins/{HooksPlugin.js → server/plugins/server/HooksPlugin.js} +8 -10
- package/dist/plugins/server/plugins/server/HooksPlugin.js.map +1 -0
- package/dist/plugins/server/plugins/server/PublicationOptimizer.d.ts +0 -0
- package/dist/plugins/server/plugins/server/PublicationOptimizer.js +14 -0
- package/dist/plugins/server/plugins/server/PublicationOptimizer.js.map +1 -0
- package/dist/plugins/{SslPlugin.js → server/plugins/server/SslPlugin.js} +8 -8
- package/dist/plugins/server/plugins/server/SslPlugin.js.map +1 -0
- package/dist/plugins/{StaticPlugin.js → server/plugins/server/StaticPlugin.js} +9 -4
- package/dist/plugins/server/plugins/server/StaticPlugin.js.map +1 -0
- package/dist/plugins/server/server/config.d.ts +59 -0
- package/dist/plugins/server/server/config.js +182 -0
- package/dist/plugins/server/server/config.js.map +1 -0
- package/dist/plugins/server/server/connectors/FsHosting.d.ts +13 -0
- package/dist/plugins/server/server/connectors/FsHosting.js +55 -0
- package/dist/plugins/server/server/connectors/FsHosting.js.map +1 -0
- package/dist/plugins/server/server/connectors/FsStorage.d.ts +41 -0
- package/dist/{server/backends/FsBackend.js → plugins/server/server/connectors/FsStorage.js} +103 -125
- package/dist/plugins/server/server/connectors/FsStorage.js.map +1 -0
- package/dist/plugins/server/server/connectors/connectors.d.ts +83 -0
- package/dist/plugins/server/server/connectors/connectors.js +99 -0
- package/dist/plugins/server/server/connectors/connectors.js.map +1 -0
- package/dist/plugins/server/server/events.d.ts +26 -0
- package/dist/plugins/server/server/events.js +15 -0
- package/dist/plugins/server/server/events.js.map +1 -0
- package/dist/plugins/server/server/jobs.d.ts +6 -0
- package/dist/plugins/server/server/jobs.js.map +1 -0
- package/dist/plugins/server/server/utils/validation.d.ts +7 -0
- package/dist/{server → plugins/server/server}/utils/validation.js +3 -2
- package/dist/plugins/server/server/utils/validation.js.map +1 -0
- package/dist/plugins/server/types.d.ts +309 -0
- package/dist/{types.js → plugins/server/types.js} +18 -7
- package/dist/plugins/server/types.js.map +1 -0
- package/dist/server/constants.js +30 -0
- package/dist/server/plugins/server/Cache.js +15 -0
- package/dist/server/server/api/api.js +20 -0
- package/dist/server/server/api/connectorApi.js +200 -0
- package/dist/server/server/api/publicationApi.js +116 -0
- package/dist/server/server/api/websiteApi.js +297 -0
- package/dist/server/{cli.js → server/cli.js} +6 -5
- package/dist/server/server/config.js +121 -0
- package/dist/server/server/connectors/FsHosting.js +37 -0
- package/dist/server/server/connectors/FsStorage.js +218 -0
- package/dist/server/server/connectors/connectors.js +65 -0
- package/dist/server/server/events.js +14 -0
- package/dist/server/{express.js → server/express.js} +4 -3
- package/dist/server/{index.js → server/index.js} +14 -7
- package/dist/server/server/jobs.js +47 -0
- package/dist/server/server/utils/validation.js +15 -0
- package/dist/server/types.js +19 -0
- package/package.json +26 -15
- package/src/css/grapesjs.scss +5 -0
- package/src/ts/client/api.ts +135 -0
- package/src/ts/client/config.ts +3 -3
- package/{dist/events.js → src/ts/client/events.ts} +13 -6
- package/src/ts/client/expose.ts +11 -0
- package/src/ts/client/grapesjs/LoginDialog.ts +33 -32
- package/src/ts/client/grapesjs/PublicationManager.ts +86 -112
- package/src/ts/client/grapesjs/PublicationUi.ts +43 -33
- package/src/ts/client/grapesjs/eleventy.ts +4 -1
- package/src/ts/client/grapesjs/index.ts +6 -19
- package/src/ts/client/grapesjs/openImport.ts +5 -0
- package/src/ts/client/grapesjs/storage.ts +18 -14
- package/src/ts/client/index.ts +21 -15
- package/src/ts/constants.ts +24 -14
- package/src/ts/page.ts +1 -1
- package/src/ts/plugins/client/publicationRenderer.ts +128 -0
- package/src/ts/plugins/client/template.ts +196 -0
- package/src/ts/plugins/server/FtpConnector.ts +602 -0
- package/src/ts/plugins/{HooksPlugin.ts → server/HooksPlugin.ts} +9 -12
- package/src/ts/plugins/server/PublicationOptimizer.ts +14 -0
- package/src/ts/plugins/{SslPlugin.ts → server/SslPlugin.ts} +8 -8
- package/src/ts/plugins/{StaticPlugin.ts → server/StaticPlugin.ts} +8 -4
- package/src/ts/server/api/api.ts +19 -0
- package/src/ts/server/api/connectorApi.ts +322 -0
- package/src/ts/server/api/publicationApi.ts +166 -0
- package/src/ts/server/api/websiteApi.ts +420 -0
- package/src/ts/server/cli.ts +7 -5
- package/src/ts/server/config.ts +107 -95
- package/src/ts/server/connectors/FsHosting.ts +60 -0
- package/src/ts/server/connectors/FsStorage.ts +247 -0
- package/src/ts/server/connectors/connectors.ts +173 -0
- package/src/ts/server/events.ts +20 -0
- package/src/ts/server/express.ts +4 -3
- package/src/ts/server/index.ts +19 -15
- package/src/ts/server/jobs.test.ts +1 -0
- package/src/ts/server/utils/BackwardCompat.ts +1 -1
- package/src/ts/server/utils/validation.ts +3 -2
- package/src/ts/types.ts +93 -61
- package/.silex/default/website.json +0 -1
- package/dist/client/client/grapesjs/eleventy.d.ts +0 -1
- package/dist/client/client/grapesjs/template.d.ts +0 -1
- package/dist/client/client/services.d.ts +0 -35
- package/dist/client/events.d.ts +0 -2
- package/dist/constants.d.ts +0 -21
- package/dist/constants.js +0 -41
- package/dist/constants.js.map +0 -1
- package/dist/events.d.ts +0 -2
- package/dist/events.js.map +0 -1
- package/dist/plugins/AuthPlugin.js.map +0 -1
- package/dist/plugins/Cache.js.map +0 -1
- package/dist/plugins/FtpBackend.d.ts +0 -92
- package/dist/plugins/FtpBackend.js +0 -604
- package/dist/plugins/FtpBackend.js.map +0 -1
- package/dist/plugins/HooksPlugin.js.map +0 -1
- package/dist/plugins/PublicationPlugin.d.ts +0 -17
- package/dist/plugins/PublicationPlugin.js +0 -170
- package/dist/plugins/PublicationPlugin.js.map +0 -1
- package/dist/plugins/SslPlugin.js.map +0 -1
- package/dist/plugins/StaticPlugin.js.map +0 -1
- package/dist/plugins/WebsitePlugin.d.ts +0 -14
- package/dist/plugins/WebsitePlugin.js +0 -302
- package/dist/plugins/WebsitePlugin.js.map +0 -1
- package/dist/server/backends/FsBackend.d.ts +0 -42
- package/dist/server/backends/FsBackend.js.map +0 -1
- package/dist/server/backends/index.d.ts +0 -95
- package/dist/server/backends/index.js +0 -255
- package/dist/server/backends/index.js.map +0 -1
- package/dist/server/config.d.ts +0 -58
- package/dist/server/config.js +0 -174
- package/dist/server/config.js.map +0 -1
- package/dist/server/jobs.js.map +0 -1
- package/dist/server/utils/validation.js.map +0 -1
- package/dist/types.d.ts +0 -270
- package/dist/types.js.map +0 -1
- package/src/ts/client/grapesjs/template.ts +0 -183
- package/src/ts/client/services.ts +0 -129
- package/src/ts/plugins/FtpBackend.ts +0 -689
- package/src/ts/plugins/PublicationPlugin.ts +0 -170
- package/src/ts/plugins/WebsitePlugin.ts +0 -318
- package/src/ts/server/backends/FsBackend.ts +0 -266
- package/src/ts/server/backends/index.ts +0 -309
- /package/dist/{server → plugins/client/server}/jobs.d.ts +0 -0
- /package/dist/{server → plugins/client/server}/utils/validation.d.ts +0 -0
- /package/dist/plugins/{AuthPlugin.d.ts → server/plugins/server/AuthPlugin.d.ts} +0 -0
- /package/dist/plugins/{AuthPlugin.js → server/plugins/server/AuthPlugin.js} +0 -0
- /package/dist/plugins/{Cache.d.ts → server/plugins/server/Cache.d.ts} +0 -0
- /package/dist/plugins/{Cache.js → server/plugins/server/Cache.js} +0 -0
- /package/dist/plugins/{SslPlugin.d.ts → server/plugins/server/SslPlugin.d.ts} +0 -0
- /package/dist/plugins/{StaticPlugin.d.ts → server/plugins/server/StaticPlugin.d.ts} +0 -0
- /package/dist/{server → plugins/server/server}/jobs.js +0 -0
- /package/src/ts/plugins/{AuthPlugin.ts → server/AuthPlugin.ts} +0 -0
- /package/src/ts/plugins/{Cache.ts → server/Cache.ts} +0 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { getPageSlug } from '../../page.js';
|
|
2
|
+
import { onAll } from '../../client/utils.js';
|
|
3
|
+
import { ClientEvent } from '../../client/events.js';
|
|
4
|
+
export default (config, opts = {}) => {
|
|
5
|
+
const options = {
|
|
6
|
+
autoHomePage: false,
|
|
7
|
+
...opts,
|
|
8
|
+
html: {
|
|
9
|
+
frontMatter: false,
|
|
10
|
+
ext: '.html',
|
|
11
|
+
url: '/',
|
|
12
|
+
path: './',
|
|
13
|
+
...opts.html,
|
|
14
|
+
},
|
|
15
|
+
css: {
|
|
16
|
+
frontMatter: false,
|
|
17
|
+
ext: '.css',
|
|
18
|
+
url: '/css',
|
|
19
|
+
path: './css',
|
|
20
|
+
...opts.css,
|
|
21
|
+
},
|
|
22
|
+
assets: {
|
|
23
|
+
url: '/',
|
|
24
|
+
path: './',
|
|
25
|
+
...opts.assets,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
config.on(ClientEvent.STARTUP_END, ({ editor }) => {
|
|
29
|
+
editor.on(ClientEvent.PUBLISH_START, () => {
|
|
30
|
+
// Update assets URL to display outside the editor
|
|
31
|
+
const assetsFolderUrl = options.assets.url;
|
|
32
|
+
if (assetsFolderUrl) {
|
|
33
|
+
// Concat the paths, handles the trailing and leading slashes
|
|
34
|
+
const publishedUrl = path => `${assetsFolderUrl.replace(/\/+$/, '')}/${path.replace(/^\/+/, '')}`;
|
|
35
|
+
// New URLs for assets, according to site config
|
|
36
|
+
onAll(editor, c => {
|
|
37
|
+
// Attributes
|
|
38
|
+
if (c.get('type') === 'image') {
|
|
39
|
+
const src = c.get('src');
|
|
40
|
+
c.set('tmp-src', src);
|
|
41
|
+
c.set('src', publishedUrl(src));
|
|
42
|
+
}
|
|
43
|
+
//// Inline styles
|
|
44
|
+
//// This is handled by the editor.Css.getAll loop
|
|
45
|
+
//const bgUrl = c.getStyle()['background-image']?.match(/url\('(.*)'\)/)?.pop()
|
|
46
|
+
//if(bgUrl) {
|
|
47
|
+
// c.set('tmp-bg-url', bgUrl)
|
|
48
|
+
// c.setStyle({
|
|
49
|
+
// ...c.getStyle(),
|
|
50
|
+
// 'background-image': `url('${publishedUrl(bgUrl)}')`,
|
|
51
|
+
// })
|
|
52
|
+
//}
|
|
53
|
+
});
|
|
54
|
+
editor.Css.getAll()
|
|
55
|
+
.forEach(c => {
|
|
56
|
+
const bgUrl = c.getStyle()['background-image']?.match(/url\('(.*)'\)/)?.pop();
|
|
57
|
+
if (bgUrl) {
|
|
58
|
+
c.setStyle({
|
|
59
|
+
...c.getStyle(),
|
|
60
|
+
'background-image': `url('${publishedUrl(bgUrl)}')`,
|
|
61
|
+
});
|
|
62
|
+
c.set('tmp-bg-url-css', bgUrl);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
editor.Pages.getAll().forEach(page => {
|
|
67
|
+
if (page.get('type') === 'main' && options?.autoHomePage) {
|
|
68
|
+
page.set('slug', 'index');
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
page.set('slug', getPageSlug(page.get('name') || page.get('type')));
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
editor.on(ClientEvent.PUBLISH_END, () => {
|
|
76
|
+
const assetsFolderUrl = options.assets.url;
|
|
77
|
+
// Reset asset URLs
|
|
78
|
+
if (assetsFolderUrl) {
|
|
79
|
+
onAll(editor, c => {
|
|
80
|
+
if (c.get('type') === 'image' && c.has('tmp-src')) {
|
|
81
|
+
c.set('src', c.get('tmp-src'));
|
|
82
|
+
c.set('tmp-src');
|
|
83
|
+
}
|
|
84
|
+
//// This is handled by the editor.Css.getAll loop
|
|
85
|
+
//if(c.getStyle()['background-image'] && c.has('tmp-bg-url')) {
|
|
86
|
+
// c.setStyle({
|
|
87
|
+
// ...c.getStyle(),
|
|
88
|
+
// 'background-image': `url('${c.get('tmp-bg-url')}')`,
|
|
89
|
+
// })
|
|
90
|
+
// c.set('tmp-bg-url')
|
|
91
|
+
//}
|
|
92
|
+
});
|
|
93
|
+
editor.Css.getAll()
|
|
94
|
+
.forEach(c => {
|
|
95
|
+
if (c.has('tmp-bg-url-css')) {
|
|
96
|
+
c.setStyle({
|
|
97
|
+
...c.getStyle(),
|
|
98
|
+
'background-image': `url('${c.get('tmp-bg-url-css')}')`,
|
|
99
|
+
});
|
|
100
|
+
c.set('tmp-bg-url-css');
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
editor.on(ClientEvent.PUBLISH_DATA, data => {
|
|
106
|
+
data.pages.forEach((page, idx) => {
|
|
107
|
+
const file = data.files[idx];
|
|
108
|
+
// CSS
|
|
109
|
+
file.cssPath = file.cssPath.replace(/\.css$/, options.css.ext);
|
|
110
|
+
file.cssPath = options.css.path + file.cssPath;
|
|
111
|
+
if (options.css.frontMatter) {
|
|
112
|
+
file.css = `---\npermalink: ${options.css.url}/${page.slug}.css\n---\n${file.css}`;
|
|
113
|
+
}
|
|
114
|
+
// HTML
|
|
115
|
+
file.htmlPath = file.htmlPath.replace(/\.html$/, options.html.ext);
|
|
116
|
+
file.htmlPath = options.html.path + file.htmlPath;
|
|
117
|
+
if (options.html.frontMatter) {
|
|
118
|
+
file.html = `---\npermalink: ${options.html.url}/${page.slug}.html\n---\n${file.html}`;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
data.assets.forEach((asset, idx) => {
|
|
122
|
+
asset.path = options.assets.path + asset.src;
|
|
123
|
+
// The rest is handled by the editor.Css.getAll loop
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=publicationRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publicationRenderer.js","sourceRoot":"","sources":["../../../../../src/ts/plugins/client/publicationRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEpD,eAAe,CAAC,MAAM,EAAE,OAAY,EAAE,EAAE,EAAE;IACxC,MAAM,OAAO,GAAG;QACd,YAAY,EAAE,KAAK;QACnB,GAAG,IAAI;QACP,IAAI,EAAE;YACJ,WAAW,EAAE,KAAK;YAClB,GAAG,EAAE,OAAO;YACZ,GAAG,EAAE,GAAG;YACR,IAAI,EAAE,IAAI;YACV,GAAG,IAAI,CAAC,IAAI;SACb;QACD,GAAG,EAAE;YACH,WAAW,EAAE,KAAK;YAClB,GAAG,EAAE,MAAM;YACX,GAAG,EA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,IAAI,CAAC,GAAG,EAAE,CAAA;iBACnF;gBACD,OAAO;gBACP,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;gBAClE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAA;gBACjD,IAAI,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE;oBAC5B,IAAI,CAAC,IAAI,GAAG,mBAAmB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,eAAe,IAAI,CAAC,IAAI,EAAE,CAAA;iBACvF;YACH,CAAC,CAAC,CAAA;YACF,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;gBACjC,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC,GAAG,CAAA;gBAC5C,oDAAoD;YACtD,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Silex website builder, free/libre no-code tool for makers.
|
|
3
|
+
* Copyright (c) 2023 lexoyo and Silex Labs foundation
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
//import {html, render} from 'lit-html'
|
|
18
|
+
//import {styleMap} from 'lit-html/directives/style-map.js'
|
|
19
|
+
//import { onAll } from '@silexlabs/silex/dist/client/utils.js'
|
|
20
|
+
import { onAll } from '../../client/utils.js';
|
|
21
|
+
import { ServerEvent } from '../../server/events.js';
|
|
22
|
+
//// @ts-ignore
|
|
23
|
+
//import {html, render} from '/node_modules/lit-html/lit-html.js'
|
|
24
|
+
//// @ts-ignore
|
|
25
|
+
//import {styleMap} from '/node_modules/lit-html/directives/style-map.js'
|
|
26
|
+
const silex = window['silex'];
|
|
27
|
+
const pluginName = 'template';
|
|
28
|
+
const templateType = 'templateType';
|
|
29
|
+
const templateKey = 'template';
|
|
30
|
+
export default async (config, opts = {}) => {
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
const { html, render } = await import('/node_modules/lit-html/lit-html.js');
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
const { styleMap } = await import('/node_modules/lit-html/directives/style-map.js');
|
|
35
|
+
config.on(ServerEvent.STARTUP_END, () => {
|
|
36
|
+
const editor = silex.getEditor();
|
|
37
|
+
// Add the new trait to all component types
|
|
38
|
+
editor.DomComponents.getTypes().map(type => {
|
|
39
|
+
const originalType = editor.DomComponents.getType(type.id);
|
|
40
|
+
editor.DomComponents.addType(type.id, {
|
|
41
|
+
model: {
|
|
42
|
+
defaults: {
|
|
43
|
+
traits: [
|
|
44
|
+
// Keep the type original traits
|
|
45
|
+
...originalType.model.prototype.defaults.traits,
|
|
46
|
+
// Add the new trait
|
|
47
|
+
{
|
|
48
|
+
label: false,
|
|
49
|
+
type: templateType,
|
|
50
|
+
name: pluginName,
|
|
51
|
+
},
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
function doRender(el) {
|
|
58
|
+
const template = editor.getSelected()?.get(templateKey) || {};
|
|
59
|
+
const taStyle = opts.styles?.textarea ?? styleMap({
|
|
60
|
+
backgroundColor: 'var(--darkerPrimaryColor)',
|
|
61
|
+
});
|
|
62
|
+
const sepStyle = opts.styles?.sep ?? styleMap({ height: '10px' });
|
|
63
|
+
const labels = {
|
|
64
|
+
before: html `<strong>Before</strong> the element`,
|
|
65
|
+
replace: html `<strong>Replace</strong> the element's children`,
|
|
66
|
+
after: html `<strong>After</strong> the element`,
|
|
67
|
+
attributes: html `HTML attributes`,
|
|
68
|
+
classname: html `CSS classes`,
|
|
69
|
+
style: html `CSS styles`,
|
|
70
|
+
};
|
|
71
|
+
render(html `
|
|
72
|
+
<div>
|
|
73
|
+
<h3>Template</h3>
|
|
74
|
+
<p>This will be inserted in the published version</p>
|
|
75
|
+
</div>
|
|
76
|
+
${['classname', 'attributes', 'style'].map(id => html `
|
|
77
|
+
<label>
|
|
78
|
+
${labels[id]}
|
|
79
|
+
<input
|
|
80
|
+
id="template-${id}"
|
|
81
|
+
.value=${template[id] || ''}
|
|
82
|
+
style=${taStyle}
|
|
83
|
+
/>
|
|
84
|
+
</label>
|
|
85
|
+
`)}
|
|
86
|
+
${['before', 'replace', 'after'].map(id => html `
|
|
87
|
+
<label
|
|
88
|
+
for="template-${id}"
|
|
89
|
+
>${labels[id]}</label>
|
|
90
|
+
<textarea
|
|
91
|
+
id="template-${id}"
|
|
92
|
+
style=${taStyle}
|
|
93
|
+
.value=${template[id] || ''}
|
|
94
|
+
></textarea>
|
|
95
|
+
`)}
|
|
96
|
+
`, el);
|
|
97
|
+
}
|
|
98
|
+
editor.TraitManager.addType(templateType, {
|
|
99
|
+
createInput({ trait }) {
|
|
100
|
+
// Create a new element container and add some content
|
|
101
|
+
const el = document.createElement('div');
|
|
102
|
+
el.classList.add('gjs-one-bg');
|
|
103
|
+
// update the UI when a page is added/renamed/removed
|
|
104
|
+
editor.on('page', () => doRender(el));
|
|
105
|
+
doRender(el);
|
|
106
|
+
// this will be the element passed to onEvent and onUpdate
|
|
107
|
+
return el;
|
|
108
|
+
},
|
|
109
|
+
// Update the component based on UI changes
|
|
110
|
+
// `elInput` is the result HTMLElement you get from `createInput`
|
|
111
|
+
onEvent({ elInput, component, event }) {
|
|
112
|
+
const template = {
|
|
113
|
+
before: elInput.querySelector('#template-before').value,
|
|
114
|
+
replace: elInput.querySelector('#template-replace').value,
|
|
115
|
+
after: elInput.querySelector('#template-after').value,
|
|
116
|
+
attributes: elInput.querySelector('#template-attributes').value,
|
|
117
|
+
classname: elInput.querySelector('#template-classname').value,
|
|
118
|
+
style: elInput.querySelector('#template-style').value,
|
|
119
|
+
};
|
|
120
|
+
// Store the new template
|
|
121
|
+
if (Object.values(template).filter(val => !!val && !!cleanup(val)).length > 0) {
|
|
122
|
+
component.set(templateKey, template);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
component.set(templateKey);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
// Update UI on the component change
|
|
129
|
+
onUpdate({ elInput, component }) {
|
|
130
|
+
doRender(elInput);
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
// Make html attribute
|
|
134
|
+
// Quote strings, no values for boolean
|
|
135
|
+
function makeAttribute(key, value) {
|
|
136
|
+
switch (typeof value) {
|
|
137
|
+
case 'boolean': return value ? key : '';
|
|
138
|
+
default: return `${key}="${value}"`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// Remove empty lines in templates
|
|
142
|
+
function cleanup(template) {
|
|
143
|
+
return template
|
|
144
|
+
// split in lines
|
|
145
|
+
.split('\n')
|
|
146
|
+
// remove lines with only spaces
|
|
147
|
+
.map(line => line.trim())
|
|
148
|
+
.filter(line => !!line)
|
|
149
|
+
// put back together
|
|
150
|
+
.join('\n');
|
|
151
|
+
}
|
|
152
|
+
editor.on(ServerEvent.PUBLISH_START, () => {
|
|
153
|
+
// Insert templates
|
|
154
|
+
onAll(editor, c => {
|
|
155
|
+
const template = c.get(templateKey);
|
|
156
|
+
const toHTML = c.toHTML;
|
|
157
|
+
const classes = c.getClasses();
|
|
158
|
+
const before = cleanup(template?.before || '');
|
|
159
|
+
const replace = cleanup(template?.replace || '');
|
|
160
|
+
const after = cleanup(template?.after || '');
|
|
161
|
+
const classname = cleanup(template?.classname || '');
|
|
162
|
+
const style = cleanup(template?.style || '');
|
|
163
|
+
const attributes = cleanup(template?.attributes || '');
|
|
164
|
+
// Store the initial method
|
|
165
|
+
if (!c.has('tmpHtml'))
|
|
166
|
+
c.set('tmpHtml', toHTML);
|
|
167
|
+
// Override the method
|
|
168
|
+
c.toHTML = () => {
|
|
169
|
+
return `${before}${c.get('tagName') ? `<${c.get('tagName')}
|
|
170
|
+
${Object.entries(c.get('attributes')).map(([key, value]) => makeAttribute(key, value)).join(' ')}
|
|
171
|
+
${classes.length || classname ? `class="${classes.join(' ')} ${classname}"` : ''}
|
|
172
|
+
${attributes}
|
|
173
|
+
${style ? `style="${style}"` : ''}
|
|
174
|
+
>` : ''}${replace || c.getInnerHTML()}${c.get('tagName') ? `</${c.get('tagName')}>` : ''}${after}`;
|
|
175
|
+
};
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
editor.on(ServerEvent.PUBLISH_END, () => {
|
|
179
|
+
onAll(editor, c => {
|
|
180
|
+
// Restore the original method
|
|
181
|
+
c.toHTML = c.get('tmpHtml');
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../../../../src/ts/plugins/client/template.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,uCAAuC;AACvC,2DAA2D;AAC3D,+DAA+D;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEp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E,CAAA;gBACJ,CAAC,CAAA;YACH,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QACF,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,WAAW,EAAE,GAAG,EAAE;YACtC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE;gBAChB,8BAA8B;gBAC9B,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;YAC7B,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview This is where the default config is defined. Also use this object as an event emitter to listen to Silex events
|
|
3
|
+
* The values can be overriden with env vars or before passing the config to Silex
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @class default config for Silex server
|
|
7
|
+
*/
|
|
8
|
+
import { Config, Plugin } from '@silexlabs/silex-plugins';
|
|
9
|
+
import { Application } from 'express';
|
|
10
|
+
import { HostingConnector, StorageConnector } from './connectors/connectors';
|
|
11
|
+
import { Connector } from './connectors/connectors';
|
|
12
|
+
import { ConnectorType } from '../types';
|
|
13
|
+
/**
|
|
14
|
+
* Config types definitions
|
|
15
|
+
*/
|
|
16
|
+
export declare class ServerConfig extends Config {
|
|
17
|
+
expressOptions: {
|
|
18
|
+
jsonLimit: string;
|
|
19
|
+
textLimit: string;
|
|
20
|
+
urlencodedLimit: string;
|
|
21
|
+
sessionName: string;
|
|
22
|
+
sessionSecret: string;
|
|
23
|
+
cors: string;
|
|
24
|
+
};
|
|
25
|
+
port: string;
|
|
26
|
+
debug: boolean;
|
|
27
|
+
url: string;
|
|
28
|
+
userConfigPath: Plugin | undefined;
|
|
29
|
+
configFilePath: Plugin;
|
|
30
|
+
getConnectors(type?: ConnectorType | string | null): Connector[];
|
|
31
|
+
private storageConnectors;
|
|
32
|
+
addStorageConnector(storage: StorageConnector | StorageConnector[]): void;
|
|
33
|
+
setStorageConnectors(storageConnectors: StorageConnector[]): void;
|
|
34
|
+
getStorageConnectors(): StorageConnector[];
|
|
35
|
+
private hostingConnectors;
|
|
36
|
+
addHostingConnector(hosting: HostingConnector | HostingConnector[]): void;
|
|
37
|
+
setHostingConnectors(hostings: HostingConnector[]): void;
|
|
38
|
+
getHostingConnectors(): HostingConnector[];
|
|
39
|
+
/**
|
|
40
|
+
* Add routes to serve the client config file
|
|
41
|
+
*/
|
|
42
|
+
addRoutes(app: Application): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Load config files
|
|
45
|
+
* This is the main config file and the user config file
|
|
46
|
+
*/
|
|
47
|
+
loadConfigFiles(): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Load user config file
|
|
50
|
+
* This is the config file passed as env var CONFIG
|
|
51
|
+
*/
|
|
52
|
+
loadUserConfig(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Load .silex.js in the root folder
|
|
55
|
+
* This is the main config file
|
|
56
|
+
*/
|
|
57
|
+
loadSilexConfig(): Promise<void>;
|
|
58
|
+
initDefaultConnectors(): Promise<void>;
|
|
59
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Silex website builder, free/libre no-code tool for makers.
|
|
3
|
+
* Copyright (c) 2023 lexoyo and Silex Labs foundation
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* @fileoverview This is where the default config is defined. Also use this object as an event emitter to listen to Silex events
|
|
19
|
+
* The values can be overriden with env vars or before passing the config to Silex
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* @class default config for Silex server
|
|
23
|
+
*/
|
|
24
|
+
import { Config } from '@silexlabs/silex-plugins';
|
|
25
|
+
import { resolve } from 'path';
|
|
26
|
+
import { CLIENT_CONFIG_FILE_NAME } from '../constants';
|
|
27
|
+
import { readFile } from 'fs/promises';
|
|
28
|
+
import { toConnectorEnum } from './connectors/connectors';
|
|
29
|
+
import { FsStorage } from './connectors/FsStorage';
|
|
30
|
+
import { ConnectorType } from '../types';
|
|
31
|
+
import { FsHosting } from './connectors/FsHosting';
|
|
32
|
+
/**
|
|
33
|
+
* Config types definitions
|
|
34
|
+
*/
|
|
35
|
+
export class ServerConfig extends Config {
|
|
36
|
+
expressOptions = {
|
|
37
|
+
jsonLimit: process.env.SILEX_EXPRESS_JSON_LIMIT,
|
|
38
|
+
textLimit: process.env.SILEX_EXPRESS_TEXT_LIMIT,
|
|
39
|
+
urlencodedLimit: process.env.SILEX_EXPRESS_URLENCODED_LIMIT,
|
|
40
|
+
sessionName: process.env.SILEX_SESSION_NAME,
|
|
41
|
+
sessionSecret: process.env.SILEX_SESSION_SECRET,
|
|
42
|
+
cors: process.env.SILEX_CORS_URL,
|
|
43
|
+
};
|
|
44
|
+
port = process.env.SILEX_PORT;
|
|
45
|
+
debug = process.env.SILEX_DEBUG === 'true';
|
|
46
|
+
url = `${process.env.SILEX_PROTOCOL}://${process.env.SILEX_HOST}:${process.env.SILEX_PORT}`;
|
|
47
|
+
userConfigPath = process.env.SILEX_CONFIG;
|
|
48
|
+
configFilePath = resolve(__dirname, '../../../.silex.js');
|
|
49
|
+
// All connectors or just the storage or hosting connectors
|
|
50
|
+
getConnectors(type = null) {
|
|
51
|
+
// All connectors including storage and hosting connectors
|
|
52
|
+
if (!type) {
|
|
53
|
+
// Concat storage and hosting connectors
|
|
54
|
+
const allConnectors = this.getStorageConnectors().concat(this.getHostingConnectors());
|
|
55
|
+
// Remove duplicates (if a connector is both a storage and a hosting connector)
|
|
56
|
+
return [...new Set(allConnectors)];
|
|
57
|
+
}
|
|
58
|
+
// Convert to enum in case it is a string
|
|
59
|
+
const connectorType = toConnectorEnum(type.toString());
|
|
60
|
+
// Only one type of connector
|
|
61
|
+
switch (connectorType) {
|
|
62
|
+
case ConnectorType.HOSTING: return this.getHostingConnectors();
|
|
63
|
+
case ConnectorType.STORAGE: return this.getStorageConnectors();
|
|
64
|
+
default: throw new Error(`Unknown connector type ${type}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Storage connectors to store the website data and assets
|
|
68
|
+
storageConnectors = [];
|
|
69
|
+
addStorageConnector(storage) {
|
|
70
|
+
this.setStorageConnectors(this.storageConnectors.concat(storage));
|
|
71
|
+
}
|
|
72
|
+
setStorageConnectors(storageConnectors) {
|
|
73
|
+
this.storageConnectors = storageConnectors;
|
|
74
|
+
}
|
|
75
|
+
getStorageConnectors() {
|
|
76
|
+
return this.storageConnectors;
|
|
77
|
+
}
|
|
78
|
+
// Hosting connectors to publish the website online
|
|
79
|
+
hostingConnectors = [];
|
|
80
|
+
addHostingConnector(hosting) {
|
|
81
|
+
this.setHostingConnectors(this.hostingConnectors.concat(hosting));
|
|
82
|
+
}
|
|
83
|
+
setHostingConnectors(hostings) {
|
|
84
|
+
this.hostingConnectors = hostings;
|
|
85
|
+
}
|
|
86
|
+
getHostingConnectors() { return this.hostingConnectors; }
|
|
87
|
+
/**
|
|
88
|
+
* Add routes to serve the client config file
|
|
89
|
+
*/
|
|
90
|
+
async addRoutes(app) {
|
|
91
|
+
const path = process.env.SILEX_CLIENT_CONFIG;
|
|
92
|
+
if (path) {
|
|
93
|
+
console.log(`> Serving client side config ${path} at ${CLIENT_CONFIG_FILE_NAME}`);
|
|
94
|
+
try {
|
|
95
|
+
// Load the client config file
|
|
96
|
+
let clientConfig = (await readFile(path)).toString();
|
|
97
|
+
// Serve the config file
|
|
98
|
+
app.get(`/${CLIENT_CONFIG_FILE_NAME}`, async (req, res) => {
|
|
99
|
+
// Reload each time in debug mode
|
|
100
|
+
if (this.debug) {
|
|
101
|
+
console.log('[Debug mode] Reloading config file', path);
|
|
102
|
+
clientConfig = (await readFile(path)).toString();
|
|
103
|
+
}
|
|
104
|
+
// Send the config file
|
|
105
|
+
res
|
|
106
|
+
.contentType('application/javascript')
|
|
107
|
+
.send(clientConfig);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
console.error(`Error loading client config file ${path}`, e);
|
|
112
|
+
throw new Error(`Error loading client config file ${path}: ${e.message}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Load config files
|
|
118
|
+
* This is the main config file and the user config file
|
|
119
|
+
*/
|
|
120
|
+
async loadConfigFiles() {
|
|
121
|
+
// Load the user config file
|
|
122
|
+
await this.loadUserConfig();
|
|
123
|
+
// Load the main config file
|
|
124
|
+
await this.loadSilexConfig();
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Load user config file
|
|
128
|
+
* This is the config file passed as env var CONFIG
|
|
129
|
+
*/
|
|
130
|
+
async loadUserConfig() {
|
|
131
|
+
if (this.userConfigPath) {
|
|
132
|
+
console.log('> Loading user config', this.userConfigPath);
|
|
133
|
+
try {
|
|
134
|
+
// Initiate the process with the config file which is just another plugin
|
|
135
|
+
await this.addPlugin(this.userConfigPath, {});
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
throw new Error(`User config file ${this.userConfigPath} error: ${e.message}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Load .silex.js in the root folder
|
|
144
|
+
* This is the main config file
|
|
145
|
+
*/
|
|
146
|
+
async loadSilexConfig() {
|
|
147
|
+
console.log('> Loading config', this.configFilePath);
|
|
148
|
+
try {
|
|
149
|
+
// Initiate the process with the config file which is just another plugin
|
|
150
|
+
await this.addPlugin(this.configFilePath, {});
|
|
151
|
+
}
|
|
152
|
+
catch (e) {
|
|
153
|
+
console.log(e.requireStack[0]);
|
|
154
|
+
// Check if the error is about the config file not found and not another module not found in the config file
|
|
155
|
+
if (e.code === 'MODULE_NOT_FOUND' && (!e.requireStack || !e.requireStack.find(path => path === this.configFilePath))) {
|
|
156
|
+
console.info('> /!\\ Config file not found', this.configFilePath);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
throw new Error(`Error in config file ${this.configFilePath}: ${e.message}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async initDefaultConnectors() {
|
|
164
|
+
// Add default storage connectors
|
|
165
|
+
if (!this.storageConnectors.length) {
|
|
166
|
+
this.addStorageConnector(new FsStorage(null, {
|
|
167
|
+
path: process.env.SILEX_FS_ROOT,
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
// Add default hosting connectors
|
|
171
|
+
if (!this.hostingConnectors.length) {
|
|
172
|
+
this.addHostingConnector(new FsHosting(null, {
|
|
173
|
+
path: process.env.SILEX_FS_ROOT,
|
|
174
|
+
}));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../src/ts/server/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;;GAGG;AAEH;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAU,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;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CAAC,CAAA;SACJ;QACD,iCAAiC;QACjC,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE;YAClC,IAAI,CAAC,mBAAmB,CAAC,IAAI,SAAS,CAAC,IAAI,EAAE;gBAC3C,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;aAChC,CAAC,CAAC,CAAA;SACJ;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ConnectorFile, HostingConnector, ConnectorSession } from './connectors';
|
|
2
|
+
import { FsStorage } from './FsStorage';
|
|
3
|
+
import { ConnectorType, JobData, WebsiteId } from '../../types';
|
|
4
|
+
type FsSession = ConnectorSession;
|
|
5
|
+
export declare class FsHosting extends FsStorage implements HostingConnector<FsSession> {
|
|
6
|
+
connectorId: string;
|
|
7
|
+
displayName: string;
|
|
8
|
+
icon: string;
|
|
9
|
+
connectorType: ConnectorType;
|
|
10
|
+
publish(session: FsSession, id: WebsiteId, files: ConnectorFile[]): Promise<JobData>;
|
|
11
|
+
getUrl(session: FsSession, id: WebsiteId): Promise<string>;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Silex website builder, free/libre no-code tool for makers.
|
|
3
|
+
* Copyright (c) 2023 lexoyo and Silex Labs foundation
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
import { join } from 'path';
|
|
18
|
+
import { jobError, jobSuccess, startJob } from '../jobs';
|
|
19
|
+
import { FsStorage } from './FsStorage';
|
|
20
|
+
import { ConnectorType, JobStatus } from '../../types';
|
|
21
|
+
export class FsHosting extends FsStorage {
|
|
22
|
+
connectorId = 'fs-hosting';
|
|
23
|
+
displayName = 'File system hosting';
|
|
24
|
+
icon = 'data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22currentColor%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M6%202L6%2022%2018%2022%2018%207%2012%202%206%202Z%22%3E%3C%2Fpath%3E%3Cpath%20d%3D%22M18%202L12%202%2012%208%2018%208%2018%202Z%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E';
|
|
25
|
+
connectorType = ConnectorType.HOSTING;
|
|
26
|
+
async publish(session, id, files) {
|
|
27
|
+
const job = startJob(`Publishing to ${this.displayName}`);
|
|
28
|
+
job.logs = [[`Publishing to ${this.displayName}`]];
|
|
29
|
+
job.errors = [[]];
|
|
30
|
+
this.writeAssets(session, id, files, async ({ status, message }) => {
|
|
31
|
+
// Update the job status
|
|
32
|
+
job.status = status;
|
|
33
|
+
job.message = message;
|
|
34
|
+
job.logs[0].push(message);
|
|
35
|
+
if (status === JobStatus.SUCCESS) {
|
|
36
|
+
jobSuccess(job.jobId, message);
|
|
37
|
+
}
|
|
38
|
+
else if (status === JobStatus.ERROR) {
|
|
39
|
+
job.errors[0].push(message);
|
|
40
|
+
jobError(job.jobId, message);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return job;
|
|
44
|
+
}
|
|
45
|
+
async getUrl(session, id) {
|
|
46
|
+
const filePath = join(this.options.path, id, 'index.html');
|
|
47
|
+
const fileUrl = new URL(filePath, 'file://');
|
|
48
|
+
return fileUrl.toString();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=FsHosting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FsHosting.js","sourceRoot":"","sources":["../../../../../src/ts/server/connectors/FsHosting.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,aAAa,EAAW,SAAS,EAAiC,MAAM,aAAa,CAAA;AAQ9F,MAAM,OAAO,SAAU,SAAQ,SAAS;IACtC,WAAW,GAAG,YAAY,CAAA;IAC1B,WAAW,GAAG,qBAAqB,CAAA;IACnC,IAAI,GAAG,+aAA+a,CAAA;IACtb,aAAa,GAAG,aAAa,CAAC,OAAO,CAAA;IAErC,KAAK,CAAC,OAAO,CAAC,OAAkB,EAAE,EAAa,EAAE,KAAsB;QACrE,MAAM,GAAG,GAAG,QAAQ,CAAC,iBAAiB,IAAI,CAAC,WAAW,EAAE,CAAuB,CAAA;QAC/E,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,iBAAiB,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAA;QAClD,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAA;QACjB,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAC,MAAM,EAAE,OAAO,EAAC,EAAE,EAAE;YAC/D,wBAAwB;YACxB,GAAG,CAAC,MAAM,GAAG,MAAM,CAAA;YACnB,GAAG,CAAC,OAAO,GAAG,OAAO,CAAA;YACrB,GAAG,CAAC,IAAI,CAAC,CAAC,C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