Skip to content

Commit 64cf57f

Browse files
authored
Added support to PurgeCSS (alshedivat#1562)
Tackled alshedivat#1329 with [PurgeCSS](https://purgecss.com/). Being talking with @varuniyer about using [jekyll-uncss](https://github.com/episource/jekyll-uncss) to reduce css file sizes by ditching unused classes. This approach have 3 main problems: 1 - have some limitations as pointed [here](alshedivat#1329 (comment)) 2 - last update to [jekyll-uncss](https://github.com/episource/jekyll-uncss) was about 3 years ago, so it might have a few issues 3 - [uncss](https://github.com/uncss/uncss) haven't seem a new release in a while, currently [lacking maintenance](uncss/uncss#459), and using some deprecated libraries as seem here: ``` npm install -g uncss npm WARN deprecated request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see request/request#3142 npm WARN deprecated har-validator@5.1.5: this library is no longer supported npm WARN deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin. npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. npm WARN deprecated request@2.88.2: request has been deprecated, see request/request#3142 ``` I thought about giving PurgeCSS a go, since it has been more [actively maintaned](https://github.com/FullHuman/purgecss), but [jekyll-purgecss](https://github.com/mhanberg/jekyll-purgecss) haven't. For this, I needed to change to use some local libraries instead of getting them via CDN. The good news is that it is quite effective in reducing css file sizes. Comparing dir sizes with `du -hs _site/assets/css/`: | current | minify | PurgeCSS | PurgeCSS + minify | | ------- | ------ | -------- | ----------------- | | 1,1M | 988K | 456K | 420K | --------- Signed-off-by: George Araujo <george.gcac@gmail.com>
1 parent b663e9e commit 64cf57f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+7876
-41
lines changed

.github/workflows/deploy.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ jobs:
3030
run: |
3131
pip3 install --upgrade jupyter
3232
npm install -g mermaid.cli
33+
npm install -g purgecss
3334
export JEKYLL_ENV=production
34-
bundle exec jekyll build
35+
bundle exec jekyll build --lsi
36+
purgecss -c purgecss.config.js
3537
- name: Deploy 🚀
3638
if: github.event_name != 'pull_request'
3739
uses: JamesIves/github-pages-deploy-action@v4

README.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ Beyond Vision: Physics meets AI (ICIAP: <a href="https://physicsmeetsai.github.i
167167

168168
## Table Of Contents
169169

170-
* [User community](#user-community)
171-
* [Lighthouse PageSpeed Insights](#lighthouse-pagespeed-insights)
172-
* [Table Of Contents](#table-of-contents)
173-
* [Getting started](#getting-started)
170+
- [User community](#user-community)
171+
- [Lighthouse PageSpeed Insights](#lighthouse-pagespeed-insights)
172+
- [Table Of Contents](#table-of-contents)
173+
- [Getting started](#getting-started)
174174
- [Installation](#installation)
175175
- [Local setup using Docker (Recommended)](#local-setup-using-docker-recommended)
176176
- [Local Setup (Legacy)](#local-setup-legacy)
@@ -312,6 +312,14 @@ $ bundle exec jekyll build --lsi
312312
which will (re-)generate the static webpage in the `_site/` folder.
313313
Then simply copy the contents of the `_site/` directory to your hosting server.
314314

315+
If you also want to remove unused css classes from your file, run:
316+
317+
```bash
318+
$ purgecss -c purgecss.config.js
319+
```
320+
321+
which will replace the css files in the `_site/assets/css/` folder with the purged css files.
322+
315323
**Note:** Make sure to correctly set the `url` and `baseurl` fields in `_config.yml` before building the webpage. If you are deploying your webpage to `your-domain.com/your-project/`, you must set `url: your-domain.com` and `baseurl: /your-project/`. If you are deploying directly to `your-domain.com`, leave `baseurl` blank.
316324

317325
</details>

_config.yml

+4-21
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ impressum_path: # set to path to include impressum link in the footer, use the
2727
# Theme
2828
# -----------------------------------------------------------------------------
2929

30-
# code highlighter theme
31-
highlight_theme_light: github # https://github.com/jwarby/jekyll-pygments-themes
32-
highlight_theme_dark: native # https://github.com/jwarby/jekyll-pygments-themes
33-
3430
# repo color theme
3531
repo_theme_light: default # https://github.com/anuraghazra/github-readme-stats/blob/master/themes/README.md
3632
repo_theme_dark: dark # https://github.com/anuraghazra/github-readme-stats/blob/master/themes/README.md
@@ -242,6 +238,9 @@ defaults:
242238
values:
243239
sitemap: false
244240

241+
sass:
242+
style: compressed
243+
245244
# -----------------------------------------------------------------------------
246245
# Jekyll Minifier
247246
# -----------------------------------------------------------------------------
@@ -377,19 +376,8 @@ enable_progressbar: true # enables a horizontal progress bar linked to
377376
# Library versions
378377
# -----------------------------------------------------------------------------
379378

380-
academicons:
381-
version: "1.9.1"
382-
integrity: "sha256-i1+4qU2G2860dGGIOJscdC30s9beBXjFfzjWLjBRsBg="
383-
bootstrap:
384-
version: "4.6.1"
385-
integrity:
386-
css: "sha256-DF7Zhf293AJxJNTmh5zhoYYIMs2oXitRfBjY+9L//AY="
387-
js: "sha256-fgLAgv7fyCGopR/gBNq2iW3ZKIdqIcyshnUULC4vex8="
388379
bootstrap-table:
389-
version: "1.21.4"
390-
fontawesome:
391-
version: "6.4.0"
392-
integrity: "sha256-HtsXJanqjKTc8vVQjO4YMhiqFoXkfBsjBWcX91T1jr8="
380+
version: "1.22.1"
393381
jquery:
394382
version: "3.6.0"
395383
integrity: "sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
@@ -398,11 +386,6 @@ mathjax:
398386
masonry:
399387
version: "4.2.2"
400388
integrity: "sha256-Nn1q/fx0H7SNLZMQ5Hw5JLaTRZp0yILA/FRexe19VdI="
401-
mdb:
402-
version: "4.20.0"
403-
integrity:
404-
css: "sha256-jpjYvU3G3N6nrrBwXJoVEYI/0zw8htfFnhT9ljN3JJw="
405-
js: "sha256-NdbiivsvWt7VYCt6hYNT3h/th9vSTL4EDWeGs5SN3DA="
406389
medium_zoom:
407390
version: "1.0.8"
408391
integrity: "sha256-7PhEpEWEW0XXQ0k6kQrPKwuoIomz8R8IYyuU1Qew4P8="

_includes/head.html

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,36 @@
22
{% include metadata.html %}
33

44
<!-- Bootstrap & MDB -->
5-
<link href="https://cdn.jsdelivr.net/npm/bootstrap@{{ site.bootstrap.version }}/dist/css/bootstrap.min.css" rel="stylesheet" integrity="{{ site.bootstrap.integrity.css }}" crossorigin="anonymous">
6-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/mdbootstrap@{{ site.mdb.version }}/css/mdb.min.css" integrity="{{ site.mdb.integrity.css }}" crossorigin="anonymous" />
5+
<link rel="stylesheet" href="{{ '/assets/css/bootstrap.min.css' | relative_url | bust_file_cache }}">
6+
<link rel="stylesheet" href="{{ '/assets/css/mdb.min.css' | relative_url | bust_file_cache }}">
77

88
<!-- Bootstrap Table -->
99
<link defer rel="stylesheet" href="https://unpkg.com/bootstrap-table@{{ site.bootstrap-table.version }}/dist/bootstrap-table.min.css">
1010

1111
<!-- Fonts & Icons -->
12-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@{{ site.fontawesome.version }}/css/all.min.css" integrity="{{ site.fontawesome.integrity }}" crossorigin="anonymous">
13-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/academicons@{{ site.academicons.version }}/css/academicons.min.css" integrity="{{ site.academicons.integrity }}" crossorigin="anonymous">
12+
<link rel="stylesheet" href="{{ '/assets/css/academicons.min.css' | relative_url | bust_file_cache }}">
1413
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Roboto+Slab:100,300,400,500,700|Material+Icons">
1514

1615
<!-- Code Syntax Highlighting -->
17-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/jwarby/jekyll-pygments-themes@master/{{ site.highlight_theme_light | append: '.css' }}" media="" id="highlight_theme_light" />
16+
<link rel="stylesheet" href="{{ '/assets/css/jekyll-pygments-themes-github.css' | relative_url | bust_file_cache }}" media="" id="highlight_theme_light" />
1817

1918
{% if page.toc and page.toc.sidebar %}
2019
<!-- Sidebar Table of Contents -->
21-
<link href="https://cdn.rawgit.com/afeld/bootstrap-toc/v1.0.1/dist/bootstrap-toc.min.css" rel="stylesheet" />
20+
<link href="{{ '/assets/css/bootstrap-toc.min.css' | relative_url | bust_file_cache }}" rel="stylesheet" />
2221
{% endif %}
2322

2423
<!-- Styles -->
2524
{% if site.icon.size <= 4 %}
2625
<link rel="shortcut icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>{{ site.icon }}</text></svg>">
2726
{% elsif site.icon != blank %}
28-
<link rel="shortcut icon" href="{{ site.icon | prepend: '/assets/img/' | relative_url}}"/>
27+
<link rel="shortcut icon" href="{{ site.icon | prepend: '/assets/img/' | relative_url | bust_file_cache}}"/>
2928
{% endif %}
3029
<link rel="stylesheet" href="{{ '/assets/css/main.css' | relative_url | bust_css_cache }}">
3130
<link rel="canonical" href="{{ page.url | replace:'index.html','' | absolute_url }}">
3231

3332
<!-- Dark Mode -->
3433
{% if site.enable_darkmode %}
35-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/jwarby/jekyll-pygments-themes@master/{{ site.highlight_theme_dark | append: '.css' }}" media="none" id="highlight_theme_dark" />
34+
<link rel="stylesheet" href="{{ '/assets/css/jekyll-pygments-themes-native.css' | relative_url | bust_file_cache }}" media="none" id="highlight_theme_dark" />
3635
<script src="{{ '/assets/js/theme.js' | relative_url | bust_file_cache }}"></script>
3736
<script src="{{ '/assets/js/dark_mode.js' | relative_url | bust_file_cache }}"></script>
3837
{% endif %}

_includes/scripts/bootstrap.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<!-- Bootsrap & MDB scripts -->
2-
<script src="https://cdn.jsdelivr.net/npm/bootstrap@{{ site.bootstrap.version }}/dist/js/bootstrap.bundle.min.js" integrity="{{ site.bootstrap.integrity.js }}" crossorigin="anonymous"></script>
3-
<script src="https://cdn.jsdelivr.net/npm/mdbootstrap@{{ site.mdb.version }}/js/mdb.min.js" integrity="{{ site.mdb.integrity.js }}" crossorigin="anonymous"></script>
2+
<script src="{{ '/assets/js/bootstrap.bundle.min.js' | relative_url }}"></script>
3+
<script src="{{ '/assets/js/mdb.min.js' | relative_url }}"></script>

_includes/scripts/misc.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
{%- if site.enable_medium_zoom %}
99
<!-- Medium Zoom JS -->
1010
<script defer src="https://cdn.jsdelivr.net/npm/medium-zoom@{{ site.medium_zoom.version }}/dist/medium-zoom.min.js" integrity="{{ site.medium_zoom.integrity }}" crossorigin="anonymous"></script>
11-
<script defer src="{{ '/assets/js/zoom.js' | relative_url }}"></script>
11+
<script defer src="{{ '/assets/js/zoom.js' | relative_url | bust_file_cache }}"></script>
1212
{%- endif -%}
1313

1414
{% if page.toc and page.toc.sidebar %}
1515
<!-- Sidebar Table of Contents -->
16-
<script defer src="https://cdn.rawgit.com/afeld/bootstrap-toc/v1.0.1/dist/bootstrap-toc.min.js"></script>
16+
<script defer src="{{ '/assets/js/bootstrap-toc.min.js' | relative_url | bust_file_cache }}"></script>
1717
{% endif %}
1818

1919
<!-- Bootstrap Table -->

_sass/_variables.scss

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* To adjust anything, simply edit the variables below and rebuild the theme.
44
******************************************************************************/
55

6-
76
// Colors
87
$red-color: #FF3636 !default;
98
$red-color-dark: #B71C1C !default;
@@ -31,8 +30,10 @@ $grey-900: #212529;
3130
$white-color: #ffffff !default;
3231
$black-color: #000000 !default;
3332

34-
3533
// Theme colors
3634

3735
$code-bg-color-light: rgba($purple-color, 0.05);
3836
$code-bg-color-dark: #2c3237 !default;
37+
38+
// Font awesome location
39+
$fa-font-path: "../webfonts";

_sass/font-awesome/_animated.scss

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
// animating icons
2+
// --------------------------
3+
4+
.#{$fa-css-prefix}-beat {
5+
animation-name: #{$fa-css-prefix}-beat;
6+
animation-delay: var(--#{$fa-css-prefix}-animation-delay, 0s);
7+
animation-direction: var(--#{$fa-css-prefix}-animation-direction, normal);
8+
animation-duration: var(--#{$fa-css-prefix}-animation-duration, 1s);
9+
animation-iteration-count: var(--#{$fa-css-prefix}-animation-iteration-count, infinite);
10+
animation-timing-function: var(--#{$fa-css-prefix}-animation-timing, ease-in-out);
11+
}
12+
13+
.#{$fa-css-prefix}-bounce {
14+
animation-name: #{$fa-css-prefix}-bounce;
15+
animation-delay: var(--#{$fa-css-prefix}-animation-delay, 0s);
16+
animation-direction: var(--#{$fa-css-prefix}-animation-direction, normal);
17+
animation-duration: var(--#{$fa-css-prefix}-animation-duration, 1s);
18+
animation-iteration-count: var(--#{$fa-css-prefix}-animation-iteration-count, infinite);
19+
animation-timing-function: var(--#{$fa-css-prefix}-animation-timing, cubic-bezier(0.280, 0.840, 0.420, 1));
20+
}
21+
22+
.#{$fa-css-prefix}-fade {
23+
animation-name: #{$fa-css-prefix}-fade;
24+
animation-delay: var(--#{$fa-css-prefix}-animation-delay, 0s);
25+
animation-direction: var(--#{$fa-css-prefix}-animation-direction, normal);
26+
animation-duration: var(--#{$fa-css-prefix}-animation-duration, 1s);
27+
animation-iteration-count: var(--#{$fa-css-prefix}-animation-iteration-count, infinite);
28+
animation-timing-function: var(--#{$fa-css-prefix}-animation-timing, cubic-bezier(.4,0,.6,1));
29+
}
30+
31+
.#{$fa-css-prefix}-beat-fade {
32+
animation-name: #{$fa-css-prefix}-beat-fade;
33+
animation-delay: var(--#{$fa-css-prefix}-animation-delay, 0s);
34+
animation-direction: var(--#{$fa-css-prefix}-animation-direction, normal);
35+
animation-duration: var(--#{$fa-css-prefix}-animation-duration, 1s);
36+
animation-iteration-count: var(--#{$fa-css-prefix}-animation-iteration-count, infinite);
37+
animation-timing-function: var(--#{$fa-css-prefix}-animation-timing, cubic-bezier(.4,0,.6,1));
38+
}
39+
40+
.#{$fa-css-prefix}-flip {
41+
animation-name: #{$fa-css-prefix}-flip;
42+
animation-delay: var(--#{$fa-css-prefix}-animation-delay, 0s);
43+
animation-direction: var(--#{$fa-css-prefix}-animation-direction, normal);
44+
animation-duration: var(--#{$fa-css-prefix}-animation-duration, 1s);
45+
animation-iteration-count: var(--#{$fa-css-prefix}-animation-iteration-count, infinite);
46+
animation-timing-function: var(--#{$fa-css-prefix}-animation-timing, ease-in-out);
47+
}
48+
49+
.#{$fa-css-prefix}-shake {
50+
animation-name: #{$fa-css-prefix}-shake;
51+
animation-delay: var(--#{$fa-css-prefix}-animation-delay, 0s);
52+
animation-direction: var(--#{$fa-css-prefix}-animation-direction, normal);
53+
animation-duration: var(--#{$fa-css-prefix}-animation-duration, 1s);
54+
animation-iteration-count: var(--#{$fa-css-prefix}-animation-iteration-count, infinite);
55+
animation-timing-function: var(--#{$fa-css-prefix}-animation-timing, linear);
56+
}
57+
58+
.#{$fa-css-prefix}-spin {
59+
animation-name: #{$fa-css-prefix}-spin;
60+
animation-delay: var(--#{$fa-css-prefix}-animation-delay, 0s);
61+
animation-direction: var(--#{$fa-css-prefix}-animation-direction, normal);
62+
animation-duration: var(--#{$fa-css-prefix}-animation-duration, 2s);
63+
animation-iteration-count: var(--#{$fa-css-prefix}-animation-iteration-count, infinite);
64+
animation-timing-function: var(--#{$fa-css-prefix}-animation-timing, linear);
65+
}
66+
67+
.#{$fa-css-prefix}-spin-reverse {
68+
--#{$fa-css-prefix}-animation-direction: reverse;
69+
}
70+
71+
.#{$fa-css-prefix}-pulse,
72+
.#{$fa-css-prefix}-spin-pulse {
73+
animation-name: #{$fa-css-prefix}-spin;
74+
animation-direction: var(--#{$fa-css-prefix}-animation-direction, normal);
75+
animation-duration: var(--#{$fa-css-prefix}-animation-duration, 1s);
76+
animation-iteration-count: var(--#{$fa-css-prefix}-animation-iteration-count, infinite);
77+
animation-timing-function: var(--#{$fa-css-prefix}-animation-timing, steps(8));
78+
}
79+
80+
// if agent or operating system prefers reduced motion, disable animations
81+
// see: https://www.smashingmagazine.com/2020/09/design-reduced-motion-sensitivities/
82+
// see: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion
83+
@media (prefers-reduced-motion: reduce) {
84+
.#{$fa-css-prefix}-beat,
85+
.#{$fa-css-prefix}-bounce,
86+
.#{$fa-css-prefix}-fade,
87+
.#{$fa-css-prefix}-beat-fade,
88+
.#{$fa-css-prefix}-flip,
89+
.#{$fa-css-prefix}-pulse,
90+
.#{$fa-css-prefix}-shake,
91+
.#{$fa-css-prefix}-spin,
92+
.#{$fa-css-prefix}-spin-pulse {
93+
animation-delay: -1ms;
94+
animation-duration: 1ms;
95+
animation-iteration-count: 1;
96+
transition-delay: 0s;
97+
transition-duration: 0s;
98+
}
99+
}
100+
101+
@keyframes #{$fa-css-prefix}-beat {
102+
0%, 90% { transform: scale(1); }
103+
45% { transform: scale(var(--#{$fa-css-prefix}-beat-scale, 1.25)); }
104+
}
105+
106+
@keyframes #{$fa-css-prefix}-bounce {
107+
0% { transform: scale(1,1) translateY(0); }
108+
10% { transform: scale(var(--#{$fa-css-prefix}-bounce-start-scale-x, 1.1),var(--#{$fa-css-prefix}-bounce-start-scale-y, 0.9)) translateY(0); }
109+
30% { transform: scale(var(--#{$fa-css-prefix}-bounce-jump-scale-x, 0.9),var(--#{$fa-css-prefix}-bounce-jump-scale-y, 1.1)) translateY(var(--#{$fa-css-prefix}-bounce-height, -0.5em)); }
110+
50% { transform: scale(var(--#{$fa-css-prefix}-bounce-land-scale-x, 1.05),var(--#{$fa-css-prefix}-bounce-land-scale-y, 0.95)) translateY(0); }
111+
57% { transform: scale(1,1) translateY(var(--#{$fa-css-prefix}-bounce-rebound, -0.125em)); }
112+
64% { transform: scale(1,1) translateY(0); }
113+
100% { transform: scale(1,1) translateY(0); }
114+
}
115+
116+
@keyframes #{$fa-css-prefix}-fade {
117+
50% { opacity: var(--#{$fa-css-prefix}-fade-opacity, 0.4); }
118+
}
119+
120+
@keyframes #{$fa-css-prefix}-beat-fade {
121+
0%, 100% {
122+
opacity: var(--#{$fa-css-prefix}-beat-fade-opacity, 0.4);
123+
transform: scale(1);
124+
}
125+
50% {
126+
opacity: 1;
127+
transform: scale(var(--#{$fa-css-prefix}-beat-fade-scale, 1.125));
128+
}
129+
}
130+
131+
@keyframes #{$fa-css-prefix}-flip {
132+
50% {
133+
transform: rotate3d(var(--#{$fa-css-prefix}-flip-x, 0), var(--#{$fa-css-prefix}-flip-y, 1), var(--#{$fa-css-prefix}-flip-z, 0), var(--#{$fa-css-prefix}-flip-angle, -180deg));
134+
}
135+
}
136+
137+
@keyframes #{$fa-css-prefix}-shake {
138+
0% { transform: rotate(-15deg); }
139+
4% { transform: rotate(15deg); }
140+
8%, 24% { transform: rotate(-18deg); }
141+
12%, 28% { transform: rotate(18deg); }
142+
16% { transform: rotate(-22deg); }
143+
20% { transform: rotate(22deg); }
144+
32% { transform: rotate(-12deg); }
145+
36% { transform: rotate(12deg); }
146+
40%, 100% { transform: rotate(0deg); }
147+
}
148+
149+
@keyframes #{$fa-css-prefix}-spin {
150+
0% { transform: rotate(0deg); }
151+
100% { transform: rotate(360deg); }
152+
}
153+
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// bordered + pulled icons
2+
// -------------------------
3+
4+
.#{$fa-css-prefix}-border {
5+
border-color: var(--#{$fa-css-prefix}-border-color, #{$fa-border-color});
6+
border-radius: var(--#{$fa-css-prefix}-border-radius, #{$fa-border-radius});
7+
border-style: var(--#{$fa-css-prefix}-border-style, #{$fa-border-style});
8+
border-width: var(--#{$fa-css-prefix}-border-width, #{$fa-border-width});
9+
padding: var(--#{$fa-css-prefix}-border-padding, #{$fa-border-padding});
10+
}
11+
12+
.#{$fa-css-prefix}-pull-left {
13+
float: left;
14+
margin-right: var(--#{$fa-css-prefix}-pull-margin, #{$fa-pull-margin});
15+
}
16+
17+
.#{$fa-css-prefix}-pull-right {
18+
float: right;
19+
margin-left: var(--#{$fa-css-prefix}-pull-margin, #{$fa-pull-margin});
20+
}

0 commit comments

Comments
 (0)