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

Always vendor all external JS/CSS #169

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7345622
first chunk of vendoring
bollwyvl Apr 30, 2020
bed20ed
fonts
bollwyvl Apr 30, 2020
bb35aef
lawyer up
bollwyvl Apr 30, 2020
0e04b2a
more verbose cdn config name, default to cdn, handle sphinx <3
bollwyvl Apr 30, 2020
b486a75
some more tweaking to conf
bollwyvl Apr 30, 2020
7a650b0
remove configurability, simplify config
bollwyvl May 1, 2020
eff61b2
remove NAME variable, as only used in one place again
bollwyvl May 1, 2020
a331540
build in ci
bollwyvl May 1, 2020
7fb62c8
fix conda install
bollwyvl May 1, 2020
6e5f40e
actually fix conda install of yarn
bollwyvl May 1, 2020
09624fe
linting
bollwyvl May 1, 2020
478f3ee
merge master
bollwyvl May 4, 2020
0e1b35b
Merge remote-tracking branch 'upstream/master' into always-vendor-ext…
bollwyvl May 12, 2020
aaa92d4
revert all mathjax-related changes
bollwyvl May 13, 2020
77bbbd5
add vendored assets to repo
bollwyvl May 13, 2020
c5bc9f5
merge master
bollwyvl Jun 16, 2020
d127923
rebuild yarn.lock, regenerate static
bollwyvl Jun 16, 2020
c8d033d
avoid node_modules in scss import, add preload of js in template
bollwyvl Jun 16, 2020
1b581fb
add cache-busting html macros: hash for built, versions for vendor
bollwyvl Jun 16, 2020
5477208
use proper hashes for current and future css and js in macros
bollwyvl Jun 16, 2020
40a88c2
Merge remote-tracking branch 'upstream/master' into always-vendor-ext…
bollwyvl Jun 19, 2020
d76ef11
remove ProvidePlugin
bollwyvl Jun 20, 2020
ba38d75
merge master
bollwyvl Jun 23, 2020
22c2470
rebuild assets after merging master
bollwyvl Jun 23, 2020
3eb4d1c
Merge remote-tracking branch 'upstream/master' into always-vendor-ext…
bollwyvl Jun 24, 2020
d90f795
add user_guide docs about customizing fonts, contributing about macro…
bollwyvl Jun 24, 2020
879fcf9
update pull request screenshot
bollwyvl Jun 24, 2020
2b7d4a5
pngcrush screenshot, fix some sentence continuation
bollwyvl Jun 24, 2020
f85cffe
move webpack macros into static
bollwyvl Jun 24, 2020
7bbe4c7
clean up some paths
bollwyvl Jun 24, 2020
dec25bc
add some more about fonts and selectors
bollwyvl Jun 24, 2020
356f8f9
rebuild
bollwyvl Jun 24, 2020
c1ac080
whitespace
bollwyvl Jun 24, 2020
1ee04a5
another pass over contributiong/customizing
bollwyvl Jun 25, 2020
7d32515
merge master
bollwyvl Jun 25, 2020
fe3b00a
update figure
jorisvandenbossche Jul 6, 2020
993bb3b
don't build with yarn in CI + use installed (not editable) python pac…
jorisvandenbossche Jul 6, 2020
6f934a1
some rst edits
jorisvandenbossche Jul 6, 2020
b1da116
fix rst edits
jorisvandenbossche Jul 6, 2020
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: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
conda config --set always_yes yes --set changeps1 no
conda update conda
conda config --add channels conda-forge
conda install yarn
yarn && yarn build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might have been raised / discussed before, but in principle this is not needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's not trying to re-build in CI, I don't that a PR actually is actually checked as to whether they author checked in the assets. but perhaps i'm wrong?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does solve the author forgetting to build the production assets.
It doesn't solve committing the builded assets though?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is actually checked as to whether they author checked in the assets.

The linting CI build should ensure that

# Install pandas + some optional dependencies
pip install -r docs/requirements.txt
# install the theme package
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ celerybeat-schedule
.venv
venv/
ENV/
envs/

# Spyder project settings
.spyderproject
Expand All @@ -103,3 +104,6 @@ ENV/

node_modules/
.vscode

