Update app.js
This commit is contained in:
parent
02144a9afe
commit
27eba0b7a2
1 changed files with 9 additions and 15 deletions
|
|
@ -35,9 +35,7 @@ async function init() {
|
||||||
function populateNav() {
|
function populateNav() {
|
||||||
els.primaryNav.innerHTML = '<a href="#/">Home</a>';
|
els.primaryNav.innerHTML = '<a href="#/">Home</a>';
|
||||||
indexData.sections.forEach(s => {
|
indexData.sections.forEach(s => {
|
||||||
const hasIndex = indexData.flat.some(f =>
|
const hasIndex = indexData.flat.some(f => f.path.startsWith(s + "/") && f.isIndex);
|
||||||
f.path.startsWith(s + "/") && f.isIndex
|
|
||||||
);
|
|
||||||
if (hasIndex) {
|
if (hasIndex) {
|
||||||
els.primaryNav.innerHTML += `<a href="#/${s}/">${s.charAt(0).toUpperCase() + s.slice(1)}</a>`;
|
els.primaryNav.innerHTML += `<a href="#/${s}/">${s.charAt(0).toUpperCase() + s.slice(1)}</a>`;
|
||||||
}
|
}
|
||||||
|
|
@ -61,6 +59,11 @@ function populateTags() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatTimestamp(ms) {
|
||||||
|
const d = new Date(ms);
|
||||||
|
return `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')} ${String(d.getHours()).padStart(2,'0')}:${String(d.getMinutes()).padStart(2,'0')}`;
|
||||||
|
}
|
||||||
|
|
||||||
function wireUI() {
|
function wireUI() {
|
||||||
els.menuBtn.addEventListener("click", () => {
|
els.menuBtn.addEventListener("click", () => {
|
||||||
sidebarOpen = !sidebarOpen;
|
sidebarOpen = !sidebarOpen;
|
||||||
|
|
@ -91,13 +94,6 @@ function wireUI() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatDateTime(mtime) {
|
|
||||||
const d = new Date(mtime);
|
|
||||||
const date = d.toISOString().split("T")[0];
|
|
||||||
const time = d.toTimeString().slice(0, 5);
|
|
||||||
return `${date} at ${time}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderList() {
|
function renderList() {
|
||||||
const section = els.sectionSelect.value;
|
const section = els.sectionSelect.value;
|
||||||
const tags = Array.from(els.tagSelect.selectedOptions).map(o => o.value.toLowerCase());
|
const tags = Array.from(els.tagSelect.selectedOptions).map(o => o.value.toLowerCase());
|
||||||
|
|
@ -120,8 +116,8 @@ function renderList() {
|
||||||
posts.forEach(p => {
|
posts.forEach(p => {
|
||||||
const li = document.createElement("li");
|
const li = document.createElement("li");
|
||||||
const pin = p.isPinned ? "Star " : "";
|
const pin = p.isPinned ? "Star " : "";
|
||||||
const datetime = formatDateTime(p.mtime);
|
const time = formatTimestamp(p.ctime);
|
||||||
li.innerHTML = `<a href="#/${p.path}">${pin}${p.title}</a><small>${datetime}</small>`;
|
li.innerHTML = `<a href="#/${p.path}">${pin}${p.title}</a><small>${time}</small>`;
|
||||||
els.postList.appendChild(li);
|
els.postList.appendChild(li);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -143,9 +139,7 @@ async function handleHash() {
|
||||||
|
|
||||||
if (rel.endsWith('/')) {
|
if (rel.endsWith('/')) {
|
||||||
const section = rel.slice(0, -1);
|
const section = rel.slice(0, -1);
|
||||||
const indexFile = indexData.flat.find(f =>
|
const indexFile = indexData.flat.find(f => f.path.startsWith(section + "/") && f.isIndex);
|
||||||
f.path.startsWith(section + "/") && f.isIndex
|
|
||||||
);
|
|
||||||
if (indexFile) {
|
if (indexFile) {
|
||||||
indexFile.ext === ".md" ? await renderMarkdown(indexFile.path) : renderIframe(indexFile.path);
|
indexFile.ext === ".md" ? await renderMarkdown(indexFile.path) : renderIframe(indexFile.path);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue