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

include is not very efficient #1034

Open
GuillaumeGomez opened this issue May 7, 2024 · 3 comments
Open

include is not very efficient #1034

GuillaumeGomez opened this issue May 7, 2024 · 3 comments

Comments

@GuillaumeGomez
Copy link
Contributor

Currently, code like:

<script>{%- include "theme.js" -%}</script>

generates:

        ::std::write!(
            writer,
            "</title>\n\n        <script>",
            expr2 = &::askama::MarkupDisplay::new_unsafe(&(self.csp_nonce), ::askama::Html),
        )?;
        include_bytes! ("/home/imperio/rust/docs.rs/templates/theme.js");
        writer.write_str("(function() {\n    function applyTheme(theme) {\n        if (theme) {\n            document.documentElement.dataset.docsRsTheme = theme;\n        }\n    }\n\n    window.addEventListener(\"storage\", ev => {\n        if (ev.key === \"rustdoc-theme\") {\n            applyTheme(ev.newValue);\n        }\n    });\n\n    // see ./storage-change-detection.html for details\n    window.addEventListener(\"message\", ev => {\n        if (ev.data && ev.data.storage && ev.data.storage.key === \"rustdoc-theme\") {\n            applyTheme(ev.data.storage.value);\n        }\n    });\n\n    applyTheme(window.localStorage.getItem(\"rustdoc-theme\"));\n})();")?;
        writer.write_str("</script>")?;

It duplicates the content of the file instead of just doing write!("<script>{}</script>", include_str!("theme.js"));.

Planning to send a fix for this "soon".

@GuillaumeGomez
Copy link
Contributor Author

After looking into it a bit more, I don't think we can do much about it since there is no macro to just check if a file was modified without including its content... So unless someone has a better idea, I'll just close this issue.

@Kijewski
Copy link
Contributor

Will look into it.

@Kijewski Kijewski reopened this May 14, 2024
@GuillaumeGomez
Copy link
Contributor Author

I'm curious to see what you will come up with. 😃

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

2 participants