fastn-stack / fastn

🚧 (Alpha stage software) fastn - better way to build websites 🚧
https://fastn.com
GNU Affero General Public License v3.0
467 stars 36 forks source link

Need new syntax for value passed in `js` common attribute #967

Open Arpita-Jaiswal opened 1 year ago

Arpita-Jaiswal commented 1 year ago

Currently, the syntax to pass value in js is:

-- ftd.text: Hello
js: bar.js:type=module

Problems:

The below code will not work:

-- ftd.text: Hello
js: https://unpkg.com/web3modal@1.9.0/dist/index.js:type=text/javascript

So we need to remove http or https protocol from the link.

-- ftd.text: Hello
js: //unpkg.com/web3modal@1.9.0/dist/index.js:type=text/javascript

Therefore, we need a better syntax for this.

Some suggestions for new syntax

Syntax 1:

-- ftd.text: Hello
js: { src = bar.js, type = module }

Syntax 2:

-- ftd.text: Hello
js:  bar.js | type = module

We are open for any syntax suggestions

amitu commented 1 year ago

How about both js: and js-module:. What possible values we can pass to type?

amitu commented 1 year ago

As per MDN, the possible values of type are module, importmap, blocking, and any valid content type can be used as type if the content of script tag is not meant to be JavaScript.

For our purpose only type: module is relevant. So we will do js and js-module.

HarshikaAdarsh commented 1 year ago

we can use some other alternatives like

syntax 1) -- ftd.text: Hello js: src:bar.js module

Here we have use colon (:) to separate the key-value pairs. The src key represents the source file (bar.js), and the module key indicates the module type.

syntax 2) -- ftd.text: Hello js: bar.js(module)

source file (bar.js) followed by the module type (module).

To include the HTTP or HTTPS protocol in the link while using the simplified syntax

js: https://anything.com/bar.js(module)

amitu commented 1 year ago

We have one more option:

js: https://anything.com/bar.js as module
HarshikaAdarsh commented 1 year ago

that would be more simple and easy to understand

amitu commented 1 year ago

Why don't you take a stab at implementing it @HarshikaAdarsh? Should not be too easy. If you are interested you can come say hello on our discord, #fastn-contributors channel and we can guide you more.

ashutosh887 commented 1 year ago

@amitu @Arpita-Jaiswal Let me work on this issue