plugins: external URLs support for frontend_js and frontend_css

Massimo Melina committed May 7, 2023 at 12:00 UTC 10ca8b92feae1ada8ec8a90d83167933dea5e99e
3 files changed +8 -5
dev-plugins.md
+3
@@ -31,7 +31,9 @@ All the following properties are essentially optional.
31 - `version: number` use progressive numbers to distinguish each release. This must go in `exports`.
32 - `apiRequired: number | [min:number,max:number]` declare version(s) for which the plugin is designed for. You'll find api version in `src/const.ts`. This must go in `exports`.
33 - `frontend_css: string | string[]` path to one or more css files that you want the frontend to load. These are to be placed in the `public` folder (refer below).
34 + You can also include external files, by entering a full URL.
35 - `frontend_js: string | string[]` path to one or more js files that you want the frontend to load. These are to be placed in the `public` folder (refer below).
36 + You can also include external files, by entering a full URL.
37 - `middleware: (Context) => void | true | function` a function that will be used as a middleware: use this to interfere with http activity.
38
39 ```js
@@ -238,6 +240,7 @@ HFS will scan through them in inverted alphabetical order searching for a compat
240 ## API version history
241
242 - 8.1 (v0.45.0) should have been 0.44.0 but forgot to update number
243 + - full URL support for frontend_js and frontend_css
244 - entry.cantOpen
245 - HFS.apiCall, reloadList, logout, h, React, state, t, _, dialogLib
246 - second parameter of onEvent is now deprecated
src/const.ts
+1 -1
@@ -17,7 +17,7 @@ export const VERSION = pkg.version
17 export const DAY = 86_400_000
18 export const SESSION_DURATION = Number(process.env.SESSION_DURATION) * 1000 || DAY
19
20 -export const API_VERSION = 8.1 // entry.uri + script.plugin
20 +export const API_VERSION = 8.1 // entry.uri + script.plugin + absolute frontend_*
21 export const COMPATIBLE_API_VERSION = 1 // while changes in the api are not breaking, this number stays the same, otherwise it is made equal to API_VERSION
22
23 export const HFS_REPO = 'rejetto/hfs'
src/serveGuiFiles.ts
+4 -4
@@ -118,13 +118,13 @@ async function treatIndex(ctx: Koa.Context, filesUri: string, body: string) {
118 _.map(configs, (v,k) => `--${pluginName}-${k}: ${serializeCss(v)};`).join('\n')).join('')}
119 }
120 </style>
121 - ${!isFrontend ? '' : mapPlugins((plug,k) =>
121 + ${!isFrontend ? '' : mapPlugins((plug,id) =>
122 plug.frontend_css?.map(f =>
123 - `<link rel='stylesheet' type='text/css' href='${pub + k + '/' + f}' plugin=${JSON.stringify(k)}/>`))
123 + `<link rel='stylesheet' type='text/css' href='${f.includes('//') ? f : pub + id + '/' + f}' plugin=${JSON.stringify(id)}/>`))
124 .flat().filter(Boolean).join('\n')}
125 - ${!isFrontend ? '' : mapPlugins((plug,k) =>
125 + ${!isFrontend ? '' : mapPlugins((plug,id) =>
126 plug.frontend_js?.map(f =>
127 - `<script defer plugin=${JSON.stringify(k)} src='${pub + k + '/' + f}'></script>`))
127 + `<script defer plugin=${JSON.stringify(id)} src='${f.includes('//') ? f : pub + id + '/' + f}'></script>`))
128 .flat().filter(Boolean).join('\n')}
129 `)
130 if (isFrontend)