8000 Allow arbitrary URI in "extra.social.link" · Issue #1623 · squidfunk/mkdocs-material · GitHub
[go: up one dir, main page]

Skip to content

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

@jfcherng

Description

@jfcherng

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 %}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue reports a bug

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0