observablehq / feedback

Customer submitted bugs and feature requests
42 stars 3 forks source link

Make url slug and cell name available within a cell #554

Open resmartiZH opened 1 year ago

resmartiZH commented 1 year ago

Is your feature request related to a problem? Please describe. I have generated some functions which can be considered as a generalized chart. The function can now be importet in a new notebook an configured eighter manually or through a json from an api to show specific data in an instance of this chart. I then embed this chart into a cms through the standard embed options. I have also implemented several export options. What's missing for the embeded chart in our cms from the export dropdown is the option to generate an embed code and allow someone else to get an embed code from the site where chart is embeded.

Describe the solution you'd like To generate an embed code outside of the observablehq web interface the url slug an the cell name of a cell needs to be available. If the url slug and the cell name would be available as a variable in a cell the embed code could be generated by a custom function. So I'm imagining a variable like width which is available within a cell to get the url slug of a notebook and an other variable to get the cells name.

Describe alternatives you've considered One solution to generate the embed code would be to provide the url-slug and the cell name to the function manually. That would work but would mean aditional parameters to the function which generates the chart. This leads to a source for error and more maintenance work on the embedded charts in the future. It seems silly to manuall tell the system information that the system obviously allready has.

Additional context Example of a generalized chart: https://observablehq.com/@resmartizh/prototyp-karte-mit-linechart. The main function in this case would be makeMapLine

wiltsecarpenter commented 1 year ago

FYI: You should be able to access the current notebook slog with document.baseURI. You can also use location.search and location.hash to get the Url parameters (?...) and anchor (#...).

Be sure and check out the description of "with" on the imports documentation page: https://observablehq.com/@observablehq/import

resmartiZH commented 1 year ago

@wiltsecarpenter thanks for the imput. document.baseURI works as long as the code is run within observablehq.com, but once a cell is embeded in an other website using the javascript runtime document.baseURI becomes the URI of the website, which doesn't contain the url-slug anymore.