diff --git a/source/_ext/github_issues_url.py b/source/_ext/github_issues_url.py new file mode 100644 index 0000000..30e0e96 --- /dev/null +++ b/source/_ext/github_issues_url.py @@ -0,0 +1,55 @@ +from urllib.parse import urljoin +from urllib.parse import urlencode + + +def get_page_url(app, docname): + site_base_url = app.config.html_baseurl + document_uri = app.builder.get_relative_uri(app.builder.config.master_doc, docname) + return urljoin(site_base_url, document_uri) + + +def get_page_source_url(context, filepath): + return "{source_url}/blob/{branch}/{dir}/{filepath}".format( + source_url=context["source_url"], + branch=context["source_branch"], + dir=context["source_dir"], + filepath=filepath, + + ) + + +def setup_github_issues_url(app, pagename, templatename, context, doctree): + def github_issues_url(root_doc, pagename, page_source_suffix): + if not root_doc or not page_source_suffix: + return "" + + document_path = pagename + page_source_suffix + + page_url = get_page_url(app, pagename) + page_source_url = get_page_source_url(context, document_path) + + + source_url = context["source_url"] + source_url = context["source_url"] + + new_issue_context = { + "document_path": document_path, + "page_url": page_url, + "page_source_url": page_source_url, + } + + new_issue_title = context["new_issue_title"].format_map(new_issue_context) + new_issue_body = context["new_issue_body"].format_map(new_issue_context) + url_params = urlencode({ + "title": new_issue_title, + "body": new_issue_body, + }) + + return f"{source_url}/issues/new?{url_params}" + + context["github_issues_url"] = github_issues_url + + + +def setup(app): + app.connect("html-page-context", setup_github_issues_url) diff --git a/source/_ext/template.py b/source/_ext/template.py index d345db0..d497423 100644 --- a/source/_ext/template.py +++ b/source/_ext/template.py @@ -4,8 +4,6 @@ def template(app, docname: str, source: list[str]): return content = content.replace("!template", "", 1) - print("*"*80) - print(app.config.templates_context) rendered = app.builder.templates.render_string(content, app.config.templates_context) source[0] = rendered diff --git a/source/_templates/sidebar/navigation.html b/source/_templates/sidebar/navigation.html new file mode 100644 index 0000000..3d4270a --- /dev/null +++ b/source/_templates/sidebar/navigation.html @@ -0,0 +1,11 @@ + diff --git a/source/conf.py b/source/conf.py index b3c2275..b389d69 100644 --- a/source/conf.py +++ b/source/conf.py @@ -40,6 +40,7 @@ "sphinx.ext.githubpages", "myst_parser", # Local extensions + "github_issues_url", "github_repos", "template", ] @@ -52,6 +53,18 @@ # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] +new_issue_title = "Melhoria na página: {document_path}" +new_issue_body = """ +Página: {page_url} +Arquivo: {page_source_url} + +--- + +### Descrição + +... +""" + # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # @@ -74,6 +87,15 @@ # html_theme = 'furo' +html_context = { + # Extension: github_issues_url + "source_url": "https://github.com/apyb/wiki", + "source_branch": "main", + "source_dir": "source", + "new_issue_title": new_issue_title, + "new_issue_body": new_issue_body, +} + # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css".