mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-01-19 17:58:26 +08:00
commit
5554c6e62d
40
.github/workflows/nonebot_plugin_docs.yml
vendored
Normal file
40
.github/workflows/nonebot_plugin_docs.yml
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
name: Release Nonebot Plugin Docs
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [ published ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '12'
|
||||
- run: npm ci
|
||||
- name: Build Docs
|
||||
env:
|
||||
VUEPRESS_BASE: '/docs/'
|
||||
run: npx vuepress build docs --dest packages/nonebot-plugin-docs/nonebot_plugin_docs/dist
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.8
|
||||
architecture: "x64"
|
||||
- name: Install Poetry
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install poetry
|
||||
|
||||
- name: Publish Package
|
||||
run: |
|
||||
export NONEBOT_VERSION=`poetry version -s`
|
||||
cd packages/nonebot-plugin-docs/
|
||||
poetry version $NONEBOT_VERSION
|
||||
poetry build
|
||||
poetry publish -u ${{secrets.PYPI_USERNAME}} -p ${{secrets.PYPI_PASSWORD}}
|
@ -29,7 +29,7 @@
|
||||
"author": "nonebot",
|
||||
"desc": "在本地浏览NoneBot文档",
|
||||
"name": "NoneBot离线文档",
|
||||
"repo": "yanyongyu/nonebot2/tree/master/packages/nonebot-plugin-docs"
|
||||
"repo": "nonebot/nonebot2/tree/master/packages/nonebot-plugin-docs"
|
||||
},
|
||||
{
|
||||
"id": "nonebot_plugin_sentry",
|
||||
|
27
packages/nonebot-plugin-docs/README.md
Normal file
27
packages/nonebot-plugin-docs/README.md
Normal file
@ -0,0 +1,27 @@
|
||||
<p align="center">
|
||||
<a href="https://v2.nonebot.dev/"><img src="https://raw.githubusercontent.com/nonebot/nonebot2/master/docs/.vuepress/public/logo.png" width="200" height="200" alt="nonebot"></a>
|
||||
</p>
|
||||
|
||||
<div align="center">
|
||||
|
||||
# nonebot-plugin-docs
|
||||
|
||||
_✨ NoneBot 本地文档插件 ✨_
|
||||
|
||||
</div>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://raw.githubusercontent.com/nonebot/nonebot2/master/LICENSE">
|
||||
<img src="https://img.shields.io/github/license/nonebot/nonebot2.svg" alt="license">
|
||||
</a>
|
||||
<a href="https://pypi.python.org/pypi/nonebot-plugin-docs">
|
||||
<img src="https://img.shields.io/pypi/v/nonebot-plugin-docs.svg" alt="pypi">
|
||||
</a>
|
||||
<img src="https://img.shields.io/badge/python-3.7+-blue.svg" alt="python">
|
||||
</p>
|
||||
|
||||
## 使用方式
|
||||
|
||||
加载插件并启动 Bot ,在浏览器内打开 `http://host:port/docs/`。
|
||||
|
||||
具体网址会在控制台内输出。
|
25
packages/nonebot-plugin-docs/nonebot_plugin_docs/__init__.py
Normal file
25
packages/nonebot-plugin-docs/nonebot_plugin_docs/__init__.py
Normal file
@ -0,0 +1,25 @@
|
||||
import importlib
|
||||
|
||||
import nonebot
|
||||
from nonebot.log import logger
|
||||
|
||||
|
||||
def init():
|
||||
driver = nonebot.get_driver()
|
||||
try:
|
||||
_module = importlib.import_module(
|
||||
f"nonebot_plugin_docs.drivers.{driver.type}")
|
||||
except ImportError:
|
||||
logger.warning(f"Driver {driver.type} not supported")
|
||||
return
|
||||
register_route = getattr(_module, "register_route")
|
||||
register_route(driver)
|
||||
host = str(driver.config.host)
|
||||
port = driver.config.port
|
||||
if host in ["0.0.0.0", "127.0.0.1"]:
|
||||
host = "localhost"
|
||||
logger.opt(colors=True).info(f"Nonebot docs will be running at: "
|
||||
f"<b><u>http://{host}:{port}/docs/</u></b>")
|
||||
|
||||
|
||||
init()
|
@ -0,0 +1,14 @@
|
||||
from pathlib import Path
|
||||
|
||||
from nonebot.drivers.fastapi import Driver
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
|
||||
def register_route(driver: Driver):
|
||||
app = driver.server_app
|
||||
|
||||
static_path = str((Path(__file__).parent / ".." / "dist").resolve())
|
||||
|
||||
app.mount("/docs",
|
||||
StaticFiles(directory=static_path, html=True),
|
||||
name="docs")
|
22
packages/nonebot-plugin-docs/pyproject.toml
Normal file
22
packages/nonebot-plugin-docs/pyproject.toml
Normal file
@ -0,0 +1,22 @@
|
||||
[tool.poetry]
|
||||
name = "nonebot-plugin-docs"
|
||||
version = "2.0.0a6.post1"
|
||||
description = "View NoneBot2 Docs Locally"
|
||||
authors = ["yanyongyu <yanyongyu_1@126.com>"]
|
||||
license = "MIT"
|
||||
readme = "README.md"
|
||||
homepage = "https://github.com/nonebot/nonebot2/blob/master/packages/nonebot-plugin-docs"
|
||||
repository = "https://github.com/nonebot/nonebot2"
|
||||
keywords = ["nonebot", "nonebot2", "docs"]
|
||||
include = ["nonebot_plugin_docs/dist/**/*"]
|
||||
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.7"
|
||||
nonebot2 = "^2.0.0-alpha.1"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
build-backend = "poetry.core.masonry.api"
|
Loading…
Reference in New Issue
Block a user