Skip to content

Commit 387a548

Browse files
committed
Merge branch 'tabler-admin'
1 parent 240afc3 commit 387a548

40 files changed

+1846
-1108
lines changed

config/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"siteTitle":"Blog-Doc","siteDescription":"The simplest Node.js CMS and SSG !","siteURL":"https://blocdoc-1-v3476171.deta.app/","featuredImage":"/images/black-and-white-checked-photo.webp","archiveImage":"/images/assorted-folders-photo.avif","tagsImage":"/images/pile-of-assorted-color-papers-photo.avif","tagImage":"/images/assorted-color-sticky-notes-photo.avif","searchImage":"/images/brown-and-silver-telescope-near-water-photo.avif","postsPerPage":"3","postPreviewFallbackImage":"/images/white-camera-on-black-background.webp","rssSiteLanguage":"en-US","rssCopyright":"Copyright (c) 2022 - Present, LebCit under the MIT License","searchFeature":true,"addIdsToHeadings":true,"menuLinks":{"posts":"Archive","tags":"Tags","search":"Search","pages/doc":"Documentation","pages/license":"License","https://github.com/LebCit/blog-doc-space":"GitHub Repo","admin":"Admin ⚡"},"footerCopyright":"App built with ❤️ by <a href='https://lebcit.github.io/'>LebCit</a>","adminLinks":{"admin":"Admin ⚡","admin-pages":"📃 Pages","admin-posts":"📝 Posts","admin-create":"➕ New","admin-gallery":"🖼️ Gallery","admin-config":"⚙️ Settings"}}
1+
{"siteTitle":"Blog-Doc","siteDescription":"The simplest Node.js CMS and SSG !","siteURL":"https://blocdoc-1-v3476171.deta.app/","rssSiteLanguage":"en-US","rssCopyright":"Copyright (c) 2022 - Present, LebCit under the MIT License","featuredImage":"/images/black-and-white-checked-photo.webp","archiveImage":"/images/assorted-folders-photo.avif","tagsImage":"/images/pile-of-assorted-color-papers-photo.avif","tagImage":"/images/assorted-color-sticky-notes-photo.avif","searchImage":"/images/brown-and-silver-telescope-near-water-photo.avif","footerCopyright":"App built with ❤️ by <a href='https://lebcit.github.io/'>LebCit</a>","postsPerPage":3,"postPreviewFallbackImage":"/images/white-camera-on-black-background.webp","searchFeature":true,"addIdsToHeadings":true,"menuLinks":{"posts":"Archive","tags":"Tags","search":"Search","pages/doc":"Documentation","pages/license":"License","https://github.com/LebCit/blog-doc-space":"GitHub Repo","admin":"Admin ⚡"}}

public/admin/images/menu.svg

Lines changed: 1 addition & 0 deletions
Loading

public/admin/js/admin.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
if (window.location.pathname === "/admin-create") {
22
await import("./adminCreate.js")
3-
} else if (window.location.pathname === "/admin-config") {
4-
await import("./adminConfig.js")
3+
} else if (window.location.pathname === "/admin-config-site") {
4+
await import("./adminConfigSite.js")
5+
} else if (window.location.pathname === "/admin-config-menu") {
6+
await import("./adminConfigMenu.js")
57
} else if (window.location.pathname.startsWith("/admin-pages")) {
68
await import("./pagesTable.js")
79
} else if (window.location.pathname.startsWith("/admin-posts")) {
810
await import("./postsTable.js")
911
} else {
1012
await import("./adminUpdate.js")
11-
}
13+
}
Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const menuLinks = document.getElementById("menuLinks")
22
const menuLinksObject = JSON.parse(menuLinks.textContent)
3-
delete menuLinksObject.admin
3+
delete menuLinksObject.admin // Remove admin link `from menu configuration`
44
menuLinks.remove()
55

6-
const container = document.getElementById("container")
6+
const container = document.getElementById("menu-links-accordion-container")
77
const template = document.getElementById("template")
88

