Browse Source

Make post component

master
Dylan Baker 3 years ago
parent
commit
a42ba8ae66
4 changed files with 23 additions and 31 deletions
  1. 19
    0
      templates/components.html
  2. 2
    18
      templates/index.html
  3. 1
    0
      templates/layout.html
  4. 1
    13
      templates/single.html

+ 19
- 0
templates/components.html View File

@@ -0,0 +1,19 @@
1
+{% macro post(post, type) %}
2
+<div class="post">
3
+  <h3 class="post__heading">
4
+    <div class="post__links">
5
+      {% if type == "index" %}
6
+      <a class="post__link" href="/posts/{{ post.id }}">view</a>
7
+      {% endif %} {% if logged_in %}
8
+      <a class="post__link" href="/posts/{{ post.id }}/edit">edit</a>
9
+      {% endif %}
10
+    </div>
11
+    <span class="post__title">
12
+      {{ post.title }} :: {{ post.date }}
13
+    </span>
14
+  </h3>
15
+  <div class="post__body">
16
+    {{ post.body | safe }}
17
+  </div>
18
+</div>
19
+{% endmacro %}

+ 2
- 18
templates/index.html View File

@@ -18,23 +18,7 @@
18 18
 {% endif %}
19 19
 
20 20
 <div class="posts">
21
-  {% for post in posts %}
22
-  <div class="posts__post post">
23
-    <h3 class="post__heading">
24
-      <div class="post__links">
25
-        <a class="post__link" href="/posts/{{ post.id }}">view</a>
26
-        {% if logged_in %}
27
-        <a class="post__link" href="/posts/{{ post.id }}/edit">edit</a>
28
-        {% endif %}
29
-      </div>
30
-      <span class="post__title">
31
-        {{ post.title }} :: {{ post.date }}
32
-      </span>
33
-    </h3>
34
-    <div class="post__body">
35
-      {{ post.body | safe }}
36
-    </div>
37
-  </div>
38
-  {% endfor %}
21
+  {% for post in posts %} {{ components::post(post=post, type="index") }} {%
22
+  endfor %}
39 23
 </div>
40 24
 {% endblock %}

+ 1
- 0
templates/layout.html View File

@@ -1,3 +1,4 @@
1
+{% import "components.html" as components %}
1 2
 <!DOCTYPE html>
2 3
 <html lang="en">
3 4
   <head>

+ 1
- 13
templates/single.html View File

@@ -1,17 +1,5 @@
1 1
 {% extends "layout.html" %} {% block content %}
2 2
 <div class="posts">
3
-  <div class="posts__post post">
4
-    <h3 class="post__heading">
5
-      {% if logged_in %}
6
-      <a class="post__link" href="/posts/{{ post.id }}/edit">edit</a>
7
-      {% endif %}
8
-      <span class="post__title">
9
-        {{ post.title }} :: {{ post.date }}
10
-      </span>
11
-    </h3>
12
-    <div class="post__body">
13
-      {{ post.body | safe }}
14
-    </div>
15
-  </div>
3
+  {{ components::post(post=post, type="single") }}
16 4
 </div>
17 5
 {% endblock %}

Loading…
Cancel
Save