Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow arbitrary URI in "extra.social.link" #1623

Closed
jfcherng opened this issue Apr 17, 2020 · 5 comments
Closed

Allow arbitrary URI in "extra.social.link" #1623

jfcherng opened this issue Apr 17, 2020 · 5 comments
Labels
bug Issue reports a bug

Comments

@jfcherng
Copy link
Contributor

jfcherng commented Apr 17, 2020

Description

Currently, having // in extra.social.link is mandatory because of

{% set _,rest = social.link.split("//") %}

Click to show the current error message
INFO    -  Building documentation...
INFO    -  Cleaning site directory
Traceback (most recent call last):
  File "c:\program files\python38\lib\runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\program files\python38\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Program Files\Python38\Scripts\mkdocs.exe\__main__.py", line 7, in <module>
  File "c:\program files\python38\lib\site-packages\click\core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "c:\program files\python38\lib\site-packages\click\core.py", line 717, in main
    rv = self.invoke(ctx)
  File "c:\program files\python38\lib\site-packages\click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\program files\python38\lib\site-packages\click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\program files\python38\lib\site-packages\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "c:\program files\python38\lib\site-packages\mkdocs\__main__.py", line 140, in serve_command
    serve.serve(
  File "c:\program files\python38\lib\site-packages\mkdocs\commands\serve.py", line 141, in serve
    config = builder()
  File "c:\program files\python38\lib\site-packages\mkdocs\commands\serve.py", line 136, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "c:\program files\python38\lib\site-packages\mkdocs\commands\build.py", line 288, in build
    _build_theme_template(template, env, files, config, nav)
  File "c:\program files\python38\lib\site-packages\mkdocs\commands\build.py", line 114, in _build_theme_template
    output = _build_template(template_name, template, files, config, nav)
  File "c:\program files\python38\lib\site-packages\mkdocs\commands\build.py", line 93, in _build_template
    output = template.render(context)
  File "c:\program files\python38\lib\site-packages\jinja2\asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "c:\program files\python38\lib\site-packages\jinja2\environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "c:\program files\python38\lib\site-packages\jinja2\environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "c:\program files\python38\lib\site-packages\jinja2\_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "E:\WWW\FanHuaJi_Docs\theme\404.html", line 1, in <module>
    {% extends "base.html" %}
  File "c:\program files\python38\lib\site-packages\jinja2\environment.py", line 1005, in render
    return concat(self.root_render_func(self.new_context(vars)))
  File "E:\WWW\FanHuaJi_Docs\theme\404.html", line 14, in root
  File "c:\program files\python38\lib\site-packages\material\base.html", line 116, in root
    {% endblock %}
  File "c:\program files\python38\lib\site-packages\material\base.html", line 425, in block_footer
  File "E:\WWW\FanHuaJi_Docs\theme\partials\footer.html", line 65, in root
    <!-- Copyright and theme information -->
  File "c:\program files\python38\lib\site-packages\material\partials\social.html", line 18, in root
ValueError: not enough values to unpack (expected 2, got 1)

Use Cases

I would like to use mailto:me@example.com with image. I.e.,

extra:
  social:
    - icon: fontawesome/solid/envelope
      link: mailto:me@example.com

Screenshots / Mockups

image

This is what I am currently using as an example.

    {% for social in config.extra.social %}
      {% set domain = "" %}
      {% if "//" in social.link %}
        {% set scheme,rest = social.link.split("//") %}
        {% if "" == scheme or "http" in scheme %}
          {% set domain = rest.split("/")[0] %}
        {% endif %}
      {% endif %}
      <a
        href="{{ social.link }}"
        target="_blank" rel="noopener"
        title="{{ domain }}"
        class="md-footer-social__link"
      >
        {% include ".icons/" ~ social.icon ~ ".svg" %}
      </a>
    {% endfor %}
@jfcherng jfcherng changed the title Allow arbitrary URI in "socials" Allow arbitrary URI in "social.link" Apr 17, 2020
@squidfunk squidfunk added the bug Issue reports a bug label Apr 18, 2020
@XhmikosR
Copy link
Contributor

@squidfunk that's why I suggested a text option which could simplify and improve things here if present.

@squidfunk
Copy link
Owner

squidfunk commented Apr 18, 2020

It wouldn't solve the issue, as even with an option we would have to supply reasonable defaults.

@jfcherng jfcherng changed the title Allow arbitrary URI in "social.link" Allow arbitrary URI in "extra.social.link" Apr 18, 2020
@squidfunk
Copy link
Owner

db7c28b adds a name attribute to each social link. Furthermore, the domain is now only set when // is a substring of the URL, as you suggested.

@squidfunk squidfunk added the resolved Issue is resolved, yet unreleased if open label May 3, 2020
@squidfunk
Copy link
Owner

Released as part of 5.1.5.

@squidfunk squidfunk removed the resolved Issue is resolved, yet unreleased if open label May 3, 2020
@jfcherng
Copy link
Contributor Author

jfcherng commented May 3, 2020

Working great now. Thanks 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug
Projects
None yet
Development

No branches or pull requests

3 participants