Skip to content

Commit

Permalink
Merge branch 'master' into zh_CN
Browse files Browse the repository at this point in the history
  • Loading branch information
dpy013 committed Jul 15, 2021
2 parents b4a471b + 6f5443c commit 8091fab
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 36 deletions.
34 changes: 15 additions & 19 deletions .github/workflows/tox.yml
Expand Up @@ -55,41 +55,37 @@ jobs:
fail_ci_if_error: false

lint:
strategy:
fail-fast: false
max-parallel: 4
matrix:
tox-env: ['flake8', 'markdown-lint', 'jshint', 'csslint']
env:
TOXENV: ${{ matrix.tox-env }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.9
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip tox
- name: Setup Node
if: ${{ matrix.tox-env != 'flake8' }}
uses: actions/setup-node@v1
with:
node-version: '10'
node-version: 14
- name: Install Node dependencies
if: ${{ matrix.tox-env != 'flake8' }}
run: |
if [[ "$TOXENV" == 'markdown-lint' ]]; then npm install -g markdownlint-cli; fi
if [[ "$TOXENV" == 'jshint' ]]; then npm install -g jshint; fi
if [[ "$TOXENV" == 'csslint' ]]; then npm install -g csslint; fi
- name: Run tox
run: python -m tox
npm install -g markdownlint-cli jshint csslint
- name: Check with flake8
if: always()
run: python -m tox -e flake8
- name: Check with markdown-lint
if: always()
run: python -m tox -e markdown-lint
- name: Check with jshint
if: always()
run: python -m tox -e jshint
- name: Check with csslint
if: always()
run: python -m tox -e csslint

translation:
strategy:
fail-fast: false
max-parallel: 4
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions mkdocs/commands/build.py
@@ -1,7 +1,7 @@
import logging
import os
import gzip
from urllib.parse import urlparse
from urllib.parse import urlsplit

from jinja2.exceptions import TemplateNotFound
import jinja2
Expand Down Expand Up @@ -76,7 +76,7 @@ def _build_template(name, template, files, config, nav):
# See https://github.com/mkdocs/mkdocs/issues/77.
# However, if site_url is not set, assume the docs root and server root
# are the same. See https://github.com/mkdocs/mkdocs/issues/1598.
base_url = urlparse(config['site_url'] or '/').path
base_url = urlsplit(config['site_url'] or '/').path
else:
base_url = utils.get_relative_url('.', name)

Expand Down
4 changes: 2 additions & 2 deletions mkdocs/commands/serve.py
@@ -1,7 +1,7 @@
import logging
import shutil
import tempfile
from urllib.parse import urlparse
from urllib.parse import urlsplit
from os.path import isdir, isfile, join

from mkdocs.commands.build import build
Expand All @@ -28,7 +28,7 @@ def serve(config_file=None, dev_addr=None, strict=None, theme=None,
site_dir = tempfile.mkdtemp(prefix='mkdocs_')

def mount_path(config):
return urlparse(config['site_url'] or '/').path
return urlsplit(config['site_url'] or '/').path

def builder():
log.info("Building documentation...")
Expand Down
8 changes: 4 additions & 4 deletions mkdocs/config/config_options.py
@@ -1,7 +1,7 @@
import os
from collections import namedtuple
from collections.abc import Sequence
from urllib.parse import urlparse, urlunparse
from urllib.parse import urlsplit, urlunsplit
import ipaddress
import markdown

Expand Down Expand Up @@ -297,14 +297,14 @@ def run_validation(self, value):
return value

try:
parsed_url = urlparse(value)
parsed_url = urlsplit(value)
except (AttributeError, TypeError):
raise ValidationError("Unable to parse the URL.")

if parsed_url.scheme:
if self.is_dir and not parsed_url.path.endswith('/'):
parsed_url = parsed_url._replace(path=f'{parsed_url.path}/')
return urlunparse(parsed_url)
return urlunsplit(parsed_url)

raise ValidationError(
"The URL isn't valid, it should include the http:// (scheme)")
Expand All @@ -319,7 +319,7 @@ class RepoURL(URL):
"""

def post_validation(self, config, key_name):
repo_host = urlparse(config['repo_url']).netloc.lower()
repo_host = urlsplit(config['repo_url']).netloc.lower()
edit_uri = config.get('edit_uri')

# derive repo_name from repo_url if unset
Expand Down
4 changes: 2 additions & 2 deletions mkdocs/structure/nav.py
@@ -1,5 +1,5 @@
import logging
from urllib.parse import urlparse
from urllib.parse import urlsplit

from mkdocs.structure.pages import Page
from mkdocs.utils import nest_paths
Expand Down Expand Up @@ -124,7 +124,7 @@ def get_navigation(files, config):

links = _get_by_type(items, Link)
for link in links:
scheme, netloc, path, params, query, fragment = urlparse(link.url)
scheme, netloc, path, query, fragment = urlsplit(link.url)
if scheme or netloc:
log.debug(
"An external link to '{}' is included in "
Expand Down
10 changes: 5 additions & 5 deletions mkdocs/structure/pages.py
@@ -1,6 +1,6 @@
import os
import logging
from urllib.parse import urlparse, urlunparse, urljoin
from urllib.parse import urlsplit, urlunsplit, urljoin
from urllib.parse import unquote as urlunquote

import markdown
Expand Down Expand Up @@ -98,7 +98,7 @@ def _set_canonical_url(self, base):
if not base.endswith('/'):
base += '/'
self.canonical_url = urljoin(base, self.url)
self.abs_url = urlparse(self.canonical_url).path
self.abs_url = urlsplit(self.canonical_url).path
else:
self.canonical_url = None
self.abs_url = None
Expand Down Expand Up @@ -202,7 +202,7 @@ def run(self, root):
return root

def path_to_url(self, url):
scheme, netloc, path, params, query, fragment = urlparse(url)
scheme, netloc, path, query, fragment = urlsplit(url)

if (scheme or netloc or not path or url.startswith('/') or url.startswith('\\')
or AMP_SUBSTITUTE in url or '.' not in os.path.split(path)[-1]):
Expand All @@ -224,8 +224,8 @@ def path_to_url(self, url):
return url
target_file = self.files.get_file_from_path(target_path)
path = target_file.url_relative_to(self.file)
components = (scheme, netloc, path, params, query, fragment)
return urlunparse(components)
components = (scheme, netloc, path, query, fragment)
return urlunsplit(components)


class _RelativePathExtension(Extension):
Expand Down
4 changes: 2 additions & 2 deletions mkdocs/utils/__init__.py
Expand Up @@ -17,7 +17,7 @@
import importlib_metadata
from collections import defaultdict
from datetime import datetime, timezone
from urllib.parse import urlparse
from urllib.parse import urlsplit
from yaml_env_tag import construct_env_tag
from mergedeep import merge

Expand Down Expand Up @@ -291,7 +291,7 @@ def normalize_url(path, page=None, base=''):
def _get_norm_url(path):
path = path_to_url(path or '.')
# Allow links to be fully qualified URLs
parsed = urlparse(path)
parsed = urlsplit(path)
if parsed.scheme or parsed.netloc or path.startswith(('/', '#')):
return path, True
return path, False
Expand Down

0 comments on commit 8091fab

Please sign in to comment.