Skip to content

Commit

Permalink
Merge pull request #37 from neatc0der/release/v2.2.1
Browse files Browse the repository at this point in the history
Release/v2.2.1
  • Loading branch information
neatc0der authored Jan 28, 2022
2 parents f6bfc8f + 1fc1df8 commit cd1d62c
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 18 deletions.
28 changes: 25 additions & 3 deletions .build/mkdocs_markmap_build/distribution.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import os
import sys
from typing import List
import requests

from twine.cli import dispatch

from mkdocs_markmap.__meta__ import PROJECT_NAME
from .common import AssetDownloader, GithubHandler
from mkdocs_markmap.__meta__ import PROJECT_NAME, REPOSITORY_URL
from .common import AssetDownloader


MASTODON_URL: str = "https://fosstodon.org"


class DistributionHandler(object):
def __init__(self, tag: str) -> None:
self._collector = AssetDownloader(tag)
self._collector: AssetDownloader = AssetDownloader(tag)

def distribute(self, dry_run: bool = True):
assets: List[str] = self._collector.get_assets_from_release()
Expand All @@ -27,3 +31,21 @@ def distribute(self, dry_run: bool = True):

else:
dispatch(['upload', *assets])


class MastodonHandler(object):
def __init__(self, tag: str) -> None:
self.tag = tag
self._url: str = f"{REPOSITORY_URL}/releases/{tag}"

def post(self):
auth_token: str = os.environ.get('MASTODON_TOKEN')
if auth_token is None:
print('environment variable "MASTODON_TOKEN" is not set')
sys.exit(1)

response: requests.Response = requests.post(f"{MASTODON_URL}/api/v1/statuses", data={
"status": f"🆕 {PROJECT_NAME} {self.tag}\n{self._url}",
}, headers={"Authorization": f"Bearer {auth_token}"})
if not response.ok:
print(f"unable to post status on mastodon: {response.text} ({response.status_code})")
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)
11 changes: 6 additions & 5 deletions mkdocs_markmap/__meta__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PACKAGE_NAME = 'mkdocs_markmap'
PROJECT_NAME = PACKAGE_NAME.replace('_', '-')
PROJECT_VERSION = '2.2.0'
PACKAGE_NAME: str = 'mkdocs_markmap'
PROJECT_NAME: str = PACKAGE_NAME.replace('_', '-')
PROJECT_VERSION: str = '2.2.1'

OWNER = 'neatc0der'
REPOSITORY_NAME = f'{OWNER}/{PROJECT_NAME}'
OWNER: str = 'neatc0der'
REPOSITORY_NAME: str = f'{OWNER}/{PROJECT_NAME}'
REPOSITORY_URL: str = f'https://github.com/{REPOSITORY_NAME}'
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
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from setuptools import setup, find_packages
from typing import List

from mkdocs_markmap.__meta__ import PROJECT_NAME, PROJECT_VERSION, REPOSITORY_NAME
from mkdocs_markmap.__meta__ import PROJECT_NAME, PROJECT_VERSION, REPOSITORY_URL


def readme() -> str:
Expand Down Expand Up @@ -30,7 +30,7 @@ def get_requirements(filename: str, base_dir: str = 'requirements') -> List[str]
long_description=readme(),
long_description_content_type='text/markdown',
keywords='mkdocs python markdown markmap mindmap include',
url=f'https://github.com/{REPOSITORY_NAME}',
url=REPOSITORY_URL,
author='neatc0der',
author_email='',
license='MIT',
Expand Down
10 changes: 9 additions & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sys.path.insert(0, str(PROJECT_PATH / '.build'))

from mkdocs_markmap.__meta__ import PROJECT_VERSION
from mkdocs_markmap_build.distribution import DistributionHandler
from mkdocs_markmap_build.distribution import DistributionHandler, MastodonHandler
from mkdocs_markmap_build.info import ReleaseInfo
from mkdocs_markmap_build.release import ReleaseHandler

Expand Down Expand Up @@ -64,6 +64,14 @@ def info(c, tag=None, github=False, pypi=False):


@task
def mastodon(c, tag=TARGET_TAG):
print(f'post status: {tag}')

handler: MastodonHandler = MastodonHandler(tag)
handler.post()


@task(post=[mastodon])
def distribute(c, tag=TARGET_TAG, dry_run=True):
print(f'distribute release: {tag}')

Expand Down

0 comments on commit cd1d62c

Please sign in to comment.