Skip to content

Conversation

Lucca-mito
Copy link

@Lucca-mito Lucca-mito commented Oct 13, 2024

Summary

First-class support for adding custom scripts to a DocC-generated website. These may be local scripts, in which case the website will continue to work offline, or they may be external scripts at a user-specified URL. This support is in the form of a custom-scripts.json file, the scripting analog of theme-settings.json.

Full pitch: https://forums.swift.org/t/pitch-support-for-custom-scripts-in-docc/75357.

Dependencies

Corresponding change in swift-docc.

Testing

  • Unit tests added.
  • To test the feature end-to-end, you'll need to use the version of swift-docc with the corresponding changes. Follow the steps in the pitch for adding any custom scripts you want to your documentation website (your own scripts, or a library such as MathJax or D2). If you want a specific example to test the implementation:
    • Copy the custom-scripts.json and the custom mathjax-config.js script (shown in the pitch) to your documentation catalog.
    • Add LaTeX expressions to your in-source documentation.
    • docc convert the documentation catalog with your custom scripts. Observe that the modified swift-docc copied custom-scripts.json and the custom scripts into the documentation archive.
    • Preview the documentation archive. Observe that the LaTeX expressions are rendered on the page.
  • Live demo: see here and here. The LaTeX expressions in the documentation text are dynamically rendered into equations via custom scripts.

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added tests
  • Ran npm test, and it succeeded
  • Updated documentation if necessary
    • Existing documentation does not need to change. New documentation for this feature will be added after the design and implementation are finalized.

Copy link
Contributor

@mportiz08 mportiz08 left a comment

Choose a reason for hiding this comment

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

Very cool to see this in action, and I know this kind of customization will be super useful to some developers. Nice work!

I'm very interested to hear other feedback from the community on your forums pitch.

Here's some initial feedback on the renderer implementation itself in the meantime.

Also: fetchText now shares a backing helper function with fetchData. This avoids code repetition and helps fetchText handle more edge cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants