Skip to content

Commit

Permalink
GH-8: Download and cache the assets on run
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtyomVancyan committed Mar 13, 2023
1 parent 02d6970 commit c32cfe2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 0 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
from distutils import dir_util
from os.path import dirname, join
from urllib.request import urlretrieve

from setuptools import setup

if __name__ == "__main__":
cdn = "https://cdnjs.cloudflare.com/ajax/libs/mermaid/9.4.3/mermaid.js"
static = join(dirname(__file__), "src", "django_mermaid", "static")
dir_util.create_tree(static, ["mermaid.js"])
urlretrieve(cdn, join(static, "mermaid.js"))
setup()
12 changes: 12 additions & 0 deletions src/django_mermaid/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
from distutils import dir_util
from os.path import dirname, join, exists
from urllib.request import urlretrieve

from django.apps import AppConfig


class MermaidConfig(AppConfig):
name = "django_mermaid"

def ready(self):
"""Download mermaid.js from CDN if not already present"""
cdn = "https://cdnjs.cloudflare.com/ajax/libs/mermaid/9.4.3/mermaid.js"
static = join(dirname(__file__), "static")
if not exists(join(static, "mermaid.js")):
dir_util.create_tree(static, ["mermaid.js"])
urlretrieve(cdn, join(static, "mermaid.js"))

0 comments on commit c32cfe2

Please sign in to comment.