libs/ng-lib/src/lib/scully-content/scully-content.component.js
/**
     * Loads the static content from scully into the view
     * Will fetch the content from sibling links with xmlHTTPrequest
     */
Loads the static content from scully into the view
Will fetch the content from sibling links with xmlHTTPrequest
Loads the static content from scully into the view Will fetch the content from sibling links with xmlHTTPrequest
handlePage() {
        return __awaiter(this, void 0, void 0, function* () {
            const curPage = basePathOnly(location.href);
            if (lastHandled === curPage) {
                return;
            }
            lastHandled = curPage;
            const template = document.createElement('template');
            const currentCssId = this.getCSSId(this.elm);
            if (window.scullyContent) {
                const htmlString = window.scullyContent.html;
                if (currentCssId !== window.scullyContent.cssId) {
                    template.innerHTML = htmlString.split(window.scullyContent.cssId).join(currentCssId);
                }
                else {
                    template.innerHTML = htmlString;
                }
            }
            else {
                yield fetchHttp(curPage + '/index.html', 'text')
                    .catch((e) => {
                    if (isDevMode()) {
                        const uri = new URL(location.href);
                        const url = `${this.conf.baseURIForScullyContent}/${basePathOnly(uri.pathname)}/index.html`;
                        return fetchHttp(url, 'text');
                    }
                    else {
                        return Promise.reject(e);
                    }
                })
                    .then((html) => {
                    try {
                        const htmlString = html.split(scullyBegin)[1].split(scullyEnd)[0];
                        if (htmlString.includes('_ngcontent')) {
                            const atr = '_ngcontent' + htmlString.split('_ngcontent')[1].split('=')[0];
                            template.innerHTML = htmlString.split(atr).join(currentCssId);
                        }
                        else {
                            template.innerHTML = htmlString;
                        }
                    }
                    catch (e) {
                        template.innerHTML = `<h2 id="___scully-parsing-error___">Sorry, could not parse static page content</h2>
            <p>This might happen if you are not using the static generated pages.</p>`;
                    }
                })
                    .catch((e) => {
                    template.innerHTML = '<h2 id="___scully-parsing-error___">Sorry, could not load static page content</h2>';
                    console.error('problem during loading static scully content', e);
                });
            }
            const parent = this.elm.parentElement || document.body;
            const begin = document.createComment('scullyContent-begin');
            const end = document.createComment('scullyContent-end');
            parent.insertBefore(begin, this.elm);
            parent.insertBefore(template.content, this.elm);
            parent.insertBefore(end, this.elm);
            setTimeout(() => document.querySelectorAll('[href]').forEach(this.upgradeToRoutelink.bind(this)), 10);
        });
    }
handlePage ( ) { return __awaiter ( this , void 0 , void 0 , function * ( ) { const curPage = basePathOnly ( location . href ) ; if ( lastHandled === curPage ) { return ; } lastHandled = curPage ; const template = document . createElement ( 'template' ) ; const currentCssId = this . getCSSId ( this . elm ) ; if ( window . scullyContent ) { const htmlString = window . scullyContent . html ; if ( currentCssId !== window . scullyContent . cssId ) { template . innerHTML = htmlString . split ( window . scullyContent . cssId ) . join ( currentCssId ) ; } else { template . innerHTML = htmlString ; } } else { yield fetchHttp ( curPage + '/index.html' , 'text' ) . catch ( ( e ) => { if ( isDevMode ( ) ) { const uri = new URL ( location . href ) ; const url = ` ${ this . conf . baseURIForScullyContent } ${ basePathOnly ( uri . pathname ) } ` ; return fetchHttp ( url , 'text' ) ; } else { return Promise . reject ( e ) ; } } ) . then ( ( html ) => { try { const htmlString = html . split ( scullyBegin ) [ 1 ] . split ( scullyEnd ) [ 0 ] ; if ( htmlString . includes ( '_ngcontent' ) ) { const atr = '_ngcontent' + htmlString . split ( '_ngcontent' ) [ 1 ] . split ( '=' ) [ 0 ] ; template . innerHTML = htmlString . split ( atr ) . join ( currentCssId ) ; } else { template . innerHTML = htmlString ; } } catch ( e ) { template . innerHTML = ` ` ; } } ) . catch ( ( e ) => { template . innerHTML = '<h2 id="___scully-parsing-error___">Sorry, could not load static page content</h2>' ; console . error ( 'problem during loading static scully content' , e ) ; } ) ; } const parent = this . elm . parentElement || document . body ; const begin = document . createComment ( 'scullyContent-begin' ) ; const end = document . createComment ( 'scullyContent-end' ) ; parent . insertBefore ( begin , this . elm ) ; parent . insertBefore ( template . content , this . elm ) ; parent . insertBefore ( end , this . elm ) ; setTimeout ( ( ) => document . querySelectorAll ( '[href]' ) . forEach ( this . upgradeToRoutelink . bind ( this ) ) , 10 ) ; } ) ; }
Loads the static content from scully into the view
 Will fetch the content from sibling links with xmlHTTPrequest
Loads the static content from scully into the view Will fetch the content from sibling links with xmlHTTPrequest
/**
                 * Due to the fix we needed for #311
                 * it might happen that this routine is called
                 * twice for the same page.
                 * this code will make sure the second one is ignored.
                 */ /** upgrade existing static content */ /** replace the angular cssId */ /**
                 *   NOTE
                 * when updateting the texts for the errors, make sure you leave the
                 *  `id="___scully-parsing-error___"`
                 * in there. That way users can detect rendering errors in their CI
                 * on a reliable way.
                 */ /** in devmode (usually in `ng serve`) check the scully server for the content too */ /** update the angular cssId */ /** insert the whole thing just before the `<scully-content>` element */ /** upgrade all hrefs to simulated routelinks (in next microtask) */ // document.querySelectorAll('[href]').forEach(this.upgradeToRoutelink.bind(this));