Skip to content

Commit c32cfe2

Browse files
committed
GH-8: Download and cache the assets on run
1 parent 02d6970 commit c32cfe2

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

setup.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
from distutils import dir_util
2-
from os.path import dirname, join
3-
from urllib.request import urlretrieve
4-
51
from setuptools import setup
62

73
if __name__ == "__main__":
8-
cdn = "https://cdnjs.cloudflare.com/ajax/libs/mermaid/9.4.3/mermaid.js"
9-
static = join(dirname(__file__), "src", "django_mermaid", "static")
10-
dir_util.create_tree(static, ["mermaid.js"])
11-
urlretrieve(cdn, join(static, "mermaid.js"))
124
setup()

src/django_mermaid/apps.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
from distutils import dir_util
2+
from os.path import dirname, join, exists
3+
from urllib.request import urlretrieve
4+
15
from django.apps import AppConfig
26

37

48
class MermaidConfig(AppConfig):
59
name = "django_mermaid"
10+
11+
def ready(self):
12+
"""Download mermaid.js from CDN if not already present"""
13+
cdn = "https://cdnjs.cloudflare.com/ajax/libs/mermaid/9.4.3/mermaid.js"
14+
static = join(dirname(__file__), "static")
15+
if not exists(join(static, "mermaid.js")):
16+
dir_util.create_tree(static, ["mermaid.js"])
17+
urlretrieve(cdn, join(static, "mermaid.js"))

0 commit comments

Comments
 (0)