angularjson-ldrendertron

Rendertron & <script> tags


I started using Rendertron for an Angular 6 app. I noticed it does not render the <script> tags. Do you know how to configure it to do so?

The reason I need this is for the JSON-LD markup.

I have the injectShadyDom set to true as well; it defaults to false. I didn't know if this would assist at all, although this is more for web components.


Solution

  • Yes, this is possible with updates to the source code. There is a stripPage() function which removes all script tags. This function is on line 32 of the renderer.ts file. With a small hack, I can skip tags with type="application/ld+json". Time to clean it up, make it configurable, and submit a pull request!

    Origional Function

    function stripPage() {
      const elements = document.querySelectorAll('script, link[rel=import]');
      for (const e of Array.from(elements)) {
        e.remove();
      }
    }
    

    Modified Function

        function stripPage() {
            const elements = document.querySelectorAll('script, link[rel=import]');
            for (const e of Array.from(elements)) {
                if (e.getAttribute('type') !== 'application/ld+json') {
                    e.remove();
                }
            }
        }