Skip to content

Commit

Permalink
Vendor all Lato's variants (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoetmaaiers authored Jul 8, 2020
1 parent 3cad446 commit df85690
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 30 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
70 changes: 40 additions & 30 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,62 @@ const staticPath = resolve(__dirname, 'pydata_sphinx_theme', 'static');

const vendor = resolve(staticPath, 'vendor');
const vendorVersions = {
fontAwesome: require("@fortawesome/fontawesome-free/package.json").version,
openSans: require("@openfonts/open-sans_all/package.json").version,
lato: require("@openfonts/lato_latin-ext/package.json").version
fontAwesome: require('@fortawesome/fontawesome-free/package.json').version,
openSans: require('@openfonts/open-sans_all/package.json').version,
lato: require('@openfonts/lato_latin-ext/package.json').version,
};
const vendorPaths = {
fontAwesome: resolve(vendor, 'fontawesome', vendorVersions.fontAwesome),
openSans: resolve(vendor, 'open-sans_all', vendorVersions.openSans),
lato: resolve(vendor, 'lato_latin-ext', vendorVersions.lato)
lato: resolve(vendor, 'lato_latin-ext', vendorVersions.lato),
};

// generates cache-busting templates to be used in `layout.html` without knowing versions
function macroTemplate({compilation}){
function macroTemplate({ compilation }) {
const indexes = Object.keys(compilation.assets).filter(
(file) => file.indexOf('/index.') != -1
);

const indexes = Object.keys(compilation.assets).filter((file) => file.indexOf("/index.") != -1);

const css = indexes.filter((file) => file.endsWith(".css"));
const js = indexes.filter((file) => file.endsWith(".js"));
const css = indexes.filter((file) => file.endsWith('.css'));
const js = indexes.filter((file) => file.endsWith('.js'));

const stylesheet = (css) => {
return `<link rel="stylesheet" href="{{ pathto('_static/${css}', 1) }}">`;
}
};

const preload = (js) => {
return `<link rel="preload" as="script" href="{{ pathto('_static/${js}', 1) }}">`
}
return `<link rel="preload" as="script" href="{{ pathto('_static/${js}', 1) }}">`;
};

const script = (js) => {
return `<script src="{{ pathto('_static/${js}', 1) }}"></script>`;
}
};

return `<!-- these macros are generated by "yarn build:production". do not edit by hand. -->
{% macro head_pre_icons() %}
<link rel="stylesheet"
href="{{ pathto('_static/vendor/fontawesome/${vendorVersions.fontAwesome}/css/all.min.css', 1) }}">
href="{{ pathto('_static/vendor/fontawesome/${
vendorVersions.fontAwesome
}/css/all.min.css', 1) }}">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="{{ pathto('_static/vendor/fontawesome/${vendorVersions.fontAwesome}/webfonts/fa-solid-900.woff2', 1) }}">
href="{{ pathto('_static/vendor/fontawesome/${
vendorVersions.fontAwesome
}/webfonts/fa-solid-900.woff2', 1) }}">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="{{ pathto('_static/vendor/fontawesome/${vendorVersions.fontAwesome}/webfonts/fa-brands-400.woff2', 1) }}">
href="{{ pathto('_static/vendor/fontawesome/${
vendorVersions.fontAwesome
}/webfonts/fa-brands-400.woff2', 1) }}">
{% endmacro %}
{% macro head_pre_fonts() %}
<link rel="stylesheet"
href="{{ pathto('_static/vendor/open-sans_all/${vendorVersions.openSans}/index.css', 1) }}">
href="{{ pathto('_static/vendor/open-sans_all/${
vendorVersions.openSans
}/index.css', 1) }}">
<link rel="stylesheet"
href="{{ pathto('_static/vendor/lato_latin-ext/${vendorVersions.lato}/index.css', 1) }}">
href="{{ pathto('_static/vendor/lato_latin-ext/${
vendorVersions.lato
}/index.css', 1) }}">
{% endmacro %}
{% macro head_pre_bootstrap() %}
Expand All @@ -68,7 +79,6 @@ function macroTemplate({compilation}){
{% endmacro %}`;
}


module.exports = {
entry: {
index: ['./src/js/index.js'],
Expand Down Expand Up @@ -113,58 +123,58 @@ module.exports = {
inject: false,
minify: false,
css: true,
templateContent: macroTemplate
templateContent: macroTemplate,
}),
new CopyPlugin([
// fontawesome
{
context: './node_modules/@fortawesome/fontawesome-free',
from: 'LICENSE.txt',
to: resolve(vendorPaths.fontAwesome, 'LICENSE.txt')
to: resolve(vendorPaths.fontAwesome, 'LICENSE.txt'),
},
{
context: './node_modules/@fortawesome/fontawesome-free/css',
from: 'all.min.css',
to: resolve(vendorPaths.fontAwesome, 'css')
to: resolve(vendorPaths.fontAwesome, 'css'),
},
{
context: './node_modules/@fortawesome/fontawesome-free',
from: 'webfonts',
to: resolve(vendorPaths.fontAwesome, 'webfonts')
to: resolve(vendorPaths.fontAwesome, 'webfonts'),
},
// opensans
{
context: './node_modules/@openfonts/open-sans_all',
from: 'files/*-400*',
flatten: true,
to: resolve(vendorPaths.openSans, 'files')
to: resolve(vendorPaths.openSans, 'files'),
},
{
context: './node_modules/@openfonts/open-sans_all',
from: 'LICENSE.md',
to: resolve(vendorPaths.openSans, 'LICENSE.md')
to: resolve(vendorPaths.openSans, 'LICENSE.md'),
},
{
context: './node_modules/@openfonts/open-sans_all',
from: 'index.css',
to: resolve(vendorPaths.openSans, 'index.css')
to: resolve(vendorPaths.openSans, 'index.css'),
},
// lato
{
context: './node_modules/@openfonts/lato_latin-ext',
from: 'files/*-400*',
from: 'files/*',
flatten: true,
to: resolve(vendorPaths.lato, 'files')
to: resolve(vendorPaths.lato, 'files'),
},
{
context: './node_modules/@openfonts/lato_latin-ext',
from: 'LICENSE.md',
to: resolve(vendorPaths.lato, 'LICENSE.md')
to: resolve(vendorPaths.lato, 'LICENSE.md'),
},
{
context: './node_modules/@openfonts/lato_latin-ext',
from: 'index.css',
to: resolve(vendorPaths.lato, 'index.css')
to: resolve(vendorPaths.lato, 'index.css'),
},
]),
],
Expand Down

0 comments on commit df85690

Please sign in to comment.