From b22c1c406beacf07702046b239da0798e8713ebd Mon Sep 17 00:00:00 2001 From: mDuo13 Date: Fri, 25 Mar 2016 18:05:36 -0700 Subject: [PATCH] Dactyl - solution for different image paths by target --- tool/dactyl-config.yml | 18 ++++++++++-------- tool/dactyl_build.py | 21 ++++++++++++++++++++- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/tool/dactyl-config.yml b/tool/dactyl-config.yml index 3fdca6f33b..61aa76a492 100644 --- a/tool/dactyl-config.yml +++ b/tool/dactyl-config.yml @@ -29,15 +29,20 @@ targets: - multicode_tabs - standardize_header_ids - buttonize + - name: ripple.com filters: - multicode_tabs - standardize_header_ids - buttonize - - - name: printable - filters: - - standardize_header_ids + 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 + "img/e2g-02.png": https://ripple.com/wp-content/themes/ripple-beta/assets/img/e2g-02.png + "img/e2g-03.png": https://ripple.com/wp-content/themes/ripple-beta/assets/img/e2g-03.png + "img/ledger-process.png": https://ripple.com/wp-content/themes/ripple-beta/assets/img/ledger-process.png + "img/ledger-components.png": https://ripple.com/wp-content/themes/ripple-beta/assets/img/ledger-components.png + "img/ledger-indexes.png": https://ripple.com/wp-content/themes/ripple-beta/assets/img/ledger-indexes.png - name: rippled-setup filters: @@ -216,8 +221,7 @@ pages: category: Best Practices html: concept-issuing-and-operational-addresses.html md: concept-issuing-and-operational-addresses.md - # TODO publish this article separately on the website - ripple.com: https://ripple.com/build/gateway-guide/#hot-and-cold-wallets + ripple.com: https://ripple.com/knowledge_center/issuing-operational-addresses/ sidebar: true targets: - local @@ -283,8 +287,6 @@ ignore_anchors_in: known_broken_links: # Strangely, Python doesn't like the cert here. Firefox is OK with it. - https://validators.ripple.com - # Zendesk hasn't updated the cert. See ticket IN-1168 - - https://support.ripplelabs.com/hc/en-us/categories/200194196-Set-Up-Activation # Style Checker Config ------------------------------------------------------ # diff --git a/tool/dactyl_build.py b/tool/dactyl_build.py index 41afeefe93..983bd34d47 100755 --- a/tool/dactyl_build.py +++ b/tool/dactyl_build.py @@ -73,7 +73,7 @@ def load_config(config_file=DEFAULT_CONFIG_FILE): def substitute_links_for_target(soup, target): """Replaces local-html-links with appropriate substitutions - for the given target""" + for the given target, and images likewise""" target = get_target(target) logger.info("... modifying links for target: %s" % target["name"]) @@ -92,6 +92,25 @@ def substitute_links_for_target(soup, target): link["href"] = link["href"].replace(local_url, target_url) + + if "image_subs" in target: + images = soup.find_all("img") + for img in images: + local_path = img["src"] + if local_path in target["image_subs"]: + logger.info("... replacing image path '%s' with '%s'" % + (local_path, target["image_subs"][local_path])) + img["src"] = target["image_subs"][local_path] + + image_links = soup.find_all("a", + href=re.compile(r"^[^.]+\.(png|jpg|jpeg|gif|svg)")) + for img_link in image_links: + local_path = img_link["href"] + if local_path in target["image_subs"]: + logger.info("... replacing image link '%s' with '%s'" % + (local_path, target["image_subs"][local_path])) + img_link["href"] = target["image_subs"][local_path] + def get_target(target): """Get a target by name, or return the default target object. We can't use default args in function defs because the default is