mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 03:35:51 +00:00
Dactyl - fix key inheritence from target, pre-gen sidebar; fee voting - fix header hierarchy
This commit is contained in:
@@ -35,7 +35,7 @@ targets:
|
||||
- multicode_tabs
|
||||
- standardize_header_ids
|
||||
- buttonize
|
||||
template: template-contentonly.html
|
||||
template: template-contentwithtoc.html
|
||||
image_subs:
|
||||
"img/funds_flow_diagram.png": https://ripple.com/wp-content/uploads/2016/03/funds_flow_diagram.png
|
||||
"img/e2g-01.png": https://ripple.com/wp-content/themes/ripple-beta/assets/img/e2g-01.png
|
||||
@@ -75,7 +75,7 @@ pages:
|
||||
html: reference-rippled.html
|
||||
md: reference-rippled.md
|
||||
ripple.com: https://ripple.com/build/rippled-apis/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -95,7 +95,7 @@ pages:
|
||||
html: reference-ledger-format.html
|
||||
md: reference-ledger-format.md
|
||||
ripple.com: https://ripple.com/build/ledger-format/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -109,7 +109,7 @@ pages:
|
||||
filters:
|
||||
- remove_doctoc
|
||||
- add_version
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -119,7 +119,7 @@ pages:
|
||||
html: reference-data-api.html
|
||||
md: reference-data-api.md
|
||||
ripple.com: https://ripple.com/build/data-api-v2/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -130,7 +130,7 @@ pages:
|
||||
html: tutorial-rippleapi-beginners-guide.html
|
||||
md: tutorial-rippleapi-beginners-guide.md
|
||||
ripple.com: https://ripple.com/build/rippleapi-beginners-guide/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -140,7 +140,7 @@ pages:
|
||||
html: tutorial-rippled-setup.html
|
||||
md: tutorial-rippled-setup.md
|
||||
ripple.com: https://ripple.com/build/rippled-setup/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -151,7 +151,7 @@ pages:
|
||||
html: tutorial-reliable-transaction-submission.html
|
||||
md: tutorial-reliable-transaction-submission.md
|
||||
ripple.com: https://ripple.com/build/reliable-transaction-submission/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -161,7 +161,7 @@ pages:
|
||||
html: tutorial-multisign.html
|
||||
md: tutorial-multisign.md
|
||||
ripple.com: https://ripple.com/build/how-to-multi-sign/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
|
||||
# Concepts are introductions that explain a topic.
|
||||
# In the Dev Portal, these are mostly summaries of RCL features.
|
||||
@@ -170,7 +170,7 @@ pages:
|
||||
html: concept-paths.html
|
||||
md: concept-paths.md
|
||||
ripple.com: https://ripple.com/build/paths/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -180,7 +180,7 @@ pages:
|
||||
html: concept-fees.html
|
||||
md: concept-fees.md
|
||||
ripple.com: https://ripple.com/knowledge_center/fees-disambiguation/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -190,7 +190,7 @@ pages:
|
||||
html: concept-transfer-fees.html
|
||||
md: concept-transfer-fees.md
|
||||
ripple.com: https://ripple.com/knowledge_center/transfer-fees/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -200,7 +200,7 @@ pages:
|
||||
html: concept-transaction-cost.html
|
||||
md: concept-transaction-cost.md
|
||||
ripple.com: https://ripple.com/build/transaction-cost/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -210,7 +210,7 @@ pages:
|
||||
html: concept-fee-voting.html
|
||||
md: concept-fee-voting.md
|
||||
ripple.com: https://ripple.com/build/fee-voting/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -220,7 +220,7 @@ pages:
|
||||
html: concept-reserves.html
|
||||
md: concept-reserves.md
|
||||
ripple.com: https://ripple.com/build/reserves/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -230,7 +230,7 @@ pages:
|
||||
html: concept-freeze.html
|
||||
md: concept-freeze.md
|
||||
ripple.com: https://ripple.com/build/freeze/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -240,7 +240,7 @@ pages:
|
||||
html: concept-amendments.html
|
||||
md: concept-amendments.md
|
||||
ripple.com: https://ripple.com/build/amendments/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -250,7 +250,7 @@ pages:
|
||||
html: concept-stand-alone-mode.html
|
||||
md: concept-stand-alone-mode.md
|
||||
ripple.com: https://ripple.com/build/stand-alone-mode/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -260,7 +260,7 @@ pages:
|
||||
html: concept-noripple.html
|
||||
md: concept-noripple.md
|
||||
ripple.com: https://ripple.com/knowledge_center/understanding-the-noripple-flag/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -271,7 +271,7 @@ pages:
|
||||
html: concept-issuing-and-operational-addresses.html
|
||||
md: concept-issuing-and-operational-addresses.md
|
||||
ripple.com: https://ripple.com/knowledge_center/issuing-operational-addresses/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -282,7 +282,7 @@ pages:
|
||||
html: tutorial-gateway-guide.html
|
||||
md: tutorial-gateway-guide.md
|
||||
ripple.com: https://ripple.com/build/gateway-guide/
|
||||
sidebar: true
|
||||
sidebar: toc
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -292,7 +292,7 @@ pages:
|
||||
category: API Tools
|
||||
html: ripple-api-tool.html
|
||||
ripple.com: https://ripple.com/build/websocket-tool/
|
||||
sidebar: true
|
||||
sidebar: custom
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -305,7 +305,7 @@ pages:
|
||||
methods_js: js/apitool-methods-data_v2.js
|
||||
rest_host: https://data.ripple.com
|
||||
doc_page: reference-data-api.html
|
||||
sidebar: true
|
||||
sidebar: custom
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
@@ -318,7 +318,7 @@ pages:
|
||||
methods_js: js/apitool-methods-jsonrpc.js
|
||||
rest_host: http://localhost/rippled
|
||||
doc_page: reference-rippled.html
|
||||
sidebar: true
|
||||
sidebar: custom
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
|
||||
@@ -44,7 +44,8 @@ logger = logging.getLogger()
|
||||
RESERVED_KEYS_TARGET = [
|
||||
"name",
|
||||
"display_name",
|
||||
"filters"
|
||||
"filters",
|
||||
"image_subs",
|
||||
]
|
||||
filters = {}
|
||||
def load_config(config_file=DEFAULT_CONFIG_FILE):
|
||||
@@ -76,15 +77,16 @@ def load_config(config_file=DEFAULT_CONFIG_FILE):
|
||||
for filter_name in filternames:
|
||||
filters[filter_name] = import_module("filter_"+filter_name)
|
||||
|
||||
# Make pages inherit arbitrary keys from targets
|
||||
for target in config["targets"]:
|
||||
pages = get_pages(target)
|
||||
for p in pages:
|
||||
for key,val in target.items():
|
||||
if key in RESERVED_KEYS_TARGET:
|
||||
continue
|
||||
elif key not in p:
|
||||
p[key] = val
|
||||
def page_keys_from_target(target):
|
||||
"""Make pages inherit arbitrary keys from a target"""
|
||||
target = get_target(target)
|
||||
pages = get_pages(target)
|
||||
for p in pages:
|
||||
for key,val in target.items():
|
||||
if key in RESERVED_KEYS_TARGET:
|
||||
continue
|
||||
elif key not in p:
|
||||
p[key] = val
|
||||
|
||||
|
||||
def substitute_links_for_target(soup, target):
|
||||
@@ -360,28 +362,55 @@ def setup_html_env():
|
||||
env.trim_blocks = True
|
||||
return env
|
||||
|
||||
def toc_from_headers(html_string):
|
||||
"""make a table of contents from headers"""
|
||||
soup = BeautifulSoup(html_string, "html.parser")
|
||||
headers = soup.find_all(name=re.compile("h[1-3]"), id=True)
|
||||
toc_s = ""
|
||||
for h in headers:
|
||||
if h.name == "h1":
|
||||
toc_level = "level-1"
|
||||
elif h.name == "h2":
|
||||
toc_level = "level-2"
|
||||
else:
|
||||
toc_level = "level-3"
|
||||
|
||||
new_a = soup.new_tag("a", href="#"+h["id"])
|
||||
if h.string:
|
||||
new_a.string = h.string
|
||||
else:
|
||||
new_a.string = " ".join(h.strings)
|
||||
new_li = soup.new_tag("li")
|
||||
new_li["class"] = toc_level
|
||||
new_li.append(new_a)
|
||||
|
||||
toc_s += str(new_li)+"\n"
|
||||
|
||||
return str(toc_s)
|
||||
|
||||
def render_pages(target=None, for_pdf=False, bypass_errors=False):
|
||||
"""Parse and render all pages in target, writing files to out_path."""
|
||||
target = get_target(target)
|
||||
pages = get_pages(target)
|
||||
categories = get_categories(pages)
|
||||
page_keys_from_target(target)
|
||||
|
||||
# Insert generated HTML into templates using this Jinja environment
|
||||
env = setup_html_env()
|
||||
|
||||
if for_pdf:
|
||||
if "pdf_template" in target:
|
||||
logging.info("reading pdf template from target...")
|
||||
logging.debug("reading pdf template %s from target..." % target["pdf_template"])
|
||||
default_template = env.get_template(target["pdf_template"])
|
||||
else:
|
||||
logging.info("reading default pdf template...")
|
||||
logging.debug("reading default pdf template %s..." % config["pdf_template"])
|
||||
default_template = env.get_template(config["pdf_template"])
|
||||
else:
|
||||
if "template" in target:
|
||||
logging.info("reading HTML template from target...")
|
||||
logging.debug("reading HTML template %s from target..." % target["template"])
|
||||
default_template = env.get_template(target["template"])
|
||||
else:
|
||||
logging.info("reading default HTML template...")
|
||||
logging.debug("reading default HTML template %s..." % config["default_template"])
|
||||
default_template = env.get_template(config["default_template"])
|
||||
|
||||
for currentpage in pages:
|
||||
@@ -404,14 +433,21 @@ def render_pages(target=None, for_pdf=False, bypass_errors=False):
|
||||
else:
|
||||
html_content = ""
|
||||
|
||||
if "sidebar" in currentpage and currentpage["sidebar"] == "toc":
|
||||
sidebar_content = toc_from_headers(html_content)
|
||||
else:
|
||||
sidebar_content = None
|
||||
|
||||
# Prepare some parameters for rendering
|
||||
substitute_parameter_links("doc_page", currentpage, target)
|
||||
current_time = time.strftime("%B %d, %Y")
|
||||
|
||||
# Figure out which template to use
|
||||
if "template" in currentpage and not for_pdf:
|
||||
logging.info("using template %s from page" % currentpage["template"])
|
||||
use_template = env.get_template(currentpage["template"])
|
||||
elif "pdf_template" in currentpage and for_pdf:
|
||||
logging.info("using pdf_template %s from page" % currentpage["pdf_template"])
|
||||
use_template = env.get_template(currentpage["pdf_template"])
|
||||
else:
|
||||
use_template = default_template
|
||||
@@ -422,13 +458,9 @@ def render_pages(target=None, for_pdf=False, bypass_errors=False):
|
||||
pages=pages,
|
||||
content=html_content,
|
||||
target=target,
|
||||
current_time=current_time)
|
||||
current_time=current_time,
|
||||
sidebar_content=sidebar_content)
|
||||
|
||||
# # Experimental: replace links in full HTML, not just content
|
||||
# soup = BeautifulSoup(out_html, "html.parser")
|
||||
# if target["name"] != config["targets"][0]["name"]:
|
||||
# substitute_links_for_target(soup, target)
|
||||
# out_html = str(soup)
|
||||
|
||||
if for_pdf:
|
||||
out_path = config["temporary_files_path"]
|
||||
@@ -447,6 +479,7 @@ def watch(pdf_file, target):
|
||||
"""Look for changed files and re-generate HTML (and optionally
|
||||
PDF whenever there's an update. Runs until interrupted."""
|
||||
target = get_target(target)
|
||||
page_keys_from_target(target)
|
||||
|
||||
class UpdaterHandler(PatternMatchingEventHandler):
|
||||
"""Updates to pattern-matched files means rendering."""
|
||||
@@ -483,6 +516,7 @@ def make_pdf(outfile, target=None, bypass_errors=False):
|
||||
"""Use prince to convert several HTML files into a PDF"""
|
||||
logging.info("rendering PDF-able versions of pages...")
|
||||
target = get_target(target)
|
||||
page_keys_from_target(target)
|
||||
render_pages(target=target, for_pdf=True, bypass_errors=bypass_errors)
|
||||
|
||||
temp_files_path = config["temporary_files_path"]
|
||||
@@ -515,6 +549,7 @@ def githubify(md_file_name, target=None):
|
||||
# with open(filein, "r") as f:
|
||||
# md = f.read()
|
||||
pages = get_pages()
|
||||
page_keys_from_target(target)
|
||||
logging.info("getting markdown for page %s" % md_file_name)
|
||||
md = get_markdown_for_page(md_file_name,
|
||||
pp_env=setup_pp_env(),
|
||||
|
||||
12
tool/template-contentwithtoc.html
Normal file
12
tool/template-contentwithtoc.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<div class='devportal_wrapper'>
|
||||
<aside class='sidebar' role='complementary'>
|
||||
<ul class='dev_nav_sidebar' id='dactyl_toc_sidebar'>
|
||||
{{ sidebar_content }}
|
||||
</ul>
|
||||
</aside>
|
||||
<main class='main' role='main'>
|
||||
<div class='content'>
|
||||
{{ content }}
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
@@ -23,6 +23,7 @@
|
||||
{% if currentpage.sidebar %}
|
||||
<div class="dev_nav_wrapper">
|
||||
<div id="cont">
|
||||
<h5>In this category:</h5>
|
||||
<ul class="dev_nav_sidebar">
|
||||
<li class="level-1"><a href="index.html">Category: {{ currentpage.category }}</a></li>
|
||||
{% for page in pages %}
|
||||
@@ -33,8 +34,10 @@
|
||||
</ul>
|
||||
<hr />
|
||||
<h5>In this page:</h5>
|
||||
<ul class="dev_nav_sidebar" id="dactyl_toc_sidebar">
|
||||
{{ sidebar_content }}
|
||||
</ul>
|
||||
</div>
|
||||
<script type="text/javascript" src="assets/js/jquery.gensidebar.js"></script>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
@@ -44,4 +47,3 @@
|
||||
{{ content }}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user