Skip to content

Commit 64de952

Browse files
committed
fix header issues
1 parent 28be8b3 commit 64de952

File tree

10 files changed

+119
-69
lines changed

10 files changed

+119
-69
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
11
const comment_container = document.getElementById("bloggit-comment-container")
2-
comment_container.classList += "container mt4"
2+
33
if (comment_container){
4-
comment_container.innerHTML = `<h2>Comments</h2>`
5-
if(data["comments"] != [] || data["comments"]){
6-
data["comments"].forEach(function(parameter){
7-
let name = parameter.name
8-
let comment = parameter.comment
9-
let time = convert_datetime(parameter.time)
4+
comment_container.classList += "container mt4"
105

11-
comment_container.innerHTML += `
12-
<!-- Comments Display -->
13-
<div id="comments" class="mt-4">
14-
<!-- Comments will be displayed here -->
15-
<div class="card mb-3">
16-
<div class="card-body">
17-
<h3 class="card-title">${name}</h3>
18-
<time>${time}</time>
19-
<article class="card-text">${comment}</article>
20-
</div>
21-
</div>
22-
</div>
6+
if (comment_container){
7+
comment_container.innerHTML = `<h2>Comments</h2>
8+
<div id="comments" class="mt-4">
239
24-
`
25-
})
10+
</div>
11+
`
12+
const c_cont_inner = document.querySelector("#bloggit-comment-container #comments")
13+
if(data["comments"] != [] || data["comments"]){
14+
data["comments"].forEach(function(parameter){
15+
let name = parameter.name
16+
let comment = parameter.comment
17+
let time = convert_datetime(parameter.time)
18+
19+
c_cont_inner.innerHTML += `
20+
<!-- Comments Display -->
21+
22+
<!-- Comments will be displayed here -->
23+
<div class="card mb-3">
24+
<div class="card-body">
25+
<h3 class="card-title">${name}</h3>
26+
<time>${time}</time>
27+
<article class="card-text">${comment}</article>
28+
</div>
29+
</div>
30+
31+
`
32+
})
33+
}
2634
}
35+
}else{
36+
console.log('Comment Container not defined')
2737
}
38+
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
1-
document.getElementById("bloggit-comment-rf").innerHTML = `
2-
<div class="container mt-5">
3-
<h1>Leave a Comment</h1>
4-
<form>
5-
<div class="form-group">
6-
<label for="comment-name">Name:* (required)</label>
7-
<input type="text" class="form-control" id="comment-name" placeholder="Enter your name" required>
8-
</div>
9-
<div class="form-group">
10-
<label for="comment-email">Email: (not compulsory, and this won't be published)</label>
11-
<input type="email" class="form-control" id="comment-email" placeholder="Enter your email">
12-
</div>
13-
<div class="form-group">
14-
<label for="comment-comment">Comment:* (required)</label>
15-
<textarea class="form-control" id="comment-comment" rows="4" placeholder="Enter your comment" required></textarea>
16-
</div>
17-
<p id="comment-status"></p>
18-
<button type="submit" class="btn btn-primary" id="bloggit-submit-comment">Submit</button>
1+
const comment_form_container = document.getElementById("bloggit-comment-rf")
192

20-
</form>
21-
</div>
22-
`
3+
if(comment_form_container){
4+
comment_form_container.innerHTML = `
5+
<div class="container mt-5">
6+
<h1>Leave a Comment</h1>
7+
<form>
8+
<div class="form-group">
9+
<label for="comment-name">Name:* (required)</label>
10+
<input type="text" class="form-control" id="comment-name" placeholder="Enter your name" required>
11+
</div>
12+
<div class="form-group">
13+
<label for="comment-email">Email: (not compulsory, and this won't be published)</label>
14+
<input type="email" class="form-control" id="comment-email" placeholder="Enter your email">
15+
</div>
16+
<div class="form-group">
17+
<label for="comment-comment">Comment:* (required)</label>
18+
<textarea class="form-control" id="comment-comment" rows="4" placeholder="Enter your comment" required></textarea>
19+
</div>
20+
<p id="comment-status"></p>
21+
<button type="submit" class="btn btn-primary" id="bloggit-submit-comment">Submit</button>
22+
23+
</form>
24+
</div>
25+
`
26+
}else{
27+
console.log("Comment Form Container not defined!")
28+
}

Test templates/Javascript/Headers/milky-way.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ bloggit_header.innerHTML = `
88
`
99
const brand_name = document.getElementById("brand-name")
1010
const brand_name_a = document.createElement("a")
11-
brand_name_a.href = "/"
11+
brand_name_a.href = data["home_page"]
1212
brand_name_a.className = "navbar-brand"
1313
if(bloggit_conf["header"]["brand_name"]){
1414
brand_name_a.innerText = bloggit_conf["header"]["brand_name"]

Test templates/Javascript/home_and_blog.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function convert_datetime(param){
8787
let __time__ = `${hours}:${minutes}:${seconds}`;
8888

8989
// Format the date as "Month Day, Year"
90-
return date.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }).toString() + " ; " + __time__;
90+
return date.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }).toString() //+ " ; " + __time__;
9191
}
9292

