fastn icon indicating copy to clipboard operation
fastn copied to clipboard

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

Open Arpita-Jaiswal opened this issue 2 years ago • 7 comments

Currently, the syntax to pass value in js is:

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

Problems:

  • First of all the syntax could be better.
  • Also, this syntax limits us to not passing http or https protocol in the link.

The below code will not work:

-- ftd.text: Hello
js: https://unpkg.com/[email protected]/dist/index.js:type=text/javascript

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

-- ftd.text: Hello
js: //unpkg.com/[email protected]/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

Arpita-Jaiswal avatar Jun 14 '23 08:06 Arpita-Jaiswal

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

amitu avatar Jun 14 '23 09:06 amitu

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.

amitu avatar Jun 24 '23 05:06 amitu

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)

HarshikaAdarsh avatar Jul 08 '23 03:07 HarshikaAdarsh

We have one more option:

js: https://anything.com/bar.js as module

amitu avatar Jul 08 '23 04:07 amitu

that would be more simple and easy to understand

HarshikaAdarsh avatar Jul 08 '23 08:07 HarshikaAdarsh

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.

amitu avatar Jul 08 '23 12:07 amitu

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

ashutosh887 avatar Aug 18 '23 03:08 ashutosh887