Skip to content

Commit

Permalink
Adiciona link para criar issues no github
Browse files Browse the repository at this point in the history
  • Loading branch information
rougeth committed Sep 29, 2023
1 parent 6ed8e7d commit 9c5599a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.
55 changes: 55 additions & 0 deletions source/_ext/github_issues_url.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 0 additions & 2 deletions source/_ext/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions source/_templates/sidebar/navigation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="sidebar-tree">
{{ furo_navigation_tree }}
<p class="caption" role="heading">
<span class="caption-text">
Encontrou algum erro
<br>ou tem alguma sugestão?
</span>
</p>
<a href="{{ github_issues_url(root_doc, pagename, page_source_suffix) }}" style="color: #ff4e1b" target="blank" class="reference">Abra uma <i>issue</i> no Github</a>

</div>
22 changes: 22 additions & 0 deletions source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"sphinx.ext.githubpages",
"myst_parser",
# Local extensions
"github_issues_url",
"github_repos",
"template",
]
Expand All @@ -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.
#
Expand All @@ -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".
Expand Down

0 comments on commit 9c5599a

Please sign in to comment.