9393
function strip_tags(param){
@@ -125,15 +125,16 @@ fetch(`http://127.0.0.1:8000/posts/api/${api_key}?url=${current_url}&cont_rend=$
125125

126126
if (data["not_found_details"]){
127127
if(bloggit_conf["cont_rend"]){
128-
document.getElementById("bloggit-container").innerHTML = ` <div class="container">
129-
<div class="row justify-content-center">
130-
<div class="col-md-6 text-center mt-5">
131-
<h1 class="display-4">404 - Not Found</h1>
132-
<p class="lead">This Blog Post does not exist!.</p>
133-
<a href="${data["home"]}" class="btn btn-primary">Go to Homepage</a>
128+
document.getElementById("bloggit-container").innerHTML = `
129+
<div class="container">
130+
<div class="row justify-content-center">
131+
<div class="col-md-6 text-center mt-5">
132+
<h1 class="display-4">404 - Not Found</h1>
133+
<p class="lead">This Blog Post does not exist!.</p>
134+
<a href="${data["home_page"]}" class="btn btn-primary">Go to Homepage</a>
135+
</div>
134136
</div>
135-
</div>
136-
</div>`
137+
</div>`
137138
}else{
138139
console.log("Error 404, This post doesn't exist!");
139140
}

Test templates/home.html

+13-9
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,24 @@
88
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
99
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
1010
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
11+
<style>
12+
13+
</style>
1114
<script>
15+
1216
const bloggit_conf = {
1317
"api_key": " 7070aa3bfb7a4f6f8266fa44180d4aaf",
1418
"preloader": "veron",
1519
"cont_rend":"classic",
16-
// "header": {
17-
// "type": "milky-way",
18-
// "brand_name": "Craennie's Blog",
19-
// "links":{
20-
// "Home": "/home",
21-
// "Contact": "/contact",
22-
// "About": "/about"
23-
// }
24-
// }
20+
"header": {
21+
"type": "milky-way",
22+
"brand_name": "Craennie's Blog",
23+
"links":{
24+
"Home": "/home",
25+
"Contact": "/contact",
26+
"About": "/about"
27+
}
28+
}
2529
}
2630
</script>
2731
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">

Test templates/post.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<script>
1313
const bloggit_conf = {
1414
"api_key": "7070aa3bfb7a4f6f8266fa44180d4aaf",
15-
"preloader": "veron",
15+
// "preloader": "veron",
1616
"cont_rend":"cappuccin",
1717
"header": {
1818
"type": "milky-way",
@@ -53,7 +53,7 @@
5353

5454
<div id="bloggit-comment-rf">
5555

56-
</div>
56+
</div>
5757

5858

5959
<section id="bloggit-comment-container">

api/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Post(models.Model):
1717
body = HTMLField(
1818

1919
)
20-
time = models.DateTimeField(default = datetime.now())
20+
time = models.CharField(default = datetime.now(), max_length = 120)
2121
# featured = models.BooleanField(default=False)
2222
publish = models.BooleanField(default=False)
2323
categories = models.CharField(default = "", max_length=100)

api/views.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def get(self, request:Request, api_key, *args, **kwargs):
5959
header_type = get_object_or_404(Scripts, name = header_type)
6060
if CSS.objects.filter(name = header_type).exists():
6161
css_header = CSS.objects.get(name = header_type)
62-
except:pass
62+
else:
63+
css_header = "undefined"
64+
except: header_type = "undefined"
6365

6466
user_urls = get_object_or_404(UserSites, user = token.user)
6567

@@ -88,7 +90,8 @@ def get(self, request:Request, api_key, *args, **kwargs):
8890

8991
response_data = {
9092
"posts": serialized_data.data,
91-
"individual_page": user_urls.individual_blog_post
93+
"individual_page": user_urls.individual_blog_post,
94+
"home_page": user_urls.blog_page
9295
}
9396
try:
9497
response_data["script"] = script.script
@@ -130,13 +133,16 @@ def get(self, request:Request, api_key, *args, **kwargs):
130133

131134
response_data = {
132135
"post": serialized_data.data,
133-
# "comments": comments_serailizer.data
136+
"home_page": user_urls.blog_page
134137
}
135138
if cont_rend:
136139
response_data["script"] = Scripts.objects.get(name = "cappuccino").script
137140

138-
if header_type:
141+
if header_type != "undefined":
139142
response_data["header_type"] = header_type.script
143+
elif header_type == "undefined":
144+
pass
145+
140146

141147
comment_data = request.GET.get("comment")
142148

@@ -174,7 +180,8 @@ def get(self, request:Request, api_key, *args, **kwargs):
174180

175181
else:
176182
response_data = {
177-
"unregistered_site_url": "Not Found"
183+
"unregistered_site_url": "Not Found",
184+
"home_page": user_urls.blog_page
178185
}
179186
return Response(response_data, status = status.HTTP_401_UNAUTHORIZED)
180187

db.sqlite3

4 KB
Binary file not shown.

static/Javascript/sendcomment.js

+21
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
const submit_comment_btn = document.getElementById("bloggit-submit-comment")
2+
const comment_container = document.getElementById("bloggit-comment-container")
23

34
if(submit_comment_btn){
45
submit_comment_btn.addEventListener("click", function(e){
56

67
e.preventDefault()
8+
submit_comment_btn.disabled = true
9+
submit_comment_btn.style.cursor = "not-allowed"
710
let comment = document.getElementById("comment-comment")
811
let comment_name = document.getElementById("comment-name")
912
let comment_email = document.getElementById("comment-email")
@@ -30,6 +33,22 @@ submit_comment_btn.addEventListener("click", function(e){
3033
})
3134
.then(response => {
3235
if(response.status == '201'){
36+
let time = new Date().toDateString();
37+
38+
if(comment_container){
39+
const c_cont_inner = document.querySelector("#bloggit-comment-container #comments")
40+
c_cont_inner.innerHTML = `
41+
<div class="card mb-3">
42+
<div class="card-body">
43+
<h3 class="card-title">${comment_name.value}</h3>
44+
<time>${time}</time>
45+
<article class="card-text">${comment.value}</article>
46+
</div>
47+
</div>
48+
49+
` + c_cont_inner.innerHTML
50+
}
51+
3352
comment.value = comment_email.value = comment_name.value = ""
3453

3554
document.getElementById("comment-status").innerText = 'Your comment has been added!'
@@ -41,6 +60,8 @@ submit_comment_btn.addEventListener("click", function(e){
4160

4261
}
4362
}
63+
submit_comment_btn.disabled = false
64+
submit_comment_btn.style.cursor = "pointer"
4465
return response.json();
4566

4667
})

0 commit comments

Comments
 (0)