Skip to content

Commit df150c4

Browse files
committed
[change] JS/CSS optimizations
- Merged dark-theme.js in theme.js - Renamed index-top-feature.js to just index.js (used in index.html) - Load the minified version of index.js instead of the full one - Load the pruned/minified version of the CSS
1 parent 5ac2826 commit df150c4

File tree

6 files changed

+16
-17
lines changed

6 files changed

+16
-17
lines changed

content/pages/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,6 @@ <h2 class="title is-size-3 is-size-4-mobile is-spaced">Try the demo</h2>
467467
<script>
468468
const featuresBasePath = "{{ SITEURL }}/features/";
469469
</script>
470-
<script src="{{ SITEURL }}/theme/js/index-top-feature.js"></script>
470+
<script src="{{ SITEURL }}/theme/js/index.min.js?v=1"></script>
471471
</body>
472472
</html>

js/dark-theme.js

Lines changed: 0 additions & 10 deletions
This file was deleted.
File renamed without changes.

js/theme.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,14 @@ document.addEventListener("DOMContentLoaded", () => {
3131
});
3232
});
3333
});
34+
35+
// Dark theme: apply theme based on stored preference or system setting
36+
const storedTheme = localStorage.getItem("theme");
37+
if (storedTheme) {
38+
document.documentElement.setAttribute("data-theme", storedTheme);
39+
} else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
40+
document.documentElement.classList.add("dark");
41+
document.documentElement.setAttribute("data-theme", "dark");
42+
} else {
43+
document.documentElement.setAttribute("data-theme", "light");
44+
}

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
"build:js": "babel js/*.js js/activity/feed.js --out-dir theme/static/js && concat js/activity/*.min.js theme/static/js/feed.js -o theme/static/js/activity.js && rm theme/static/js/feed.js",
1212
"minify:activity": "terser theme/static/js/activity.js --config-file .terserrc -o theme/static/js/activity.min.js",
1313
"minify:theme": "terser theme/static/js/theme.js --config-file .terserrc -o theme/static/js/theme.min.js",
14-
"minify:dark-theme": "terser theme/static/js/dark-theme.js --config-file .terserrc -o theme/static/js/dark-theme.min.js",
1514
"minify:faq": "terser theme/static/js/faq.js --config-file .terserrc -o theme/static/js/faq.min.js",
1615
"minify:modal": "terser theme/static/js/modal.js --config-file .terserrc -o theme/static/js/modal.min.js",
17-
"minify:top-feature": "terser theme/static/js/index-top-feature.js --config-file .terserrc -o theme/static/js/index-top-feature.min.js",
18-
"minify": "npm run minify:activity && npm run minify:theme && npm run minify:dark-theme && npm run minify:faq && npm run minify:modal && npm run minify:top-feature",
16+
"minify:index": "terser theme/static/js/index.js --config-file .terserrc -o theme/static/js/index.min.js",
17+
"minify": "npm run minify:activity && npm run minify:theme && npm run minify:faq && npm run minify:modal && npm run minify:index",
1918
"build": "npm run build:css && npm run build:js && npm run minify",
2019
"serve": "http-server -a 0.0.0.0 -p 8080 ./output/",
2120
"start": "concurrently \"npm run serve\" \"npm run build:sass\" \"npm run build:postcss\"",

theme/templates/base.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
content="width=device-width, initial-scale=1, shrink-to-fit=no"
1515
/>
1616
{% block extra_meta %}{% endblock %}
17-
<link rel="stylesheet" href="{{ SITEURL }}/theme/css/theme.css?v=2" />
17+
<link rel="stylesheet" href="{{ SITEURL }}/theme/css/theme.min.css?v=1" />
1818
<link
1919
rel="icon"
2020
type="image/x-icon"
@@ -90,7 +90,6 @@
9090
title="{{ SITENAME|striptags }} Tags RSS Feed"
9191
/>
9292
{% endif %}
93-
<script src="{{ SITEURL }}/theme/js/dark-theme.min.js?v=1"></script>
9493
<meta name="generator" content="Pelican" />
9594
{% endblock head %}
9695
</head>
@@ -230,7 +229,7 @@
230229
</div>
231230
</div>
232231
</footer>
233-
<script src="{{ SITEURL }}/theme/js/theme.min.js?v=1" defer></script>
232+
<script src="{{ SITEURL }}/theme/js/theme.min.js?v=2" defer></script>
234233
{% block scripts %}{% endblock %}
235234
{% if MATOMO_SITE_ID %}
236235
<!-- Matomo -->

0 commit comments

Comments
 (0)