index.twig 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. {% spaceless %}
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <meta charset="utf-8" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
  7. <title>
  8. {% if meta.title %}
  9. {{ meta.title }} |
  10. {% endif %}
  11. {{ site_title }}
  12. </title>
  13. {% include 'includes/custom_header.twig' ignore missing %}
  14. {% if meta.description %}
  15. <meta name="description" content="{{ meta.description }}"/>
  16. {# i don't understand what og:... is good for. i hope i'm doing this right. #}
  17. <meta property="og:description" content="{{ meta.description }}"/>
  18. {% endif %}
  19. {% if meta.robots %}
  20. <meta name="robots" content="{{ meta.robots }}">
  21. {% endif %}
  22. {# i don't understand what og:... is good for. i hope i'm doing this right. #}
  23. <meta property="og:type" content="{{current_page.meta.template}}"/>
  24. <meta property="og:title"
  25. content="{{ current_page.title }} | {{ site_title }}"/>
  26. <meta property="og:url" content="{{ current_page.url }}"/>
  27. <meta property="og:site_name" content="{{ site_title }}"/>
  28. {% if current_page %}
  29. <link rel="canonical" href="{{ current_page.url }}" />
  30. {% endif %}
  31. <link rel="stylesheet" href="{{ theme_url }}/css/style.css" type="text/css" />
  32. <link rel="stylesheet" href="{{ theme_url }}/css/colors-{{ config.tagblog.colors }}.css" type="text/css" />
  33. {% if meta.template == 404 %}<link rel="stylesheet" href="{{ theme_url }}/css/404.css" type="text/css" />{% endif %}
  34. {% if meta.template == config.TableOfContent.template or not config.TableOfContent.template %}<link rel="stylesheet" href="{{ theme_url }}/css/TableOfContent.css" type="text/css" />{% endif %}
  35. </head>
  36. <body>
  37. <header>
  38. <div class="inner flexbox">
  39. {% include 'includes/topmenu.twig' ignore missing %}
  40. <a href="{{ "index"|link }}"><img src="{{ config.tagblog.site_logo }}" alt="{{- site_title -}}"></a>
  41. <div class="title">
  42. <a href="{{ "index"|link }}">{{ site_title }}</a>
  43. </div>
  44. </div>
  45. </header>
  46. <div class="inner">
  47. <section id="sidebar">
  48. {# looping over all pages to pick out what we need (i.e. pages with tags) #}
  49. {% set tag_count = {} %} {# tag_count contains: tag : count of occurences #}
  50. {% set tag_pages = {} %} {# tag_pages contains: tag : page ids of occurences hash '#' separated #}
  51. {% set tbpages = {} %} {# contains ALL pages to be considered, saves some cycles later on #}
  52. {% for page in pages if page.meta.tags %}
  53. {% set tbpages = tbpages|merge([page]) %}
  54. {% for tag in page.meta.tags|split(',') %}
  55. {# tag_count contains: tag : count of occurences #}
  56. {% set tag_count = tag_count|merge({(tag):(tag_count[tag] + 1)}) %}
  57. {# tag_pages contains: tag : page ids of occurences hash '#' separated #}
  58. {% set tag_pages = tag_pages|merge( { (tag) : (tag_pages[tag] ~ '#' ~ page.id) } ) %}
  59. {% endfor %}
  60. {% endfor %}
  61. {# sort tag_count into tag_sorting, according to config options #}
  62. {% set tag_sorting = {} %}
  63. {% if config.tagblog.tagsort.method == 'numerical' %}
  64. {% set tag_sorting = tag_count|sort %}
  65. {% elseif config.tagblog.tagsort.method == 'alphabetical' %}
  66. {% for tag in tag_count|keys|sort %}
  67. {% set tag_sorting = tag_sorting|merge({(tag): tag_count[tag] }) %}
  68. {% endfor %}
  69. {% endif %}
  70. {# ... and sort it back into tag_count array #}
  71. {% if config.tagblog.tagsort.reverse %}
  72. {% set tag_count = tag_sorting|reverse %}
  73. {% else %}
  74. {% set tag_count = tag_sorting %}
  75. {% endif %}
  76. <input id="menu-icon" type="checkbox"/>
  77. <label for="menu-icon">≡<span> menu</span></label>
  78. <nav id="menu-icon"> {# this nav's visibility is controled by the checkbox above! #}
  79. {% include 'includes/sidebar-top.twig' ignore missing %}
  80. {# Tag List #}
  81. {% if config.tagblog.taglist.enabled and tag_count %}
  82. <div class="tag_list">
  83. {% if config.tagblog.taglist.title %}<h2>{{ config.tagblog.taglist.title }}</h2>{% endif %}
  84. <ul>
  85. {% for tag,total in tag_count %}
  86. <li>
  87. <a href="/tags?q={{tag}}">{{ tag }}{% if config.tagblog.tagcount.enabled %}<span> ({{ total }})</span>{% endif %}</a>
  88. </li>
  89. {% endfor %}
  90. </ul>
  91. </div>
  92. {% endif %}
  93. {# Tag Cloud #}
  94. {% if config.tagblog.tagcloud.enabled and tag_count %}
  95. {# Levels Validation #}
  96. {% if max(tag_count) < config.tagblog.tagcloud.maxoccur %}
  97. {% set tagmaxoccur = max(tag_count) %}
  98. {% else %}
  99. {% set tagmaxoccur = config.tagblog.tagcloud.maxoccur %}
  100. {% endif %}
  101. {# Render Tag Cloud #}
  102. <div class="tag_cloud">
  103. {% if config.tagblog.tagcloud.title %}<div>{{ config.tagblog.tagcloud.title }}</div>{% endif %}
  104. <ul>
  105. {% for tag,total in tag_count %}
  106. {% if total > tagmaxoccur %}{% set size = tagmaxoccur %}{% else %}{% set size = total %}
  107. {% endif %}
  108. {% if size == 1 %}{% set fontsize = config.tagblog.tagcloud.fontsizemin %}
  109. {% else %}
  110. {# calculate tag font size - https://stackoverflow.com/a/3717340 #}
  111. {% set fontsize = ( (size / tagmaxoccur) * ( config.tagblog.tagcloud.fontsizemax - config.tagblog.tagcloud.fontsizemin ) + config.tagblog.tagcloud.fontsizemin ) %}
  112. {% endif %}
  113. <li style="font-size:{{ fontsize }}rem;">
  114. <a href="/tags?q={{tag}}">{{ tag }}{% if config.tagblog.tagcount.enabled %}<span>{{ total }}</span>{% endif %}</a></li>
  115. {% endfor %}
  116. </ul>
  117. </div>
  118. {% endif %}
  119. <hr />
  120. <div class="clearfix">
  121. {% if config.tagblog.search.enabled %}
  122. {# searches go to the /search.md page #}
  123. <form class="search paragraph" id="search_form" action="/search">
  124. {# <label for="search_input">Search» </label> #}
  125. <span><input title='The search function is primitive. It only searches for the literal string as entered.
  126. » fluffy cloud
  127. will search only the exact string
  128. » "fluffy cloud".
  129. Searches are case insensitive. Tags and some special characters are stripped.' class="submit" type="submit" value="Search" /></span>
  130. <span><input pattern=".{0{{config.tagblog.search.minlength}},}" required title="{{config.tagblog.search.minlength}} characters minimum" size="15" type="text" id="search_input" name="q" /></span>
  131. </form>
  132. {% endif %}
  133. {% if config.tagblog.feed.enabled %}
  134. <div class="rss paragraph"><a href="/feed">RSS Feed</a></div>
  135. {% endif %}
  136. {% include 'includes/sidebar-bottom.twig' ignore missing %}
  137. </div>
  138. </nav>
  139. </section>
  140. <section id="content">
  141. {% endspaceless %}
  142. {% block content %}
  143. {% set length = tbpages|length %}
  144. <article><h3>All Articles ({{length}})</h3></article>
  145. {% if config.tagblog.paging > 0 and length > config.tagblog.paging %}
  146. {# Paginate over all pages with tags #}
  147. {% set p = url_param('p','int',1) %}
  148. {% set offset = (p - 1) * config.tagblog.paging %}
  149. {% set lastpage = length//config.tagblog.paging %}
  150. {% if length%config.tagblog.paging > 0 %}{% set lastpage = lastpage + 1 %}{% endif %}
  151. {% for page in tbpages|slice(offset,config.tagblog.paging) %}
  152. {% include 'includes/postlistitem.twig' %}
  153. {% endfor %}
  154. <div class="pagination clearfix">
  155. {% if offset >= config.tagblog.paging %}
  156. <div class="previous"><a href="{{current_page.url}}?p={{ p - 1 }}">&lt;Previous Page</a></div>
  157. {% endif %}
  158. {# {% if offset >= config.tagblog.paging and offset + config.tagblog.paging < length %} | {% endif %} #}
  159. <div class="current">- {{ p }}/{{ lastpage }} -</div>
  160. {% if offset + config.tagblog.paging < length %}
  161. <div class="next"><a href="{{current_page.url}}?p={{ p + 1 }}">Next Page&gt;</a></div>
  162. {% endif %}
  163. </div>
  164. {% else %}
  165. {# just list all pages #}
  166. {% for page in tbpages %}
  167. {% include 'includes/postlistitem.twig' %}
  168. {% endfor %}
  169. {% endif %}
  170. {% endblock %}
  171. {% spaceless %}
  172. </section>
  173. </div>
  174. <footer>
  175. {% include 'includes/footer.twig' ignore missing %}
  176. </footer>
  177. </body>
  178. </html>
  179. {% endspaceless %}