Skip to content

Commit

Permalink
Support specifying a custom source
Browse files Browse the repository at this point in the history
In some cases one might rely on the CDN as a default.
But the recent Max CDN issue has shown that one might
want to deploy their own copy, or use a local version.
  • Loading branch information
0robustus1 committed Jan 11, 2023
1 parent 29df690 commit ec8f49d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ If you want a consistent emoji style, you can set it in your ``conf.py`` file:
sphinxemoji_style = 'twemoji'
By default twemoji is obtained from a CDN. If you want to specify your own
source location (be it local or from another CDN), you can do so via the ``conf.py`` file:

.. code:: python
sphinxemoji_source = 'https://unpkg.com/twemoji@latest/dist/twemoji.min.js'
# or: sphinxemoji_source = 'my-local-twemoji.min.js'
You can find the list of all supported emoji codes `in the project's documentation page
<https://sphinxemojicodes.readthedocs.io/#supported-codes>`_.

Expand Down
16 changes: 10 additions & 6 deletions sphinxemoji/sphinxemoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
from . import __version__

emoji_styles = {
'twemoji': [
'https://unpkg.com/twemoji@latest/dist/twemoji.min.js',
'twemoji.js',
'twemoji.css',
],
'twemoji': {
'source': 'https://unpkg.com/twemoji@latest/dist/twemoji.min.js',
'libs': [
'twemoji.js',
'twemoji.css',
]
},
}


Expand Down Expand Up @@ -90,8 +92,10 @@ def copy_asset_files(app, exc):
def setup(app):
app.connect('build-finished', copy_asset_files)
style = app.config._raw_config.get('sphinxemoji_style')
source = app.config._raw_config.get('sphinxemoji_source', emoji_styles[style]['source'])
if style in emoji_styles:
for fname in emoji_styles[style]:
app.add_js_file(source)
for fname in emoji_styles[style]['libs']:
if fname.endswith('.js'):
app.add_js_file(fname)
elif fname.endswith('.css'):
Expand Down

0 comments on commit ec8f49d

Please sign in to comment.