index.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. {% extends "_common/base.html" %}
  2. {% block css %}
  3. {% load avatar_tags %}
  4. {% load day_util %}
  5. {% load page_tag %}
  6. {% endblock %}
  7. {% block container %}
  8. <div class="ui grid stackable container">
  9. <div class="row" id="article">
  10. <div class="eleven wide column">
  11. <div class="ui feed">
  12. <h2>动态</h2>
  13. <div class="ui divider"></div>
  14. {% for item in articles_new %}
  15. {% if item.status == 1 %}
  16. {% if item.type == 1 and item.is_top%}
  17. <div class="event">
  18. <div class="label">
  19. <img src="/user_avatar/{{ item.user_id }}">
  20. </div>
  21. <div class="content">
  22. <div class="date"
  23. style="font-size: 1.1em">{{ item.created_time | days_until }}</div>
  24. <div class="summary"><a>
  25. {{ item.user__first_name }}{{ item.user__last_name }}</a>
  26. 发布了{{ item.category__name }}:<a
  27. href="/article/{{ item.id }}.html">{{ item.title }}</a>
  28. {% if is_login %}
  29. <a title="取消置顶" href="/article/cancel_show_index/{{ item.id }}"><i class="icon cancel"></i></a>
  30. {% endif %}</div>
  31. <div class="extra text">{{ item.intro }}
  32. &nbsp;&nbsp;&nbsp;Tags:
  33. {% for tag in item.tags %}
  34. <a href="/tag/{{ tag }}?page=1"><span
  35. class="label label-success">{{ tag }}</span></a>
  36. {% endfor %}</div>
  37. </div>
  38. </div>
  39. {% elif item.type == 2 and item.is_top %}
  40. <div class="event">
  41. <div class="label">
  42. <img src="/user_avatar/{{ item.user_id }}">
  43. </div>
  44. <div class="content">
  45. <div class="date"
  46. style="font-size: 1.1em">{{ item.created_time | days_until }}</div>
  47. <div class="summary"><a>
  48. {{ item.user__first_name }}{{ item.user__last_name }}</a>
  49. 发布了{{ item.category__name }}:<a
  50. href="/article/{{ item.id }}.html">{{ item.title }}</a>
  51. {% if is_login %}
  52. <a title="取消置顶" href="/article/cancel_show_index/{{ item.id }}"><i class="icon cancel"></i></a>
  53. {% endif %}</div>
  54. {% if '<iframe' in item.intro %}
  55. {% autoescape off %}
  56. <div class="extra images">
  57. {{ item.intro }}
  58. </div>
  59. {% endautoescape %}
  60. {% else %}
  61. {% autoescape off %}
  62. <div class="extra images">
  63. {{ item.html_text }}
  64. </div>
  65. {% endautoescape %}
  66. {% endif %}
  67. </div>
  68. </div>
  69. {% endif %}
  70. {% endif %}
  71. {% endfor %}
  72. {% if is_login %}
  73. <h3>发布动态</h3>
  74. <div class="ui divider"></div>
  75. <form class="ui reply form">
  76. {% csrf_token %}
  77. <div class="field">
  78. <!-- 编辑器 DOM -->
  79. <input placeholder="文字" name="title" class="ui input">
  80. <div style="border: 1px solid #ccc;margin-top: 5px">
  81. <div id="editor-toolbar" style="border-bottom: 1px solid #ccc;"></div>
  82. <div id="editor-text-area"></div>
  83. </div>
  84. </div>
  85. <div onclick="submit()" style="float: right" class="ui primary submit labeled icon button">
  86. <i class="icon send"></i> 发布
  87. </div>
  88. </form>
  89. {% endif %}
  90. </div>
  91. </div>
  92. <div class="four wide right floated column">
  93. <h4 class="ui header">搜索</h4>
  94. <div id="search" class="ui category search">
  95. <div class="ui icon input">
  96. <input class="prompt" type="text" placeholder="搜索">
  97. <i class="search icon"></i>
  98. </div>
  99. </div>
  100. <h4 class="ui header">归档</h4>
  101. <div class="ui list">
  102. {% for record in records %}
  103. <a class="item" href="/date/{{ record.datetime }}?page=1">{{ record.datetime }}
  104. ({{ record.count }})</a>
  105. {% endfor %}
  106. </div>
  107. <h4 class="ui header">Top</h4>
  108. <div class="ui list">
  109. {% for tag in tags %}
  110. <a class="item" href="/tag/{{ tag.name }}?page=1">{{ tag.name }} ({{ tag.count }})</a>
  111. {% endfor %}
  112. </div>
  113. </div>
  114. </div>
  115. </div>
  116. {% endblock %}
  117. {% block js %}
  118. {% if is_login %}
  119. <script src="https://unpkg.com/@wangeditor/editor@latest/dist/index.js"></script>
  120. <script>
  121. const E = window.wangEditor
  122. // 切换语言
  123. const LANG = location.href.indexOf('lang=en') > 0 ? 'en' : 'zh-CN'
  124. E.i18nChangeLanguage(LANG)
  125. const imageToHtmlConf = {
  126. type: 'image',
  127. elemToHtml: function imageToHtml(elemNode) {
  128. const {src, alt, href = '', style = {}, width, height} = elemNode || {}
  129. return `<a data-pswp-width="${alt.split(',')[0]}" data-pswp-height="${alt.split(',')[1]}" href="${src}"><img data-magnify="gallery" data-src="${src}" src="${src}" data-href="${href}" "/></a>`
  130. }
  131. };
  132. const editorConfig = {
  133. placeholder: 'Type here...',
  134. scroll: false, // 禁止编辑器滚动
  135. MENU_CONF: {
  136. uploadImage: {
  137. server: '/management/files/upload',
  138. // form-data fieldName ,默认值 'wangeditor-uploaded-image'
  139. fieldName: 'file',
  140. // 单个文件的最大体积限制,默认为 2M
  141. maxFileSize: 10 * 1024 * 1024, // 1M
  142. // 最多可上传几个文件,默认为 100
  143. maxNumberOfFiles: 10,
  144. // 选择文件时的类型限制,默认为 ['image/*'] 。如不想限制,则设置为 []
  145. allowedFileTypes: ['image/*'],
  146. // 自定义上传参数,例如传递验证的 token 等。参数会被添加到 formData 中,一起上传到服务端。
  147. meta: {
  148. csrfmiddlewaretoken: $("input[name='csrfmiddlewaretoken']").val()
  149. },
  150. // 将 meta 拼接到 url 参数中,默认 false
  151. metaWithUrl: false,
  152. // 自定义增加 http header
  153. // 跨域是否传递 cookie ,默认为 false
  154. withCredentials: true,
  155. // 超时时间,默认为 10 秒
  156. timeout: 5 * 1000, // 5 秒
  157. }
  158. },
  159. onChange(editor) {
  160. const html = editor.getHtml()
  161. $('#title').val($('#page_title').val())
  162. }
  163. }
  164. E.Boot.registerElemToHtml(imageToHtmlConf);
  165. // 先创建 editor
  166. const editor = E.createEditor({
  167. selector: '#editor-text-area',
  168. content: [],
  169. // html: '',
  170. config: editorConfig
  171. })
  172. // 创建 toolbar
  173. const toolbar = E.createToolbar({
  174. editor,
  175. mode: 'simple',
  176. selector: '#editor-toolbar',
  177. config: {
  178. excludeKeys: ['blockquote', 'header1', 'header2', 'header3', '|', 'bold', 'underline', 'italic', 'through', 'color', 'bgColor', 'clearStyle', '|', 'bulletedList', 'numberedList', 'todo', 'justifyLeft', 'justifyRight', 'justifyCenter', '|', 'insertLink', 'insertVideo', 'insertTable', 'codeBlock', '|', 'undo', 'redo', '|', 'fullScreen']
  179. }
  180. })
  181. </script>
  182. {% endif %}
  183. <script>
  184. function submit() {
  185. let formData = new FormData()
  186. formData.append('title', $("input[name='title']").val())
  187. formData.append('intro', editor.getText())
  188. formData.append('category', 6)
  189. formData.append('html', editor.getHtml())
  190. formData.append('markdown', editor.getText())
  191. formData.append('type', 2)
  192. formData.append('tags', '')
  193. formData.append('status', 1)
  194. formData.append('is_top', 1)
  195. formData.append('csrfmiddlewaretoken', $("input[name='csrfmiddlewaretoken']").val())
  196. $.ajax('/management/article/add_article', {
  197. method: 'post',
  198. data: formData,
  199. contentType: false,
  200. processData: false,
  201. success: function (res) {
  202. window.location.href = '/'
  203. },
  204. error: function (err) {
  205. }
  206. })
  207. }
  208. </script>
  209. {% endblock %}
  210. {% load static %}