99
// Remove a clone when it's removeLinkButton is clicked
@@ -37,6 +37,11 @@ for (const link in menuLinksObject) {
3737
clone.id = `menuLink_${count}`
3838
// Add a data-id to each clone
3939
clone.dataset.id = `${count}`
40+
// Modify data-bs-target of each accordion button
41+
let accordionButton = clone.querySelector("button")
42+
accordionButton.dataset.bsTarget = `${accordionButton.dataset.bsTarget}_${count}`
43+
// Add link title before the end of each accordion button
44+
accordionButton.insertAdjacentHTML("beforeend", `<span class="ms-2">${menuLinksObject[link]}</span>`)
4045

4146
// Select each element in the clone that has an id
4247
let cloneElWithId = clone.querySelectorAll("[id]")
@@ -72,9 +77,9 @@ for (const link in menuLinksObject) {
7277
}
7378
}
7479

75-
// Add a new clone at the end of the container when the add-link button is clicked
76-
const addLinkButton = document.getElementById("add-link")
77-
addLinkButton.addEventListener("click", () => {
80+
// Add a new clone at the end of the container when the add-new-menu-item button is clicked
81+
const addNewMenuItem = document.getElementById("add-new-menu-item")
82+
addNewMenuItem.addEventListener("click", () => {
7883
// Get the number of clones
7984
let clonesCount = container.childElementCount + 1
8085
// Get all remove link buttons
@@ -104,6 +109,11 @@ addLinkButton.addEventListener("click", () => {
104109
clone.id = `menu-link_${highestIdNumber()}`
105110
// Add a data-id to each clone
106111
clone.dataset.id = `${highestIdNumber()}`
112+
// Modify data-bs-target of each accordion button
113+
let accordionButton = clone.querySelector("button")
114+
accordionButton.dataset.bsTarget = `${accordionButton.dataset.bsTarget}_${highestIdNumber()}`
115+
// Add `New Menu Item` before the end of each new accordion button
116+
accordionButton.insertAdjacentHTML("beforeend", `<span class="ms-2">New Menu Item</span>`)
107117

108118
// Select each element in the clone that has an id
109119
let cloneElWithId = clone.querySelectorAll("[id]")
@@ -133,12 +143,12 @@ addLinkButton.addEventListener("click", () => {
133143
removeClone()
134144
})
135145

136-
const configForm = document.getElementById("config-form")
137-
const required = configForm.querySelectorAll("*[required]")
138-
const siteURL = configForm.querySelector("#site-url")
139146
const submitConfigButton = document.getElementById("submit-config-button")
140147

141148
submitConfigButton.addEventListener("click", () => {
149+
const menuConfigForm = document.getElementById("menu-config-form")
150+
const required = menuConfigForm.querySelectorAll("*[required]")
151+
142152
let arr = []
143153
required.forEach((el) => {
144154
arr.push(el.value)
@@ -147,25 +157,16 @@ submitConfigButton.addEventListener("click", () => {
147157
if (arr.includes("")) {
148158
required.forEach((el) => {
149159
if (el.validity.valueMissing) {
150-
el.previousElementSibling.style.display = "block"
160+
el.nextElementSibling.style.display = "block"
151161
}
152162
el.addEventListener("input", () => {
153163
if (el.validity.valueMissing) {
154-
el.previousElementSibling.style.display = "block"
164+
el.nextElementSibling.style.display = "block"
155165
} else {
156-
el.previousElementSibling.style.display = "none"
166+
el.nextElementSibling.style.display = "none"
157167
}
158168
})
159169
})
160-
} else if (!siteURL.value.startsWith("https")) {
161-
siteURL.nextElementSibling.style.display = "block"
162-
siteURL.addEventListener("input", (e) => {
163-
if (!e.target.value.startsWith("https")) {
164-
siteURL.nextElementSibling.style.display = "block"
165-
} else {
166-
siteURL.nextElementSibling.style.display = "none"
167-
}
168-
})
169170
} else {
170171
Swal.fire({
171172
title: "Modify The Configuration ?!",
@@ -177,7 +178,7 @@ submitConfigButton.addEventListener("click", () => {
177178
const b = Swal.getConfirmButton()
178179
b.type = "button"
179180
b.addEventListener("click", () => {
180-
configForm.submit()
181+
menuConfigForm.submit()
181182
})
182183
},
183184
})
@@ -186,7 +187,7 @@ submitConfigButton.addEventListener("click", () => {
186187

187188
Sortable.create(container, {
188189
animation: 150,
189-
ghostClass: "blue-background-class",
190+
ghostClass: "bg-primary-subtle",
190191
store: {
191192
/**
192193
* Save the order of elements. Called onEnd (when the item is dropped).

public/admin/js/adminConfigSite.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const siteConfigForm = document.getElementById("site-config-form")
2+
const required = siteConfigForm.querySelectorAll("*[required]")
3+
const siteURL = siteConfigForm.querySelector("#site-url")
4+
const postsPerPage = siteConfigForm.querySelector("#posts-per-page")
5+
const submitConfigButton = document.getElementById("submit-config-button")
6+
7+
submitConfigButton.addEventListener("click", () => {
8+
let arr = []
9+
required.forEach((el) => {
10+
arr.push(el.value)
11+
})
12+
13+
if (arr.includes("")) {
14+
required.forEach((el) => {
15+
if (el.validity.valueMissing) {
16+
el.nextElementSibling.style.display = "block"
17+
}
18+
el.addEventListener("input", () => {
19+
if (el.validity.valueMissing) {
20+
el.nextElementSibling.style.display = "block"
21+
} else {
22+
el.nextElementSibling.style.display = "none"
23+
}
24+
})
25+
})
26+
} else if (!siteURL.value.startsWith("https")) {
27+
siteURL.previousElementSibling.style.display = "block"
28+
siteURL.addEventListener("input", (e) => {
29+
if (!e.target.value.startsWith("https")) {
30+
siteURL.previousElementSibling.style.display = "block"
31+
} else {
32+
siteURL.previousElementSibling.style.display = "none"
33+
}
34+
})
35+
} else if (postsPerPage.valueAsNumber < 1 || postsPerPage.valueAsNumber > 10) {
36+
postsPerPage.previousElementSibling.style.display = "block"
37+
postsPerPage.addEventListener("input", (e) => {
38+
if (e.target.valueAsNumber < 1 || e.target.valueAsNumber > 10) {
39+
postsPerPage.previousElementSibling.style.display = "block"
40+
} else {
41+
postsPerPage.previousElementSibling.style.display = "none"
42+
}
43+
})
44+
} else {
45+
Swal.fire({
46+
title: "Modify The Configuration ?!",
47+
html: `By clicking on <b>Modify</b>,<br>the <b>Configuration</b> will be modified !<br>Double check the footer copyright<br>if you have used HTML in it,<br>otherwise your app will break !`,
48+
icon: "warning",
49+
showCancelButton: true,
50+
confirmButtonText: "Modify",
51+
didOpen: () => {
52+
const b = Swal.getConfirmButton()
53+
b.type = "button"
54+
b.addEventListener("click", () => {
55+
siteConfigForm.submit()
56+
})
57+
},
58+
})
59+
}
60+
})

public/admin/js/adminCreate.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,28 @@ const fileForm = document.getElementById("file-form")
1616
const submitButton = document.getElementById("submit-button")
1717

1818
fileTypeSelect.selectedIndex = 0
19-
submitButton.classList.add("pure-button-disabled")
19+
submitButton.setAttribute("disabled", "")
2020

2121
fileTypeSelect.addEventListener("change", (e) => {
2222
const fileTypeSelectValue = e.target.value
2323

2424
editor.setMarkdown("")
2525

2626
if (fileTypeSelectValue) {
27-
submitButton.classList.remove("pure-button-disabled")
27+
submitButton.removeAttribute("disabled")
2828
}
2929

3030
if (fileTypeSelectValue === "page") {
3131
// SHOW PAGE FRONT MATTER
32-
pageFrontMatterDiv.classList.remove("hidden")
32+
pageFrontMatterDiv.classList.remove("d-none")
3333
const pageFrontMatterDivChildren = pageFrontMatterDiv.children
3434
for (let index = 0; index < 2; index++) {
3535
const input = pageFrontMatterDivChildren[index].lastElementChild
3636
input.setAttribute("required", "")
3737
}
3838

3939
// HIDE POST FRONT MATTER
40-
postFrontMatterDiv.classList.add("hidden")
40+
postFrontMatterDiv.classList.add("d-none")
4141
const postFrontMatterDivChildren = postFrontMatterDiv.children
4242
for (let index = 0; index < 2; index++) {
4343
const input = postFrontMatterDivChildren[index].lastElementChild
@@ -113,15 +113,15 @@ Finally, click the submit button to create your new page 😉`)
113113
})
114114
} else if (fileTypeSelectValue === "post") {
115115
// HIDE THE PAGE FRONT MATTER
116-
pageFrontMatterDiv.classList.add("hidden")
116+
pageFrontMatterDiv.classList.add("d-none")
117117
const pageFrontMatterDivChildren = pageFrontMatterDiv.children
118118
for (let index = 0; index < 2; index++) {
119119
const input = pageFrontMatterDivChildren[index].lastElementChild
120120
input.removeAttribute("required")
121121
}
122122

123123
// SHOW THE POST FRONT MATTER
124-
postFrontMatterDiv.classList.remove("hidden")
124+
postFrontMatterDiv.classList.remove("d-none")
125125
const postFrontMatterDivChildren = postFrontMatterDiv.children
126126
for (let index = 0; index < 2; index++) {
127127
const input = postFrontMatterDivChildren[index].lastElementChild
@@ -196,18 +196,18 @@ Finally, click the submit button to create your new page 😉`)
196196
}
197197
})
198198
} else {
199-
submitButton.classList.add("pure-button-disabled")
199+
submitButton.setAttribute("disabled", "")
200200

201201
// HIDE THE PAGE FRONT MATTER
202-
pageFrontMatterDiv.classList.add("hidden")
202+
pageFrontMatterDiv.classList.add("d-none")
203203
const pageFrontMatterDivChildren = pageFrontMatterDiv.children
204204
for (let index = 0; index < 2; index++) {
205205
const input = pageFrontMatterDivChildren[index].lastElementChild
206206
input.removeAttribute("required")
207207
}
208208

209209
// HIDE POST FRONT MATTER
210-
postFrontMatterDiv.classList.add("hidden")
210+
postFrontMatterDiv.classList.add("d-none")
211211
const postFrontMatterDivChildren = postFrontMatterDiv.children
212212
for (let index = 0; index < 2; index++) {
213213
const input = postFrontMatterDivChildren[index].lastElementChild

public/admin/js/pagesTable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const table = new Tabulator("#admin-table", {
2929
{ title: "Description", field: "1.data.description" },
3030
{
3131
formatter: function () {
32-
return "<button class='pure-button delete-button'>&#10008; DELETE !</button>"
32+
return "<button type='button' class='btn btn-danger'>&#10008; DELETE !</button>"
3333
},
3434
cellClick: function (e, cell) {
3535
const postData = cell.getRow().getData()
@@ -44,7 +44,7 @@ const table = new Tabulator("#admin-table", {
4444
this is IRREVERSIBLE !
4545
<br />
4646
This file will be FOREVER LOST if you proceed !
47-
<form class="hidden" id="delete-form" action="/delete/${postData[0].replace(".md", "")}" method="post">
47+
<form class="d-none" id="delete-form" action="/delete/${postData[0].replace(".md", "")}" method="post">
4848
<input type="text" name="filePath" id="file-path" value="${filePath}" />
4949
</form>`,
5050
icon: "warning",

public/admin/js/postsTable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const table = new Tabulator("#admin-table", {
4646
},
4747
{
4848
formatter: function () {
49-
return "<button class='pure-button delete-button'>&#10008; DELETE !</button>"
49+
return "<button type='button' class='btn btn-danger'>&#10008; DELETE !</button>"
5050
},
5151
cellClick: function (e, cell) {
5252
const postData = cell.getRow().getData()
@@ -61,7 +61,7 @@ const table = new Tabulator("#admin-table", {
6161
this is IRREVERSIBLE !
6262
<br />
6363
This file will be FOREVER LOST if you proceed !
64-
<form class="hidden" id="delete-form" action="/delete/${postData[0].replace(".md", "")}" method="post">
64+
<form class="d-none" id="delete-form" action="/delete/${postData[0].replace(".md", "")}" method="post">
6565
<input type="text" name="filePath" id="file-path" value="${filePath}" />
6666
</form>`,
6767
icon: "warning",

0 commit comments

Comments
 (0)