Skip to content

Commit

Permalink
Merges
Browse files Browse the repository at this point in the history
  • Loading branch information
neatc0der committed Jan 28, 2022
2 parents ac200cb + 7d490da commit 1fc1df8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,33 @@ extra_javascript:
:warning: The urls need to contain one of these keywords to be considered as deviation from default:
* `d3`
* `markmap-d3`
* `markmap-lib`
* `markmap-view`
## Troubleshooting
### Nav tree lists markmaps
1. Move your markmap files to a separate folder next to `docs`, e.g. `mindmaps`
2. Configure `base_path` accordingly (see [Advanced Settings](#advanced-settings))
### Static javascript files not working
1. Ensure naming of javascript files matches the scheme (see [Advanced Settings](#advanced-settings))
2. Copy all javascript files to `doc/js/`, otherwise `mkdocs` will not copy static files to `site/`
3. Define all files in `extra_javascript`, e.g.
```yaml
extra_javascript:
- js/markmap-d3.js
- js/markmap-lib.js
- js/markmap-view.js
```
### Usage of proxy is prevent download of javascript files
Usually proxies should be supported by `requests`, which is used for downloading all required javascript files. If the issue remains, try downloading the files yourself and store them accordingly (see [Static javascript files not working](#static-javascript-files-not-working))
## Credits :clap:
Expand Down
3 changes: 3 additions & 0 deletions changelog/v2.2.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# v2.2.1

* Fixes [static javascript files bug](https://github.com/neatc0der/mkdocs-markmap/issues/35)
2 changes: 1 addition & 1 deletion mkdocs_markmap/__meta__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PACKAGE_NAME: str = 'mkdocs_markmap'
PROJECT_NAME: str = PACKAGE_NAME.replace('_', '-')
PROJECT_VERSION: str = '2.2.0'
PROJECT_VERSION: str = '2.2.1'

OWNER: str = 'neatc0der'
REPOSITORY_NAME: str = f'{OWNER}/{PROJECT_NAME}'
Expand Down
17 changes: 12 additions & 5 deletions mkdocs_markmap/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from bs4 import BeautifulSoup, ResultSet, Tag
from mkdocs.plugins import BasePlugin
from mkdocs.structure.pages import Page
from mkdocs.config.base import Config
from mkdocs.config.base import Config, load_config
from mkdocs.config.config_options import Type as PluginType

from .defaults import MARKMAP
Expand All @@ -21,6 +21,7 @@
STYLE_PATH: Path = STATICS_PATH / 'mkdocs-markmap.css'
SCRIPT_PATH: Path = STATICS_PATH / 'mkdocs-markmap.js'


class MarkmapPlugin(BasePlugin):
"""
Plugin for markmap support
Expand Down Expand Up @@ -59,10 +60,15 @@ def markmap(self) -> Dict[str, str]:

def _load_scripts(self, soup: BeautifulSoup, script_base_url: str, js_path: Path) -> None:
for script_url in self.markmap.values():
try:
src: str = script_base_url + download(js_path, script_url)
except Exception as e:
log.error(f'unable to download script: {script_url}')
if script_url.lower().startswith("http"):
try:
src: str = script_base_url + download(js_path, script_url)
except Exception as e:
log.error(f'unable to download script: {script_url}')
src = script_url

else:
log.info(f"static script detected: {script_url}")
src = script_url

script: Tag = soup.new_tag('script', src=src, type='text/javascript')
Expand All @@ -88,6 +94,7 @@ def on_config(self, config: Config) -> Config:
for key, value in config['plugins'].get('markmap').config.items()
if key in MarkmapExtension.config_defaults
}
self.config['extra_javascript'] = config.get('extra_javascript', [])

return config

Expand Down

0 comments on commit 1fc1df8

Please sign in to comment.