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

DEV - Add Fontawesome scripts to build assets #1982

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ theme-name = "pydata_sphinx_theme"
additional-compiled-static-assets = [
"webpack-macros.html",
"vendor/",
"styles/bootstrap.css",
"scripts/bootstrap.js",
"scripts/fontawesome.js",
"locale/",
]

Expand Down Expand Up @@ -53,7 +53,7 @@ classifiers = [
[project.optional-dependencies]
doc = [
"numpydoc",
"linkify-it-py", # for link shortening
"linkify-it-py", # for link shortening
"rich",
"sphinxext-rediraffe",
"sphinx-sitemap",
Expand Down Expand Up @@ -105,6 +105,7 @@ fix = true
ignore = [
"E501", # line too long | Black take care of it
"D107", # Missing docstring in `__init__` | set the docstring in the class

]
ignore-init-module-imports = true
select = ["E", "F", "W", "I", "D", "RUF"]
Expand Down
2 changes: 1 addition & 1 deletion 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/fontawesome.min.js";
import "@fortawesome/fontawesome-free/js/all.min.js";
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ $all-colors: map.merge($pst-semantic-colors, $extra-semantic-colors);

@mixin create-sd-colors($value, $name) {
// define the pst variables, so that downstream user overrides will work
@debug "Creating color variables for semantic color: #{$name}";

--pst-color-#{$name}: #{$value};

// we are now using a11y-combination to calculate the text color - this is based
Expand Down
8 changes: 5 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const { Compilation } = require("webpack");

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 @@ -34,6 +33,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 @@ -70,13 +71,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
Loading