Compare commits

..

No commits in common. "f5af0012f04e1ac8ffd75dfed622b5b5b51ebee7" and "2753be8450196eab2fa54a84cb1015514b857578" have entirely different histories.

3 changed files with 65 additions and 125 deletions

View file

@ -50,15 +50,6 @@ button:disabled {
color: #999; color: #999;
} }
.button {
color: #333;
background-color: #f4f4f4;
border: 1px solid lightgrey;
padding: 0.2em 0.4em;
grid-column: 2/3;
margin-right: 0.2rem;
}
button:not(:disabled):active { button:not(:disabled):active {
background-color: #ddd; background-color: #ddd;
} }
@ -186,11 +177,3 @@ select {
#fmicon, #frontmatter, input.hasinput { #fmicon, #frontmatter, input.hasinput {
background-color: #ffccbc; background-color: #ffccbc;
} }
#newtier {
display: none;
}
.news {
grid-column: 2/3;
}

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"] = [];
@ -31,61 +32,19 @@
return Array.from(diff); return Array.from(diff);
} }
function newTier(fmKeyType, fmKey, fmValue = "") {
console.log("newTier", fmKeyType, fmKey);
if (fmKeyType == "ascriptions" && fmKey == "_new") {
hasesCandidates = [... new Set(reckonHasesCandidates())]
if (hasesCandidates.length > 0) {
fmKey = hasesCandidates[0]
console.log(hasesCandidates, fmKey)
}
}
let tiers = [];
let candidates = [];
METASP[fmKey].tiers.forEach((t) => {
if (fmValue.includes(t.file)) {
tiers.push(t);
} else {
candidates.push(t);
}
});
frontmatter[fmKeyType].push({
fmKey: fmKey,
tiers: tiers,
candidates: [...new Set(candidates)],
});
frontmatter = { ...frontmatter };
}
function newHasTiers(arrgs) { function newHasTiers(arrgs) {
let [fmKeyType, index, oldFmKey, newFmKey] = arrgs.detail; let [fmKeyType, index, oldFmKey, newFmKey] = arrgs.detail;
hasesCandidates = [... new Set(reckonHasesCandidates())]
console.log(hasesCandidates)
if (fmKeyType=="triad" && oldFmKey == "_new") {
if (hasesCandidates.length > 0) {
newFmKey = hasesCandidates[0];
if (hasesCandidates.length > 1) {
oldFmKey = hasesCandidates[1]
}
} else {
return
}
}
frontmatter[fmKeyType][index] = { frontmatter[fmKeyType][index] = {
fmKey: newFmKey, fmKey: newFmKey,
tiers: [], tiers: [],
candidates: METASP[newFmKey].tiers, candidates: METASP[newFmKey].tiers,
}; };
hasesCandidates = hasesCandidates.filter((h) => h != newFmKey); hasesCandidates = hasesCandidates.filter((h) => h != newFmKey);
hasesCandidates = [...hasesCandidates, oldFmKey]; hasesCandidates = [...hasesCandidates, oldFmKey];
toggleNewTriadButton();
} }
function loadHugoPageMetadata(editHash) { function loadHugoPageMetadata(editHash) {
let el = document.createElement("script"); var el = document.createElement("script");
el.onload = () => { el.onload = () => {
v = repo.content; v = repo.content;
if (v.startsWith("\n")) { if (v.startsWith("\n")) {
@ -95,8 +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);
const notSelf = Object.entries(METASP).filter((n) => n[1].singular == relpath.split("/")[0])[0][0]; let notSelf = Object.entries(METASP).filter(n => n[1].singular == relpath.split("/")[0])[0][0]
hases = Object.keys(METASP).filter((k) => k != notSelf); 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_")) {
@ -114,7 +73,20 @@
if (["triad", "ascriptions"].includes(fmKeyType)) { if (["triad", "ascriptions"].includes(fmKeyType)) {
if (Array.isArray(fmValue)) { if (Array.isArray(fmValue)) {
newTier(fmKeyType, fmKey, fmValue); let tiers = [];
let candidates = [];
METASP[fmKey].tiers.forEach((t) => {
if (fmValue.includes(t.file)) {
tiers.push(t);
} else {
candidates.push(t);
}
});
frontmatter[fmKeyType].push({
fmKey: fmKey,
tiers: tiers,
candidates: candidates,
});
} }
} else if (fmKeyType == "journal") { } else if (fmKeyType == "journal") {
frontmatter["journal"] || (frontmatter["journal"] = []); frontmatter["journal"] || (frontmatter["journal"] = []);
@ -127,28 +99,25 @@
} }
} }
}); });
hasesCandidates = reckonHasesCandidates(); hasesCandidates = diffArrr(hases, [
const tkey = Object.keys(repo.frontmatter).filter((t) => t.toLowerCase() == "title")[0]; ...frontmatter["triad"].map((t) => {
title = repo.frontmatter[tkey]; return t.fmKey;
}),
...frontmatter["ascriptions"].map((t) => {
return t.fmKey;
}),
]);
toggleNewTriadButton(); let tkey = Object.keys(repo.frontmatter).filter((t) => t.toLowerCase() == "title")[0];
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);
} }
function reckonHasesCandidates() {
return diffArrr(hases, [
...frontmatter["triad"].map((t) => {
return t.fmKey;
}),
...frontmatter["ascriptions"].map((t) => {
return t.fmKey;
}),
]);
}
function addToCandidatesRemoveFromTiers(arrgs) { function addToCandidatesRemoveFromTiers(arrgs) {
const [fmKeyType, index, fmKey, tier] = arrgs.detail; let [fmKeyType, index, fmKey, tier] = arrgs.detail;
frontmatter[fmKeyType][index]["fmKey"] = fmKey; frontmatter[fmKeyType][index]["fmKey"] = fmKey;
frontmatter[fmKeyType][index]["tiers"] = frontmatter[fmKeyType][index]["tiers"].filter( frontmatter[fmKeyType][index]["tiers"] = frontmatter[fmKeyType][index]["tiers"].filter(
(t) => t !== tier (t) => t !== tier
@ -157,7 +126,7 @@
} }
function addToTiersRemoveFromCandidates(arrgs) { function addToTiersRemoveFromCandidates(arrgs) {
const [fmKeyType, index, , value] = arrgs.detail; let [fmKeyType, index, , value] = arrgs.detail;
const tier = frontmatter[fmKeyType][index]["candidates"].filter((t) => t.file == value); const tier = frontmatter[fmKeyType][index]["candidates"].filter((t) => t.file == value);
if (tier.length > 0) { if (tier.length > 0) {
frontmatter[fmKeyType][index]["tiers"] = [...frontmatter[fmKeyType][index]["tiers"], tier[0]]; frontmatter[fmKeyType][index]["tiers"] = [...frontmatter[fmKeyType][index]["tiers"], tier[0]];
@ -186,45 +155,37 @@
} }
} }
function newFrontmatter() { function newFrontmatter() {
return Object.entries(frontmatter) return Object.entries(frontmatter).filter(val => val[1].length == 0).map(key => key[0])
.filter((val) => val[1].length == 0) }
.map((key) => key[0]);
}
function toggleNewTriadButton() { function checkTriad() {
const ct = Object.entries(frontmatter).filter((i) => i[1].length == 0 && i[0] == "triad"); let ct = Object.entries(frontmatter).filter(i => i[1].length == 0 && i[0] == "triad")
if (document.getElementById("newtier")) { return ct.length == 0 ? false : true
if (ct.length == 0) { }
document.getElementById("newtier").style.display = "none";
} else {
document.getElementById("newtier").style.display = "block";
}
}
}
function newTriad() { function newTriad() {
newHasTiers({ detail: ["triad", 0, "_new", ""] }); newHasTiers({"detail": ["triad", 0, "authors", "editors"]})
} }
function dispatchHash() { function dispatchHash() {
const searchParams = new URLSearchParams(location.search); var searchParams = new URLSearchParams(location.search);
const editHash = searchParams.get("edit"); let editHash = searchParams.get('edit')
if (editHash) { if (editHash) {
loadHugoPageMetadata(editHash); loadHugoPageMetadata(editHash)
} else { } else {
let newPage = searchParams.get("new"); let newPage = searchParams.get('new')
console.log(newPage); console.log(newPage)
} }
} }
onMount(() => { onMount(() => {
dispatchHash(); dispatchHash();
// loadHugoPageMetadata(); // loadHugoPageMetadata();
console.dir(frontmatter); console.dir(frontmatter);
}); });
$: hashChanged = () => dispatchHash(); $: hashChanged = ()=> dispatchHash();
</script> </script>
<svelte:window on:keyup={keyUp} on:hashchange={hashChanged} /> <svelte:window on:keyup={keyUp} on:hashchange={hashChanged} />
@ -245,7 +206,6 @@
{hases} {hases}
{hasesCandidates} {hasesCandidates}
on:hasTiersSelected={newHasTiers} on:hasTiersSelected={newHasTiers}
/> />
<SpTiers <SpTiers
on:addToCandidatesRemoveFromTiers={addToCandidatesRemoveFromTiers} on:addToCandidatesRemoveFromTiers={addToCandidatesRemoveFromTiers}
@ -264,12 +224,9 @@
{/if} {/if}
{/each} {/each}
{/each} {/each}
<div class="buttons news"> {#if frontmatterLoaded && checkTriad()}
<div id="newtier" class="button" on:click={newTriad}>NEW TIER</div> <div on:click="{newTriad}">NEW TRIAD TIER</div>
<div id="newascription" class="button" on:click={() => newTier("ascriptions", "_new")}> {/if}
NEW ASCRIPTION
</div>
</div>
</span> </span>
<div class="formgrid"> <div class="formgrid">
<label for="pagecontent">Content:</label> <label for="pagecontent">Content:</label>

View file

@ -46,7 +46,7 @@
on:click={swapTier(tier, -1)} on:click={swapTier(tier, -1)}
disabled={i == 0 ? true : false}>⇑</button disabled={i == 0 ? true : false}>⇑</button
> >
<button type="button" on:click={()=> removeTier(tier)}>×</button> <button type="button" on:click={removeTier(tier)}>×</button>
</div> </div>
</div> </div>
{/each} {/each}