Skip to content

Commit

Permalink
Add FA.JS to head
Browse files Browse the repository at this point in the history
  • Loading branch information
trallard committed Sep 18, 2024
1 parent 1342a23 commit 68b2649
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/pydata_sphinx_theme/assets/scripts/fontawesome.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// TODO: @trallard might end up moving this to the main JS file
// Define the custom behavior of the page
import { documentReady } from "./mixin";

import "@fortawesome/fontawesome-free/js/all.min.js";
import "@fortawesome/fontawesome-free/js/fontawesome.min.js";
import "@fortawesome/fontawesome-free/js/all.min.js";
8 changes: 5 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ exec(`pybabel compile -d ${localePath} -D sphinx`);

const scriptPath = resolve(__dirname, "src/pydata_sphinx_theme/assets/scripts");
const staticPath = resolve(__dirname, "src/pydata_sphinx_theme/theme/pydata_sphinx_theme/static");
const vendorPath = resolve(staticPath, "vendor");

/*******************************************************************************
* functions to load the assets in the html head
Expand All @@ -42,6 +41,8 @@ const vendorPath = resolve(staticPath, "vendor");
function stylesheet(css) { return `<link href="{{ pathto('_static/${css}', 1) }}?digest=${this.hash}" rel="stylesheet" />`; }
function preload(js) { return `<link rel="preload" as="script" href="{{ pathto('_static/${js}', 1) }}?digest=${this.hash}" />`; }
function script(js) { return `<script defer src="{{ pathto('_static/${js}', 1) }}?digest=${this.hash}"></script>`; }
// Adding FA without preloading
function fascript(js) { return `<script src="{{ pathto('_static/${js}', 1) }}?digest=${this.hash}"></script>`; }

/*******************************************************************************
* the assets to load in the macro
Expand Down Expand Up @@ -78,13 +79,14 @@ function macroTemplate({ compilation }) {
{% endmacro %}
{% macro head_js_preload() %}
<!-- Pre-loaded scripts that we'll load fully later -->
<!-- So that users can add custom icons -->
${fa_scripts.map(fascript.bind(compilation)).join("\n")}
<!-- Pre-loaded scripts that we'll load fully later -->
${theme_scripts.map(preload.bind(compilation)).join("\n")}
{% endmacro %}
{% macro body_post() %}
<!-- Scripts loaded after <body> so the DOM is not blocked -->
${fa_scripts.map(script.bind(compilation)).join("\n")}
${theme_scripts.map(script.bind(compilation)).join("\n")}
{% endmacro %}
`);
Expand Down

0 comments on commit 68b2649

Please sign in to comment.