common_elements.html 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. {% macro text_runs(runs) %}
  2. {%- if runs[0] is mapping -%}
  3. {%- for text_run in runs -%}
  4. {%- if text_run.get("bold", false) -%}
  5. <b>{{ text_run["text"] }}</b>
  6. {%- elif text_run.get('italics', false) -%}
  7. <i>{{ text_run["text"] }}</i>
  8. {%- else -%}
  9. {{ text_run["text"] }}
  10. {%- endif -%}
  11. {%- endfor -%}
  12. {%- elif runs -%}
  13. {{ runs }}
  14. {%- endif -%}
  15. {% endmacro %}
  16. {% macro item(info, description=false, horizontal=true, include_author=true, include_badges=true, lazy_load=false) %}
  17. <article class="item-box">
  18. {% if info['error'] %}
  19. {{ info['error'] }}
  20. {% else %}
  21. <div class="item-video {{ info['type'] + '-item' }}">
  22. <a class="thumbnail-box" href="{{ info['url'] }}" title="{{ info['title'] }}">
  23. <div class="thumbnail {% if info['type'] == 'channel' %} channel {% endif %}">
  24. {% if lazy_load %}
  25. <img class="thumbnail-img lazy" alt="&#x20;" data-src="{{ info['thumbnail'] }}">
  26. {% elif info['type'] == 'channel' %}
  27. <img class="thumbnail-img channel" alt="&#x20;" src="{{ info['thumbnail'] }}">
  28. {% else %}
  29. <img class="thumbnail-img" alt="&#x20;" src="{{ info['thumbnail'] }}">
  30. {% endif %}
  31. {% if info['type'] != 'channel' %}
  32. <p class="length">{{ (info['video_count']|commatize + ' videos') if info['type'] == 'playlist' else info['duration'] }}</p>
  33. {% endif %}
  34. </div>
  35. </a>
  36. <h4 class="title"><a href="{{ info['url'] }}" title="{{ info['title'] }}">{{ info['title'] }}</a></h4>
  37. {% if include_author %}
  38. {% set author_description = info['author'] %}
  39. {% set AUTHOR_DESC_LENGTH = 35 %}
  40. {% if author_description != None %}
  41. {% if author_description|length >= AUTHOR_DESC_LENGTH %}
  42. {% set author_description = author_description[:AUTHOR_DESC_LENGTH].split(' ')[:-1]|join(' ') %}
  43. {% if not author_description[-1] in ['.', '?', ':', '!'] %}
  44. {% set author_more = author_description + '…' %}
  45. {% set author_description = author_more|replace('"','') %}
  46. {% endif %}
  47. {% endif %}
  48. {% endif %}
  49. {% if info.get('author_url') %}
  50. <address title="{{ info['author'] }}"><b><a href="{{ info['author_url'] }}">{{ author_description }}</a></b></address>
  51. {% else %}
  52. <address title="{{ info['author'] }}"><b>{{ author_description }}</b></address>
  53. {% endif %}
  54. {% endif %}
  55. <div class="stats {{'horizontal-stats' if horizontal else 'vertical-stats'}}">
  56. {% if info['type'] == 'channel' %}
  57. <div>{{ info['approx_subscriber_count'] }} subscribers</div>
  58. <div>{{ info['video_count']|commatize }} videos</div>
  59. {% else %}
  60. {% if info.get('time_published') %}
  61. <span>{{ info['time_published'] }}</span>
  62. {% endif %}
  63. {% if info.get('approx_view_count') %}
  64. <div class="views">{{ info['approx_view_count'] }} views</div>
  65. {% endif %}
  66. {% endif %}
  67. </div>
  68. </div>
  69. {% if info['type'] == 'video' %}
  70. <input class="item-checkbox" type="checkbox" name="video_info_list" value="{{ info['video_info'] }}" form="playlist-edit">
  71. {% endif %}
  72. {% endif %}
  73. </article>
  74. {% endmacro %}
  75. {% macro page_buttons(estimated_pages, url, parameters_dictionary, include_ends=false) %}
  76. {% set current_page = parameters_dictionary.get('page', 1)|int %}
  77. {% set parameters_dictionary = parameters_dictionary.to_dict() %}
  78. {% if current_page is le(5) %}
  79. {% set page_start = 1 %}
  80. {% set page_end = [9, estimated_pages]|min %}
  81. {% else %}
  82. {% set page_start = current_page - 4 %}
  83. {% set page_end = [current_page + 4, estimated_pages]|min %}
  84. {% endif %}
  85. {% if include_ends and page_start is gt(1) %}
  86. {% set _ = parameters_dictionary.__setitem__('page', 1) %}
  87. <a class="page-link first-page-button" href="{{ url + '?' + parameters_dictionary|urlencode }}">{{ 1 }}</a>
  88. {% endif %}
  89. {% for page in range(page_start, page_end+1) %}
  90. {% if page == current_page %}
  91. <a class="page-link is-current">{{ page }}</a>
  92. {% else %}
  93. {# https://stackoverflow.com/questions/36886650/how-to-add-a-new-entry-into-a-dictionary-object-while-using-jinja2 #}
  94. {% set _ = parameters_dictionary.__setitem__('page', page) %}
  95. <a class="page-link" href="{{ url + '?' + parameters_dictionary|urlencode }}">{{ page }}</a>
  96. {% endif %}
  97. {% endfor %}
  98. {% if include_ends and page_end is lt(estimated_pages) %}
  99. {% set _ = parameters_dictionary.__setitem__('page', estimated_pages) %}
  100. <a class="page-link last-page-button" href="{{ url + '?' + parameters_dictionary|urlencode }}">{{ estimated_pages }}</a>
  101. {% endif %}
  102. {% endmacro %}
  103. {% macro next_previous_buttons(is_last_page, url, parameters_dictionary) %}
  104. {% set current_page = parameters_dictionary.get('page', 1)|int %}
  105. {% set parameters_dictionary = parameters_dictionary.to_dict() %}
  106. {% if current_page != 1 %}
  107. {% set _ = parameters_dictionary.__setitem__('page', current_page - 1) %}
  108. <a class="page-link previous-page" href="{{ url + '?' + parameters_dictionary|urlencode }}">Previous page</a>
  109. {% endif %}
  110. {% if not is_last_page %}
  111. {% set _ = parameters_dictionary.__setitem__('page', current_page + 1) %}
  112. <a class="page-link next-page" href="{{ url + '?' + parameters_dictionary|urlencode }}">Next page</a>
  113. {% endif %}
  114. {% endmacro %}
  115. {% macro next_previous_ctoken_buttons(prev_ctoken, next_ctoken, url, parameters_dictionary) %}
  116. {% set parameters_dictionary = parameters_dictionary.to_dict() %}
  117. {% if prev_ctoken %}
  118. {% set _ = parameters_dictionary.__setitem__('ctoken', prev_ctoken) %}
  119. <a class="page-link previous-page" href="{{ url + '?' + parameters_dictionary|urlencode }}">Previous page</a>
  120. {% endif %}
  121. {% if next_ctoken %}
  122. {% set _ = parameters_dictionary.__setitem__('ctoken', next_ctoken) %}
  123. <a class="page-link next-page" href="{{ url + '?' + parameters_dictionary|urlencode }}">Next page</a>
  124. {% endif %}
  125. {% endmacro %}