-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3a913ef
Showing
10 changed files
with
258 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# This file is for unifying the coding style for different editors and IDEs | ||
# editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
indent_size = 4 | ||
end_of_line = lf | ||
charset = utf-8 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
indent_style = space | ||
max_line_length = 90 | ||
|
||
[*.{yaml,yml}] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: Build | ||
on: | ||
push: | ||
pull_request: | ||
release: | ||
types: [published] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: 🔨 Build distribution | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: 🏗 Set up Python 3.7 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.7" | ||
- name: 🏗 Install build dependencies | ||
run: | | ||
python -m pip install wheel --user | ||
- name: 🔨 Build a binary wheel and a source tarball | ||
run: | | ||
python setup.py sdist bdist_wheel | ||
- name: ⬆ Upload build result | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: dist | ||
path: dist | ||
|
||
pre-commit: | ||
name: 🧹 Pre-commit | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: 🏗 Set up Python 3.11 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.11" | ||
- name: 🏗 Set up dev dependencies | ||
run: | | ||
pip install pre-commit | ||
- name: 🚀 Run pre-commit | ||
run: | | ||
pre-commit run --all-files --show-diff-on-failure | ||
publish-on-pypi: | ||
name: 📦 Publish tagged releases to PyPI | ||
if: github.event_name == 'release' && github.repository == 'OctoPrint/mkdocs-site-urls' | ||
needs: | ||
- build | ||
- pre-commit | ||
runs-on: ubuntu-latest | ||
environment: release | ||
permissions: | ||
id-token: write | ||
steps: | ||
- name: ⬇ Download build result | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: dist | ||
path: dist | ||
- name: 📦 Publish to index | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
password: ${{ secrets.pypi_token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
build | ||
dist | ||
*.egg-info | ||
*.egg | ||
__pycache__ | ||
*.pyc | ||
*.pyo | ||
*.pyd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
default_language_version: | ||
python: python3.11 | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.4.0 | ||
hooks: | ||
- id: end-of-file-fixer | ||
- id: trailing-whitespace | ||
- id: check-case-conflict | ||
- id: check-merge-conflict | ||
- id: fix-encoding-pragma | ||
args: ["--remove"] | ||
- repo: https://github.com/asottile/pyupgrade | ||
rev: v3.9.0 | ||
hooks: | ||
- id: pyupgrade | ||
args: ["--py37-plus"] | ||
- repo: https://github.com/pre-commit/mirrors-isort | ||
rev: v5.10.1 | ||
hooks: | ||
- id: isort | ||
- repo: https://github.com/psf/black | ||
rev: 23.7.0 | ||
hooks: | ||
- id: black | ||
- repo: https://github.com/pycqa/flake8 | ||
rev: 6.0.0 | ||
hooks: | ||
- id: flake8 | ||
args: [--config=setup.cfg] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Gina Häußge | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# MkDocs Site URLs | ||
|
||
A MkDocs plugin that adds support for site-relative `site:` URLs. | ||
|
||
Example: | ||
|
||
| URL | site_url | resulting URL | | ||
| --- | -------- | ------------- | | ||
| `site:images/foo.png` | `https://example.com/` | `/images/foo.png` | | ||
| `site:images/foo.png` | `https://example.com/bar/` | `/bar/images/foo.png` | | ||
|
||
## Usage | ||
|
||
1. Install the plugin from PyPI | ||
```bash | ||
pip install mkdocs-site-urls | ||
``` | ||
2. Add the `site-urls` plugin to your `mkdocs.yml` plugins section: | ||
```yaml | ||
plugins: | ||
- site-urls | ||
``` | ||
There are no configuration options. | ||
3. Start using site-relative URLs in your Markdown files by prefixing them with `site:`: | ||
```markdown | ||
[Link to another page](site:another-page/relative/to/the/site/root) | ||
![Image](site:images/foo.png) | ||
``` | ||
|
||
## How it works | ||
|
||
The plugin hooks into the [`on_page_content` event](https://www.mkdocs.org/dev-guide/plugins/#on_page_content) | ||
and replaces all URLs in `href` or `src` attributes in the rendered HTML with the corresponding site-relative URLs. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT license, see the [LICENSE](https://github.com/OctoPrint/mkdocs-site-urls/blob/main/LICENSE) file for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import re | ||
import urllib.parse | ||
|
||
import mkdocs.plugins | ||
|
||
SITE_URLS_REGEX = re.compile(r'(href|src)="site:([^"]+)"', re.IGNORECASE) | ||
|
||
logger = mkdocs.plugins.get_plugin_logger(__name__) | ||
|
||
|
||
class SiteUrlsPlugin(mkdocs.plugins.BasePlugin): | ||
@mkdocs.plugins.event_priority(50) | ||
def on_page_content(self, html, page, config, files): | ||
site_url = config["site_url"] | ||
path = urllib.parse.urlparse(site_url).path | ||
|
||
if not path: | ||
path = "/" | ||
if not path.endswith("/"): | ||
path += "/" | ||
|
||
def _replace(match): | ||
param = match.group(1) | ||
url = match.group(2) | ||
if url.startswith("/"): | ||
url = url[1:] | ||
|
||
logger.info(f"Replacing site:{match.group(2)} with {path}{url}...") | ||
return f'{param}="{path}{url}"' | ||
|
||
return SITE_URLS_REGEX.sub(_replace, html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[build-system] | ||
requires = ["setuptools>=40.8.0", "wheel"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.black] | ||
line-length = 90 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[metadata] | ||
license_file = LICENSE | ||
|
||
[bdist_wheel] | ||
universal = 1 | ||
|
||
[flake8] | ||
max-line-length = 90 | ||
extend-ignore = E203, E231, E265, E266, E402, E501, E731, B023, B903, B904, B907, B950, W503 | ||
select = B,C,E,F,W,T4,B9 | ||
|
||
[isort] | ||
multi_line_output = 3 | ||
include_trailing_comma = True | ||
force_grid_wrap = 0 | ||
use_parentheses = True | ||
ensure_newline_before_comments = True | ||
line_length = 90 | ||
known_first_party = | ||
mkdocs_site_urls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from setuptools import find_packages, setup | ||
|
||
with open("README.md", encoding="utf-8") as f: | ||
long_description = f.read() | ||
|
||
setup( | ||
name="mkdocs-site-urls", | ||
version="0.1.0", | ||
author="Gina Häußge", | ||
author_email="[email protected]", | ||
url="https://github.com/OctoPrint/mkdocs-site-urls", | ||
project_urls={"Source": "https://github.com/OctoPrint/mkdocs-site-urls"}, | ||
keywords=["mkdocs", "plugin"], | ||
packages=find_packages(), | ||
license="MIT", | ||
description="A MkDocs plugin that adds support for site-relative URLs", | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
include_package_data=True, | ||
python_requires=">=3.7", | ||
entry_points={"mkdocs.plugins": ["site-urls = mkdocs_site_urls:SiteUrlsPlugin"]}, | ||
) |