Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make featured notebook sources a frontend launch param #2412

Merged
merged 9 commits into from
Dec 13, 2022

Conversation

fonsp
Copy link
Owner

@fonsp fonsp commented Dec 13, 2022

This is necessary to render the featured notebooks directly on our WIP website :)

You can test it:

http://localhost:1234/?featured_source_url=https%3A%2F%2Fmit-c25.netlify.app%2Fpluto_export.json

This will show the regular index page, but with the notebooks from https://mit-c25.netlify.app/ as source! (These don't have images, because no image URLs are given in the frontmatters in that repository.)

Matching PlutoSliderServer PR:

@github-actions
Copy link
Contributor

Try this Pull Request!

Open Julia and type:

julia> import Pkg
julia> Pkg.activate(temp=true)
julia> Pkg.add(url="https://github.com/fonsp/Pluto.jl", rev="featured-sources-as-index-launch-param")
julia> using Pluto

// Option 2: configured through url and integrity strings
(launch_params.featured_source_url
? [{ url: launch_params.featured_source_url, integrity: launch_params.featured_source_integrity }]
: // Option 3: default
Copy link
Owner Author

@fonsp fonsp Dec 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pankgeorg You could add an option between 2 and 3 to overload the sources with those from juliahub. Something like:

// Option 1: configured directly
launch_params.featured_sources ??
// Option 2: configured through url and integrity strings
(launch_params.featured_source_url
    ? [{ url: launch_params.featured_source_url, integrity: launch_params.featured_source_integrity }]
    : // Option 3: overloaded by environment
      environment.featured_sources ??
        // Option 4: default
        default_featured_sources.sources

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this PR adds the launch_params.featured_sources config, but for JH integration the environment seems better suited, right?

@fonsp fonsp merged commit 72d7b68 into main Dec 13, 2022
@fonsp fonsp deleted the featured-sources-as-index-launch-param branch December 13, 2022 23:24
@BioTurboNick
Copy link
Contributor

How do we use this? I was thinking it would be an argument to Pluto.run() somewhere but I'm not seeing anything like that. Do we need to hand-generate the json file being used? Or I'm misunderstanding what this is for.

I was hoping it could be used to present a series of read-only templates that people can save and then edit.

@fonsp fonsp added the frontend Concerning the HTML editor label Sep 27, 2023
@BioTurboNick
Copy link
Contributor

@fonsp Just checking on this - is this parameter exposed to the Pluto.run() method somehow?

@fonsp fonsp added the publishing Notebooks as static documents on the web label Oct 30, 2023
@fonsp
Copy link
Owner Author

fonsp commented Oct 30, 2023

Hey Nick!

This is a "launch parameter" to the Pluto GUI, which is different from the Pluto.run(...) options, which mostly control the server. (The reason that there is a second set of settings is that you can also use the Pluto GUI without a server, like in an HTML export.)

The list of launch parameters is here:

There are three ways you can set the launch parameters:

  • As global javascript variables, defined before the editor loads. This is used when you click the "Export HTML" button inside Pluto. Generate an HTML and open it with a text editor to see how it works.
  • As URL parameters: one place where this is used is when you click on a featured notebook in the Pluto main menu. It opens editor.html, but the path to the statefile, notebook file, etc is given with URL query paramaters. Open a featured notebook and look at the URL to see it.
  • As HTML attributes to the <pluto-editor> web component. This is used in https://computationalthinking.mit.edu/ . Check out view-source:https://computationalthinking.mit.edu/Fall23/images_abstractions/abstraction/ to see an example.

For you use case, you probably want to generate a URL like I did in my original post and give that to people (use encodeURIComponent in JS or URIs.jl), or you can create an online website like featured.plutojl.org where people download the template files from.

The JSON file is generated automatically by PlutoSliderServer since JuliaPluto/PlutoSliderServer.jl#68 . JuliaPluto/PlutoSliderServer.jl#100 makes it possible to run a website like featured.plutojl.org yourself, where you see an index page in the style of Pluto's main menu. Check out https://github.com/JuliaPluto/featured to learn more about frontmatter and pluto_export_configuration.json.

@BioTurboNick
Copy link
Contributor

Thanks for the all the details! I'm not great with JS/HTML so I'm struggling a bit.

I'd rather not change what URL people use, I just want to provide a different default for the main page. Is it that the frontend can't really be modified by the server? Can I just change the source file, like .julia/packages/Pluto/xxxxx? I guess I'd just have to beware of updates reverting it...

@fonsp
Copy link
Owner Author

fonsp commented Oct 31, 2023

Maybe you could just fork Pluto and edit the featured_sources.js file?

@BioTurboNick
Copy link
Contributor

I'd rather not have to maintain a repo just for this.

@fonsp
Copy link
Owner Author

fonsp commented Nov 1, 2023

Alright, let me know if I can help in another way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend Concerning the HTML editor publishing Notebooks as static documents on the web
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants