Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pageviews:
# light — Use the light color scheme
# dark — Use the dark color scheme
#
theme_mode: dark
theme_mode:

# The CDN endpoint for media resources.
# Notice that once it is assigned, the CDN url
Expand Down
13 changes: 13 additions & 0 deletions _includes/metadata-hook.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Restore the desktop sidebar preference before the first paint. -->
<script>
(() => {
try {
const desktop = window.matchMedia('(min-width: 850px)').matches;
const collapsed = localStorage.getItem('sidebar-collapsed') === 'true';
document.documentElement.toggleAttribute('data-sidebar-collapsed', desktop && collapsed);
} catch (_) {
// Storage can be unavailable in strict privacy modes; the sidebar stays open.
}
})();
</script>
<script defer src="{{ '/assets/js/sidebar-controls.js' | relative_url }}"></script>
23 changes: 23 additions & 0 deletions _plugins/reliable-mathjax-loading.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

# Chirpy loads both the MathJax configuration and runtime with `async`.
# That makes their execution order nondeterministic: the runtime can start
# before the configuration that enables `$...$` inline delimiters.
module ReliableMathJaxLoading
CONFIG_PATTERN = %r{<script async src="([^"]*/assets/js/data/mathjax\.js)"></script>}
POLYFILL_PATTERN = %r{<script async src="(https://cdnjs\.cloudflare\.com/polyfill/[^"]+)"></script>}
RUNTIME_PATTERN = %r{<script id="MathJax-script" async src="([^"]+)"></script>}

def self.rewrite(html)
html
.sub(CONFIG_PATTERN, '<script src="\1"></script>')
.sub(POLYFILL_PATTERN, '<script defer src="\1"></script>')
.sub(RUNTIME_PATTERN, '<script id="MathJax-script" defer src="\1"></script>')
end
end

Jekyll::Hooks.register %i[pages documents], :post_render do |document|
next unless document.output_ext == '.html' && document.data['math']

document.output = ReliableMathJaxLoading.rewrite(document.output)
end
Loading