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

Error with docsify option onlyCover=true #38

Open
BlackRose01 opened this issue Jun 2, 2022 · 2 comments
Open

Error with docsify option onlyCover=true #38

BlackRose01 opened this issue Jun 2, 2022 · 2 comments

Comments

@BlackRose01
Copy link

Hello,

The problem is that when I set the option "onlyCover" to true then docsify is in an infinite render loop.

In my opinion the plugin tries to set the theme switcher button on the cover but on the HTML page of the cover there is no hook for it. But now your script tries to find the HTML tag and use the property "setAttribute". Here it needs a check for NULL.

A Screenshot from the error

image

The content from the specified file

window.$docsify.plugins=[].concat((e,t)=>{let o={siteFont:"PT Sans",defaultTheme:"dark",codeFontFamily:"Roboto Mono, Monaco, courier, monospace",bodyFontSize:"17px",dark:{accent:"#42b983",toogleBackground:"#ffffff",background:"#091a28",toogleImage:"url(https://cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/icons/sun.svg)"},light:{accent:"#42b983",toogleBackground:"#091a28",background:"#ffffff",toogleImage:"url(https://cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/icons/moon.svg)"}};if(t.config.hasOwnProperty("darklightTheme")){for(var[r,d]of Object.entries(t.config.darklightTheme))"light"!==r&&"dark"!==r&&"defaultTheme"!==r&&(o[r]=d);for(var[r,d]of Object.entries(o))"light"!==r&&"dark"!==r&&(o[r]=d,document.documentElement.style.setProperty("--"+r,d));if(t.config.darklightTheme.hasOwnProperty("dark"))for(var[r,d]of Object.entries(t.config.darklightTheme.dark))o.dark[r]=d;if(t.config.darklightTheme.hasOwnProperty("light"))for(var[r,d]of Object.entries(t.config.darklightTheme.light))o.light[r]=d}else for(var[r,d]of Object.entries(o))"light"!==r&&"dark"!==r&&(o[r]=d,document.documentElement.style.setProperty("--"+r,d));window.matchMedia("(prefers-color-scheme: dark)").matches?o.defaultTheme="dark":window.matchMedia("(prefers-color-scheme: light)").matches&&(o.defaultTheme="light");var i=e=>{if(document.getElementById("docsify-darklight-theme").setAttribute("data-link-title",e),document.getElementById("docsify-darklight-theme").click(),localStorage.setItem("DARK_LIGHT_THEME",e),o.defaultTheme=e,"light"==e)for(var[t,r]of Object.entries(o.light))document.documentElement.style.setProperty("--"+t,r);else if("dark"==e)for(var[t,r]of Object.entries(o.dark))document.documentElement.style.setProperty("--"+t,r)};e.afterEach((function(e,t){t(e='<div id="docsify-darklight-theme"><p>.</p></div>'+e)})),e.doneEach((function(){let e=localStorage.getItem("DARK_LIGHT_THEME");"light"==e||"dark"==e?(o.defaultTheme=e,i(o.defaultTheme)):i(o.defaultTheme),document.getElementById("docsify-darklight-theme").addEventListener("click",(function(){"light"===o.defaultTheme?i("dark"):i("light")}))}))},window.$docsify.plugins);
@BlackRose01

This comment was marked as outdated.

@BlackRose01
Copy link
Author

Maybe a quick-and-dirty fix for this problem

window.$docsify.plugins = [].concat((e, t) => {
    let o = {
        siteFont: "PT Sans",
        defaultTheme: "dark",
        codeFontFamily: "Roboto Mono, Monaco, courier, monospace",
        bodyFontSize: "17px",
        dark: { accent: "#42b983", toogleBackground: "#ffffff", background: "#091a28", toogleImage: "url(https://cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/icons/sun.svg)" },
        light: { accent: "#42b983", toogleBackground: "#091a28", background: "#ffffff", toogleImage: "url(https://cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/icons/moon.svg)" },
    };
    if (t.config.hasOwnProperty("darklightTheme")) {
        for (var [r, d] of Object.entries(t.config.darklightTheme)) "light" !== r && "dark" !== r && "defaultTheme" !== r && (o[r] = d);
        for (var [r, d] of Object.entries(o)) "light" !== r && "dark" !== r && ((o[r] = d), document.documentElement.style.setProperty("--" + r, d));
        if (t.config.darklightTheme.hasOwnProperty("dark")) for (var [r, d] of Object.entries(t.config.darklightTheme.dark)) o.dark[r] = d;
        if (t.config.darklightTheme.hasOwnProperty("light")) for (var [r, d] of Object.entries(t.config.darklightTheme.light)) o.light[r] = d;
    } else for (var [r, d] of Object.entries(o)) "light" !== r && "dark" !== r && ((o[r] = d), document.documentElement.style.setProperty("--" + r, d));
    window.matchMedia("(prefers-color-scheme: dark)").matches ? (o.defaultTheme = "dark") : window.matchMedia("(prefers-color-scheme: light)").matches && (o.defaultTheme = "light");
    var i = (e) => {
        if (
            document.getElementById("docsify-darklight-theme").setAttribute("data-link-title", e), document.getElementById("docsify-darklight-theme").click(), localStorage.setItem("DARK_LIGHT_THEME", e), (o.defaultTheme = e), "light" == e
        )
            for (var [t, r] of Object.entries(o.light)) document.documentElement.style.setProperty("--" + t, r);
        else if ("dark" == e) for (var [t, r] of Object.entries(o.dark)) document.documentElement.style.setProperty("--" + t, r);
    };
    e.afterEach((e, t) => t((e = '<div id="docsify-darklight-theme"><p>.</p></div>' + e)));
    e.doneEach((e = localStorage.getItem("DARK_LIGHT_THEME")) => {
#### FIX START
        if (document.getElementById("docsify-darklight-theme") === null) return;
#### FIX END
        "light" == e || "dark" == e ? ((o.defaultTheme = e), i(o.defaultTheme)) : i(o.defaultTheme),
            document.getElementById("docsify-darklight-theme").addEventListener("click", () => "light" === o.defaultTheme ? i("dark") : i("light"));
    });
}, window.$docsify.plugins);

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

No branches or pull requests

1 participant