main.py 1.1 KB

12345678910111213141516171819202122232425
  1. from typing import Union
  2. import urllib.parse
  3. def define_env(env):
  4. @env.macro
  5. def pageinfo(authors: Union[str, list[str]] = None, created: str = None, updated: str = None):
  6. parts = []
  7. if authors is not None:
  8. parts.append(", ".join(authors if isinstance(authors, list) else [ authors ]))
  9. if created is not None:
  10. parts.append("Created " + created)
  11. if updated is not None:
  12. parts.append("Updated " + updated)
  13. return "<br><small>" + " |&nbsp;".join(parts) + "</small>"
  14. @env.macro
  15. def release(artist: str, album: str):
  16. query = f"{artist} - {album}"
  17. return f"{query} " + \
  18. f'<a class="release-link" rel="noopener noreferrer" href="https://odesli.co/?q={urllib.parse.quote(query)}"><img src="/assets/img/icons/odesli.png" alt="Odesli"></a></a>' + \
  19. f'<a class="release-link" rel="noopener noreferrer" href="https://youtube.com/results?q={urllib.parse.quote(query)}"><img src="/assets/img/icons/youtube.png" alt="YouTube"></a></a>' + \
  20. f'<a class="release-link" rel="noopener noreferrer" href="https://google.com/search?q={urllib.parse.quote(query)}"><img src="/assets/img/icons/google.png" alt="Google"></a>'