category.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. {% extends "_common/base.html" %}
  2. {% block css %}
  3. {% load avatar_tags %}{% load day_util %}
  4. {% load page_tag %}
  5. /* class to hide content visually leaving it available to screenreaders.
  6. See notes in cookbook recipe.
  7. https://github.com/h5bp/html5-boilerplate/issues/1985#issuecomment-394096182
  8. https://medium.com/@matuzo/writing-css-with-accessibility-in-mind-8514a0007939
  9. */
  10. .visuallyhidden {
  11. border: 0;
  12. clip: rect(0 0 0 0);
  13. height: auto;
  14. margin: 0;
  15. overflow: hidden;
  16. padding: 0;
  17. position: absolute;
  18. width: 1px;
  19. white-space: nowrap;
  20. }
  21. nav {
  22. display: flex;
  23. justify-content: right;
  24. border-top: 1px solid #eee;
  25. margin-top: 1em;
  26. padding-top: .5em;
  27. }
  28. /* 容器 & 布局保持不变 */
  29. .pagination {
  30. display: flex;
  31. flex-wrap: wrap;
  32. gap: 0.5rem;
  33. justify-content: center;
  34. padding: 0.75rem 0;
  35. margin: 0;
  36. list-style: none;
  37. }
  38. .pagination li {
  39. list-style: none;
  40. }
  41. /* 普通按钮 */
  42. .pagination a,
  43. .pagination span {
  44. display: inline-flex;
  45. align-items: center;
  46. justify-content: center;
  47. min-width: 2.5em;
  48. height: 2.5em;
  49. padding: 0 0.5em;
  50. border: 1px solid #ddd;
  51. border-radius: 0.4em;
  52. background-color: #fff;
  53. color: var(--text);
  54. font-size: 1rem;
  55. text-decoration: none;
  56. transition:
  57. background-color 0.2s,
  58. color 0.2s,
  59. box-shadow 0.2s,
  60. transform 0.1s;
  61. cursor: pointer;
  62. }
  63. /* 悬停态:浅灰背景,深灰文字 */
  64. .pagination a:hover {
  65. background-color: #f2f2f2;
  66. color: #111;
  67. }
  68. /* 聚焦态:灰黑色光环 */
  69. .pagination a:focus {
  70. outline: none;
  71. box-shadow: 0 0 0 3px rgba(51, 51, 51, 0.3);
  72. }
  73. /* 当前页(Active) */
  74. .pagination li.active a {
  75. background-color: var(--primary);
  76. border-color: var(--primary);
  77. color: #fff;
  78. pointer-events: none;
  79. transform: translateY(-1px);
  80. box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  81. }
  82. /* 禁用态(上一页/下一页边界) */
  83. .pagination li.disabled span {
  84. color: #ccc;
  85. border-color: #eee;
  86. background-color: #fafafa;
  87. cursor: not-allowed;
  88. }
  89. {% endblock %}
  90. {% block container %}
  91. <div class="ui grid stackable container">
  92. <div class="row" id="article">
  93. <div class="eleven wide column">
  94. <div class="ui feed">
  95. <h2>{{ current_category }}</h2>
  96. <nav aria-label="pagination">
  97. <ul class="pagination">
  98. {# 上一页 #}
  99. {% if articles.number > 1 %}
  100. <li>
  101. <a href="?page={{ articles.number|add:"-1" }}" aria-label="上一页">
  102. «
  103. </a>
  104. </li>
  105. {% else %}
  106. <li class="disabled">
  107. <span aria-label="上一页">«</span>
  108. </li>
  109. {% endif %}
  110. {# 中间页码 #}
  111. {% for page in articles.paginator.page_range %}
  112. {% if page == articles.number %}
  113. <li class="active">
  114. <a href="?page={{ page }}" aria-current="page">{{ page }}</a>
  115. </li>
  116. {% else %}
  117. <li>
  118. <a href="?page={{ page }}">{{ page }}</a>
  119. </li>
  120. {% endif %}
  121. {% endfor %}
  122. {# 下一页 #}
  123. {% if articles.number < articles.paginator.num_pages %}
  124. <li>
  125. <a href="?page={{ articles.number|add:"1" }}" aria-label="下一页">
  126. »
  127. </a>
  128. </li>
  129. {% else %}
  130. <li class="disabled">
  131. <span aria-label="下一页">»</span>
  132. </li>
  133. {% endif %}
  134. </ul>
  135. </nav>
  136. {% for item in articles %}
  137. {% if item.status == 1 %}
  138. {% if item.type == 1 %}
  139. <div class="event">
  140. <div class="label">
  141. <img src="/user_avatar/{{ item.user_id }}">
  142. </div>
  143. <div class="content">
  144. <div class="date"
  145. style="font-size: 1.1em">{{ item.created_time | days_until }}</div>
  146. <div class="summary"><a>
  147. {{ item.user__first_name }}{{ item.user__last_name }}</a>
  148. 发布了{{ item.category__name }}:<a
  149. href="/article/{{ item.id }}.html">{{ item.title }}</a>
  150. {% if is_login %}
  151. <a title="置顶" href="/article/show_show_index/{{ item.id }}"><i
  152. class="icon home"></i></a>
  153. {% endif %}</div>
  154. <div class="extra text">{{ item.intro }}
  155. &nbsp;&nbsp;&nbsp;Tags:
  156. {% for tag in item.tags %}
  157. <a href="/tag/{{ tag }}?page=1"><span
  158. class="label label-success">{{ tag }}</span></a>
  159. {% endfor %}</div>
  160. </div>
  161. </div>
  162. {% elif item.type == 2 %}
  163. <div class="event">
  164. <div class="label">
  165. <img src="/user_avatar/{{ item.user_id }}">
  166. </div>
  167. <div class="content">
  168. <div class="date"
  169. style="font-size: 1.1em">{{ item.created_time | days_until }}</div>
  170. <div class="summary"><a>
  171. {{ item.user__first_name }}{{ item.user__last_name }}</a>
  172. 发布了{{ item.category__name }}:<a
  173. href="/article/{{ item.id }}.html">{{ item.title }}</a>
  174. {% if is_login %}
  175. <a title="置顶" href="/article/show_show_index/{{ item.id }}"><i
  176. class="icon home"></i></a>
  177. {% endif %}</div>
  178. {% autoescape off %}
  179. <div class="extra images">
  180. {{ item.html_text }}
  181. </div>
  182. {% endautoescape %}
  183. </div>
  184. </div>
  185. {% endif %}
  186. {% endif %}
  187. {% endfor %}
  188. </div>
  189. </div>
  190. <div class="four wide right floated column">
  191. <h4 class="ui header">搜索</h4>
  192. <div id="search" class="ui category search">
  193. <div class="ui icon input">
  194. <input class="prompt" type="text" placeholder="搜索">
  195. <i class="search icon"></i>
  196. </div>
  197. </div>
  198. <h4 class="ui header">归档</h4>
  199. <div class="ui list">
  200. {% for record in records %}
  201. <a class="item" href="/date/{{ record.datetime }}?page=1">{{ record.datetime }}
  202. ({{ record.count }})</a>
  203. {% endfor %}
  204. </div>
  205. <h4 class="ui header">Top</h4>
  206. <div class="ui list">
  207. {% for tag in tags %}
  208. <a class="item" href="/tag/{{ tag.name }}?page=1">{{ tag.name }} ({{ tag.count }})</a>
  209. {% endfor %}
  210. </div>
  211. </div>
  212. </div>
  213. </div>
  214. {% endblock %}
  215. {% block js %}
  216. <script>
  217. function submit() {
  218. let formData = new FormData()
  219. formData.append('title', $("input[name='title']").val())
  220. formData.append('intro', editor.getText())
  221. formData.append('category', 6)
  222. formData.append('html', editor.getHtml())
  223. formData.append('markdown', editor.getText())
  224. formData.append('type', 2)
  225. formData.append('tags', '')
  226. formData.append('status', 1)
  227. formData.append('is_top', 1)
  228. formData.append('csrfmiddlewaretoken', $("input[name='csrfmiddlewaretoken']").val())
  229. $.ajax('/management/article/add_article', {
  230. method: 'post',
  231. data: formData,
  232. contentType: false,
  233. processData: false,
  234. success: function (res) {
  235. window.location.href = '/'
  236. },
  237. error: function (err) {
  238. }
  239. })
  240. }
  241. </script>
  242. {% endblock %}
  243. {% load static %}