# vendored js/css
vendor/
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
"webpack-watch-files-plugin": "^1.0.3"
},
"dependencies": {
"@fortawesome/fontawesome-free": "^5.13.0",
"@openfonts/lato_latin-ext": "^1.44.1",
"@openfonts/open-sans_all": "^1.44.1",
"bootstrap": "^4.4.1",
"jquery": "3.4.1",
"mathjax": "2.7.5",
"optimize-css-assets-webpack-plugin": "^5.0.3",
"popper.js": "^1.16.1"
}
Expand Down
27 changes: 26 additions & 1 deletion pydata_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"""
import os

import docutils

from sphinx.errors import ExtensionError

from .bootstrap_html_translator import BootstrapHTML5Translator
import docutils

__version__ = "0.2.2dev0"

Expand Down Expand Up @@ -167,6 +168,28 @@ def get_edit_url():
# -----------------------------------------------------------------------------


def configure_mathjax(app, env, docnames):
""" Overload mathjax_path, as defaulting to a CDN in `sphinx/ext/mathjax.py`
"""
if has_default_mathjax_path(app):
app.config.mathjax_path = get_mathjax_path()


# -----------------------------------------------------------------------------


def has_default_mathjax_path(app):
if "mathjax_path" not in app.config:
return False

return app.config.mathjax_path == app.config.values["mathjax_path"][0]


def get_mathjax_path():
"""Return the locally-vendored MathJax path"""
return "vendor/mathjax/latest.js?config=TeX-AMS-MML_HTMLorMML"


def get_html_theme_path():
"""Return list of HTML theme paths."""
theme_path = os.path.abspath(os.path.dirname(__file__))
Expand All @@ -185,5 +208,7 @@ def setup(app):
app.set_translator("readthedocsdirhtml", BootstrapHTML5Translator, override=True)
app.connect("html-page-context", setup_edit_url)
app.connect("html-page-context", add_toctree_functions)
# hook this event so the config is set prior to MathJax link injection
app.connect("env-before-read-docs", configure_mathjax)

return {"parallel_read_safe": True, "parallel_write_safe": True}
8 changes: 5 additions & 3 deletions pydata_sphinx_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
{% endmacro %}

{%- block css %}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css" integrity="sha384-KA6wR/X5RY4zFAHpv/CnoG2UW1uogYfdnP67Uv7eULvTveboZJg0qUpmJZb5VqzN" crossorigin="anonymous">
<link href="{{ pathto('_static/css/index.css', 1) }}" rel="stylesheet">
<link rel="stylesheet" href="{{ pathto('_static/vendor/fontawesome/css/all.min.css', 1) }}">
<link rel="stylesheet" href="{{ pathto('_static/vendor/open-sans_all/index.css', 1) }}">
<link rel="stylesheet" href="{{ pathto('_static/vendor/lato_latin-ext/index.css', 1) }}">
<link rel="stylesheet" href="{{ pathto('_static/css/index.css', 1) }}">
{{- css() }}
{%- endblock %}

Expand Down Expand Up @@ -89,4 +91,4 @@

{%- block footer %}
{%- include "footer.html" %}
{%- endblock %}
{%- endblock %}
2 changes: 1 addition & 1 deletion pydata_sphinx_theme/static/css/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions src/scss/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ $container-max-widths: (
// Include core Bootstrap
@import '../../node_modules/bootstrap/scss/bootstrap';

// Import custom fonts
@import url('https://fonts.googleapis.com/css?family=Open+Sans:400|Lato:400');

@import './base';
@import './navbar';

Expand Down Expand Up @@ -83,8 +80,8 @@ table.field-list {
}
}

/**
* Styling for autosummary tables
/**
* Styling for autosummary tables
*/

// The first column (with the signature) should not wrap
Expand Down
82 changes: 80 additions & 2 deletions webpack.common.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
const { resolve } = require('path');
const webpack = require('webpack');
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');

const staticPath = resolve(__dirname, 'pydata_sphinx_theme/static');
const vendor = resolve(staticPath, 'vendor');

module.exports = {
entry: {
index: ['./src/js/index.js', './src/scss/index.scss'],
},
output: {
filename: 'js/[name].js?[hash]',
path: path.resolve(__dirname, 'pydata_sphinx_theme/static'),
path: staticPath,
},
module: {
rules: [
Expand Down Expand Up @@ -43,6 +47,80 @@ module.exports = {
},
plugins: [
new CleanWebpackPlugin(),
new CopyPlugin([
// fonts
{
context: './node_modules/@fortawesome/fontawesome-free/css',
from: 'all.min.css',
to: resolve(vendor, 'fontawesome', 'css')
},
{
context: './node_modules/@fortawesome/fontawesome-free',
from: 'webfonts',
to: resolve(vendor, 'fontawesome', 'webfonts')
},
{
context: './node_modules/@fortawesome/fontawesome-free',
from: 'LICENSE.txt',
to: resolve(vendor, 'fontawesome')
},
{
context: './node_modules/@openfonts/open-sans_all',
from: 'files/*-400*',
hoetmaaiers marked this conversation as resolved.
Show resolved Hide resolved
to: resolve(vendor, 'open-sans_all')
},
{
context: './node_modules/@openfonts/open-sans_all',
from: 'index.css',
to: resolve(vendor, 'open-sans_all')
},
{
context: './node_modules/@openfonts/open-sans_all',
from: 'LICENSE.md',
to: resolve(vendor, 'open-sans_all')
},
{
context: './node_modules/@openfonts/lato_latin-ext',
from: 'files/*-400*',
hoetmaaiers marked this conversation as resolved.
Show resolved Hide resolved
to: resolve(vendor, 'lato_latin-ext')
},
{
context: './node_modules/@openfonts/lato_latin-ext',
from: 'index.css',
to: resolve(vendor, 'lato_latin-ext')
},
{
context: './node_modules/@openfonts/lato_latin-ext',
from: 'LICENSE.md',
to: resolve(vendor, 'lato_latin-ext')
},
// mathjax
{
context: './node_modules/mathjax',
from: '*.js',
to: resolve(vendor, 'mathjax')
},
{
context: './node_modules/mathjax',
from: 'jax/output/HTML-CSS',
to: resolve(vendor, 'mathjax/jax/output/HTML-CSS')
},
{
context: './node_modules/mathjax',
from: 'fonts/HTML-CSS/TeX',
to: resolve(vendor, 'mathjax/fonts/HTML-CSS/TeX')
},
{
context: './node_modules/mathjax',
from: 'config/TeX-AMS-MML_HTMLorMML.js',
to: resolve(vendor, 'mathjax/config')
},
{
context: './node_modules/mathjax',
from: 'LICENSE',
to: resolve(vendor, 'mathjax')
},
]),
new webpack.ProvidePlugin({
'$': "jquery",
'jQuery': "jquery",
Expand Down
20 changes: 20 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
# yarn lockfile v1


"@fortawesome/fontawesome-free@^5.13.0":
version "5.13.0"
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free/-/fontawesome-free-5.13.0.tgz#fcb113d1aca4b471b709e8c9c168674fbd6e06d9"
integrity sha512-xKOeQEl5O47GPZYIMToj6uuA2syyFlq9EMSl2ui0uytjY9xbe8XS0pexNWmxrdcCyNGyDmLyYw5FtKsalBUeOg==

"@openfonts/lato_latin-ext@^1.44.1":
version "1.44.1"
resolved "https://registry.yarnpkg.com/@openfonts/lato_latin-ext/-/lato_latin-ext-1.44.1.tgz#b36a9c5905e0143f5f72e25cf635625f645603dd"
integrity sha512-uEhdHlTQtLumrWuKHV3JpzH7H1/gGnwXrNC8PAK6StF/Tq1AQPfdjokqgwrHPVQPooj/LAwujhvBwPDdW4/5eQ==

"@openfonts/open-sans_all@^1.44.1":
version "1.44.1"
resolved "https://registry.yarnpkg.com/@openfonts/open-sans_all/-/open-sans_all-1.44.1.tgz#4a05c454a89d0a70eb2f17bfa2ea3f21e3aae091"
integrity sha512-/3uxdiRxH1Sk+llrw4o7lunFhM5IwU/LBo2PU6EYw+iMRNuoUqKU7eyeGtFdAbvErjsU9Xvbe75zkqmsBcXGaw==

"@types/anymatch@*":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@types/anymatch/-/anymatch-1.3.1.tgz#336badc1beecb9dacc38bea2cf32adf627a8421a"
Expand Down Expand Up @@ -3124,6 +3139,11 @@ map-visit@^1.0.0:
dependencies:
object-visit "^1.0.0"

mathjax@2.7.5:
version "2.7.5"
resolved "https://registry.yarnpkg.com/mathjax/-/mathjax-2.7.5.tgz#c9c5947f86f9be31651f5f3667d3c9a8bb01efe4"
integrity sha512-OzsJNitEHAJB3y4IIlPCAvS0yoXwYjlo2Y4kmm9KQzyIBZt2d8yKRalby3uTRNN4fZQiGL2iMXjpdP1u2Rq2DQ==

md5.js@^1.3.4:
version "1.3.5"
resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f"
Expand Down