don't show tier under itself. also initial button to add new tier(s)

This commit is contained in:
Marcell Mars 2021-08-13 00:00:52 +02:00
parent 0d2d4bf11e
commit 2753be8450

View file

@ -10,10 +10,11 @@
let relpermalink = ""; let relpermalink = "";
let protocol = ""; let protocol = "";
let title = "Foo bar"; let title = "Foo bar";
let hases = []; let hases = [];
let hasesCandidates = []; let hasesCandidates = [];
let frontmatter = {}; let frontmatter = {};
frontmatter["triad"] = []; let frontmatterLoaded = false;
frontmatter["triad"] = [];
frontmatter["ascriptions"] = []; frontmatter["ascriptions"] = [];
frontmatter["notsand"] = []; frontmatter["notsand"] = [];
@ -38,8 +39,8 @@
tiers: [], tiers: [],
candidates: METASP[newFmKey].tiers, candidates: METASP[newFmKey].tiers,
}; };
hasesCandidates = [...hasesCandidates, oldFmKey];
hasesCandidates = hasesCandidates.filter((h) => h != newFmKey); hasesCandidates = hasesCandidates.filter((h) => h != newFmKey);
hasesCandidates = [...hasesCandidates, oldFmKey];
} }
function loadHugoPageMetadata(editHash) { function loadHugoPageMetadata(editHash) {
@ -53,7 +54,8 @@
relpath = repo.path; relpath = repo.path;
relpermalink = repo.relpermalink; relpermalink = repo.relpermalink;
protocol = document.location.protocol.substring(0, 4); protocol = document.location.protocol.substring(0, 4);
hases = Object.keys(METASP); let notSelf = Object.entries(METASP).filter(n => n[1].singular == relpath.split("/")[0])[0][0]
hases = Object.keys(METASP).filter(k => k != notSelf);
Object.entries(repo.frontmatter).forEach(([fmKey, fmValue]) => { Object.entries(repo.frontmatter).forEach(([fmKey, fmValue]) => {
let fmKeyType = ""; let fmKeyType = "";
if (fmKey.toLowerCase().startsWith("has_")) { if (fmKey.toLowerCase().startsWith("has_")) {
@ -77,7 +79,7 @@
if (fmValue.includes(t.file)) { if (fmValue.includes(t.file)) {
tiers.push(t); tiers.push(t);
} else { } else {
candidates.push(t); candidates.push(t);
} }
}); });
frontmatter[fmKeyType].push({ frontmatter[fmKeyType].push({
@ -108,6 +110,7 @@
let tkey = Object.keys(repo.frontmatter).filter((t) => t.toLowerCase() == "title")[0]; let tkey = Object.keys(repo.frontmatter).filter((t) => t.toLowerCase() == "title")[0];
title = repo.frontmatter[tkey]; title = repo.frontmatter[tkey];
frontmatterLoaded = true;
}; };
el.src = `../js/repo/${editHash}.js`; el.src = `../js/repo/${editHash}.js`;
document.body.appendChild(el); document.body.appendChild(el);
@ -156,10 +159,13 @@
return Object.entries(frontmatter).filter(val => val[1].length == 0).map(key => key[0]) return Object.entries(frontmatter).filter(val => val[1].length == 0).map(key => key[0])
} }
function checkTriad() {
let ct = Object.entries(frontmatter).filter(i => i[1].length == 0 && i[0] == "triad")
return ct.length == 0 ? false : true
}
function newTriad() { function newTriad() {
let t = {} newHasTiers({"detail": ["triad", 0, "authors", "editors"]})
t["detail"] = ["triad", 0, "authors", "editors"]
newHasTiers(t)
} }
function dispatchHash() { function dispatchHash() {
@ -218,11 +224,9 @@
{/if} {/if}
{/each} {/each}
{/each} {/each}
{#each newFrontmatter() as nf} {#if frontmatterLoaded && checkTriad()}
{#if nf == "triad"} <div on:click="{newTriad}">NEW TRIAD TIER</div>
<div on:click="{newTriad}">NEW TRIAD TIER</div> {/if}
{/if}
{/each}
</span> </span>
<div class="formgrid"> <div class="formgrid">
<label for="pagecontent">Content:</label> <label for="pagecontent">Content:</label>